-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Cypress #84
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cc5664e
Install Cypress in the project
JacobArrow 735dd47
Added Cypress config files with data selector command
JacobArrow b8ada18
Ignore generated Cypress media
JacobArrow 62b1020
Remove go config from page
JacobArrow 356bcd3
Force the unilogin route handler to be dynamic
JacobArrow 76cdfa5
The header component should follow semantic rules and actually be a h…
JacobArrow 7d2fcba
Catch any errors and return the default session if ´getIronSession´ i…
JacobArrow fe9e4eb
Added a simple Cypress test to check that the fronpage has a header a…
JacobArrow d6e7718
Added github workflow to run cypress tests on PRs
JacobArrow 060d62d
Added Cypress info to readme
JacobArrow 4d62af4
Added type safety to custom data-cy command
JacobArrow f565241
Remove last updated date from readme
JacobArrow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Next.js E2E Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
check: | ||
name: E2E job with Cypress | ||
runs-on: ubuntu-latest | ||
env: | ||
NEXT_PUBLIC_APP_URL: http://localhost:3000 | ||
UNILOGIN_SESSION_SECRET: XXX | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
fetch-depth: 0 # Required to retrieve git history | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: ".nvmrc" | ||
|
||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile --no-progress --non-interactive | ||
|
||
- name: Build the Nextjs app and run Cypress tests | ||
uses: cypress-io/github-action@v4 | ||
with: | ||
install: false | ||
build: yarn build | ||
start: yarn start | ||
wait-on: http://localhost:3000 | ||
runTests: yarn cypress:run | ||
browser: chrome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,10 @@ next-env.d.ts | |
# vscode | ||
.vscode | ||
|
||
# Cypress | ||
cypress/videos | ||
cypress/screenshots | ||
|
||
|
||
*storybook.log | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
Drupal CMS can be accessed through Lagoon by generating a one-time login in the preferred environment. | ||
<br> | ||
<br> | ||
Last updated: 27/11/2024 | ||
</p> | ||
|
||
## URLs | ||
|
@@ -83,6 +82,7 @@ The application is now running at [https://localhost:3000](https://localhost:300 | |
- [Tailwind CSS][tailwind] | ||
- [ESLint][eslint] & [Prettier][prettier] | ||
- [Storybook][storybook] & [Chromatic][chromatic] | ||
- [cypress][cypress] | ||
- [Vitest][vitest] | ||
|
||
### Project structure | ||
|
@@ -237,6 +237,17 @@ This will launch the Storybook server, and you can view the component library in | |
|
||
**_We create Storybook stories strictly on a "render component" basis. This means focusing on smaller atomic components that are not specific to generated code._** | ||
|
||
### Cypress | ||
|
||
Cypress is an end-to-end testing framework that allows us to write and run tests for the application's core user journeys. | ||
|
||
To start Cypress, run the following commands: | ||
|
||
```bash | ||
yarn dev # Start the development server | ||
yarn cypress:run # Run all Cypress tests | ||
``` | ||
|
||
## Deployment | ||
|
||
### git branches and pull requests | ||
|
@@ -309,19 +320,22 @@ Quality assurance (QA) is a critical aspect of our development process, ensuring | |
|
||
1. **Automated Unit Testing**: Workflows like `unit-test.yml` run unit tests automatically, ensuring that individual components and utilities function correctly. This helps catch bugs early in the development process. | ||
|
||
2. **Code Quality Checks**: Workflows such as `eslint-check.yml` and `prettier-check.yml` enforce coding standards and consistent formatting. This ensures that the codebase remains clean, readable, and maintainable. | ||
2. **End-to-end Testing**: Workflows such as `e2e-test.yml` run end-to-end tests using Cypress to simulate user interactions and test the application's core user journeys. This helps ensure that the application and important features work as expected. This also helps catch bugs early in the development process. | ||
|
||
3. **Code Quality Checks**: Workflows such as `eslint-check.yml` and `prettier-check.yml` enforce coding standards and consistent formatting. This ensures that the codebase remains clean, readable, and maintainable. | ||
|
||
3. **Type Safety**: The `type-check.yml` workflow runs TypeScript checks to ensure type safety across the project. This helps prevent type-related errors and improves code reliability. | ||
4. **Type Safety**: The `type-check.yml` workflow runs TypeScript checks to ensure type safety across the project. This helps prevent type-related errors and improves code reliability. | ||
|
||
4. **Accessibility Testing**: The `accessibility-test.yml` workflow runs accessibility tests on each [Storybook] Story using [Axe] through [Playwright]. This ensures that the application meets accessibility standards and provides a better user experience for all users. | ||
5. **Accessibility Testing**: The `accessibility-test.yml` workflow runs accessibility tests on each [Storybook] Story using [Axe] through [Playwright]. This ensures that the application meets accessibility standards and provides a better user experience for all users. | ||
|
||
5. **Visual Regression Testing**: The `chromatic.yml` workflow runs Chromatic to visualize and test UI components in [Storybook]. This helps catch visual regressions and ensures that UI changes do not introduce unexpected issues. | ||
6. **Visual Regression Testing**: The `chromatic.yml` workflow runs Chromatic to visualize and test UI components in [Storybook]. This helps catch visual regressions and ensures that UI changes do not introduce unexpected issues. | ||
|
||
## Developers | ||
|
||
- Adam Antal - [email protected] | ||
- Mikkel Jakobsen - [email protected] | ||
- Thomas Gross Rasmussen - [email protected] | ||
- Jacob Pihl - [email protected] | ||
|
||
[nextjs]: https://nextjs.org/ | ||
[app-router]: https://nextjs.org/docs/app | ||
|
@@ -339,4 +353,5 @@ Quality assurance (QA) is a critical aspect of our development process, ensuring | |
[vitest]: https://vitest.dev/ | ||
[axe]: https://playwright.dev/docs/accessibility-testing | ||
[playwright]: https://playwright.dev/ | ||
[cypress]: https://www.cypress.io/ | ||
[dpl-cms]: https://github.com/danskernesdigitalebibliotek/dpl-cms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,3 +101,5 @@ export async function GET(request: NextRequest) { | |
headers, | ||
}) | ||
} | ||
|
||
export const dynamic = "force-dynamic" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineConfig } from "cypress" | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
baseUrl: "http://localhost:3000", | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
setupNodeEvents(on, config) { | ||
// implement node event listeners here | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
describe("Front Page Tests", () => { | ||
it("Should include a header and a footer", () => { | ||
cy.visit("/") | ||
|
||
cy.get("header").should("exist") | ||
cy.get("footer").should("exist") | ||
cy.dataCy("go-logo").should("exist") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-disable @typescript-eslint/no-namespace */ | ||
import { CyKey } from "./constants" | ||
|
||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
dataCy(value: CyKey): Chainable<JQuery<HTMLElement>> | ||
} | ||
} | ||
} | ||
|
||
Cypress.Commands.add("dataCy", selector => { | ||
return cy.get(`[data-cy="${selector}"]`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const cyKeys = { | ||
"go-logo": "go-logo", | ||
} as const | ||
|
||
export type CyKey = keyof typeof cyKeys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./commands" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,9 @@ | |
"test:accessibility": "test-storybook", | ||
"test:unit:once": "vitest run", | ||
"test:unit": "vitest", | ||
"typecheck": "tsc --noEmit" | ||
"typecheck": "tsc --noEmit", | ||
"cypress:open": "cypress open", | ||
"cypress:run": "cypress run" | ||
}, | ||
"dependencies": { | ||
"@next/env": "15.0.3", | ||
|
@@ -86,6 +88,7 @@ | |
"@types/react-dom": "npm:[email protected]", | ||
"@vitejs/plugin-react": "^4.3.2", | ||
"axe-playwright": "^2.0.3", | ||
"cypress": "^13.16.1", | ||
"eslint": "^8.0.0", | ||
"eslint-config-next": "15.0.3", | ||
"eslint-config-prettier": "^9.1.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't figure out what I think about adding code to elements that only have relevance for Cypress. I know its a common practice but still worth mentioning?
I would like our components to be as clean as possible, preferably without extra data attributes.
If we keep it, I think either
data-cy={cyKeys["go-logo"]}
should be placed onButton
orIcon
"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the best practice for selecting elements with Cypress and I think we should stick with that :)
https://docs.cypress.io/app/core-concepts/best-practices#Selecting-Elements
It also allows to typecheck our element selectors, which is always nice.
Regarding where it is placed; it doesnt matter in this PR, as it is only for demonstrating the usage.
frontpage.cy.ts
will be updated once we actually have some content to test.