Skip to content
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

Playwright tests #1832

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4a5e69d
infra: generated mocks, msw setup
fhenrich33 Dec 4, 2024
a45d34e
infra: remove graphql-codegen package and plugins, setup playwright, …
fhenrich33 Dec 6, 2024
56b04e2
Merge branch 'master' of https://github.com/boxwise/boxtribute into p…
fhenrich33 Dec 6, 2024
0787be2
fix: fragment usage
fhenrich33 Dec 6, 2024
8d15663
infra: update graphql-gen script, fixtures
fhenrich33 Dec 6, 2024
f5c7ba6
Merge branch 'master' of https://github.com/boxwise/boxtribute into p…
fhenrich33 Dec 6, 2024
0733d47
Merge branch 'master' of https://github.com/boxwise/boxtribute into p…
fhenrich33 Dec 6, 2024
eea367a
Merge branch 'master' of https://github.com/boxwise/boxtribute into p…
fhenrich33 Dec 8, 2024
94c2629
refactor: move msw handlers import to source
fhenrich33 Dec 8, 2024
27d131f
Merge branch 'master' of https://github.com/boxwise/boxtribute into p…
fhenrich33 Dec 10, 2024
cb1c566
chore: file line end
fhenrich33 Dec 10, 2024
043488d
refactor: remove old test setup
fhenrich33 Dec 10, 2024
5934253
Merge branch 'master' of https://github.com/boxwise/boxtribute into p…
fhenrich33 Dec 10, 2024
09a8add
refactor: remove old test setup
fhenrich33 Dec 10, 2024
29fe187
Merge branch 'master' of https://github.com/boxwise/boxtribute into p…
fhenrich33 Dec 11, 2024
9ccc9f1
feat: update fixture objects and msw responses with mutations
fhenrich33 Dec 12, 2024
c5c9f64
feat: update fixture objects and msw responses with mutations
fhenrich33 Dec 12, 2024
512b5d9
feat: update fixture objects and msw responses with mutations
fhenrich33 Dec 12, 2024
5442c6e
feat: update fixture objects and msw responses with mutations
fhenrich33 Dec 12, 2024
c50b23c
feat: update fixture objects and msw responses with mutations
fhenrich33 Dec 12, 2024
2a14328
test: persist some box mutations in msw
fhenrich33 Dec 12, 2024
f1994f9
Merge branch 'master' of https://github.com/boxwise/boxtribute into p…
fhenrich33 Dec 12, 2024
1572eac
Merge branch 'master' of https://github.com/boxwise/boxtribute into p…
fhenrich33 Dec 12, 2024
b6ca365
infra: use workspace prettier config
fhenrich33 Dec 13, 2024
7e169c1
feat: msw handlers (except shipments, transfer agreements, box history)
fhenrich33 Dec 13, 2024
a043bc7
feat: msw handlers for shipments and transfer agreements queries
fhenrich33 Dec 13, 2024
2838fe8
test: qrCode fake cam feed
fhenrich33 Dec 13, 2024
16ce8be
feat: msw handler last mutations wip
fhenrich33 Dec 15, 2024
fdb83f8
feat: msw handler last mutations wip
fhenrich33 Dec 15, 2024
77547ff
Merge branch 'master' of https://github.com/boxwise/boxtribute into p…
fhenrich33 Dec 18, 2024
7b9069a
fix: tag labels on box edit in msw
fhenrich33 Dec 18, 2024
7f127a8
chore: add todo
fhenrich33 Dec 18, 2024
91b18eb
infra: enable gpg commit signing for vscode
fhenrich33 Dec 18, 2024
feed8db
chore: update msw todo
fhenrich33 Dec 18, 2024
ac98d5c
Merge branch 'master' of https://github.com/boxwise/boxtribute into p…
fhenrich33 Dec 19, 2024
c6d9c3a
docs: playwright adr draft
fhenrich33 Dec 19, 2024
093a1b4
test: infer operation name from graphql operation
fhenrich33 Dec 19, 2024
51d2129
test: wip/draft script to auto generate handlers and mocks
fhenrich33 Dec 19, 2024
1024d3f
test: wip/draft script to auto generate handlers and mocks
fhenrich33 Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ docs/graphql-api/public
.VSCodeCounter
*.old.*
__pycache__/*
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"editor.formatOnPaste": false, // required
"editor.formatOnType": false, // required
"editor.formatOnSave": true,
"prettier.configPath": ".prettierrc",

// eslint
"eslint.workingDirectories": ["./", "./front", "./shared-components", "./statviz"],
Expand All @@ -29,5 +30,6 @@
},

"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
"typescript.enablePromptUseWorkspaceTsdk": true,
"git.enableCommitSigning": true
}
2 changes: 1 addition & 1 deletion back/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ to simulate a god user with ID 8 (for a regular user, set something like `id=1,
> [!IMPORTANT]
> To keep the front-end side up-to-date with the GraphQL schema, make sure that the pre-commit command for `*.graphql` files (`id: generate-graphql-ts-types`) is running properly.
>
> It should generate both `schema.graphql` (the introspected unified schema) and `graphql-env.d.ts` (the generated types to be ìnferred and consumed in the FE with `gql.tada`) inside `/graphql/generated/`.
> It should generate `schema.graphql` (the introspected unified schema), `graphql-env.d.ts` (the generated types to be ìnferred and consumed in the FE with `gql.tada`), `types.ts` (base generated types for msw handlers and mocks) and lastly `mocks.ts` (base mocks to make fixtures and use in tests) inside `/graphql/generated/`.

## Project structure

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ services:
NODE_ENV: development
HUSKY: 0
FRONT_ENVIRONMENT: ${ENVIRONMENT:-development}
FRONT_USE_MSW: ${USE_MSW}
FRONT_SENTRY_ENVIRONMENT: ${ENVIRONMENT:-development}
FRONT_SENTRY_FE_DSN: ${SENTRY_FE_DSN:-}
FRONT_SENTRY_TRACES_SAMPLE_RATE: ${SENTRY_TRACES_SAMPLE_RATE:-}
Expand Down
76 changes: 76 additions & 0 deletions docs/adr/adr_frontend_tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# ADR: Use Playwright for End-to-End and Integration Testing

## Status

Proposed

## Context

The current testing setup for the Boxtribute front-end project uses React Testing Library and Vitest for unit and integration tests. While these tools are effective for testing individual components and their interactions, they do not provide a comprehensive solution for end-to-end (E2E) testing. E2E testing is crucial for ensuring that the application works correctly from the user's perspective, covering the entire workflow from start to finish.

Additionally, we are using Mock Service Worker (MSW) to mock API requests and avoid hitting the real server and database during tests. This allows us to test the application in isolation and ensure consistent test results.

## Decision Drivers

1. **Comprehensive E2E and Integration Testing**: We need a testing framework that can simulate real user interactions and test the application as a whole, as well as handle integration tests with mocked API requests.
2. **Cross-Browser Testing**: The ability to test the application across different browsers to ensure compatibility.
3. **Ease of Use**: The testing framework should be easy to set up and use, with good documentation and community support.
4. **Performance**: The framework should be fast and efficient, minimizing the impact on the development workflow.
5. **Integration with CI/CD**: The framework should integrate well with our existing CI/CD pipeline.

## Considered Options

1. **React Testing Library + Vitest**

- Pros:
- Well-suited for unit and integration tests.
- Good community support and documentation.
- Easy to set up and use.
- Cons:
- Limited to testing individual components and their interactions.
- Does not provide comprehensive E2E testing capabilities.
- No built-in support for cross-browser testing.

2. **Playwright**
- Pros:
- Comprehensive E2E and integration testing capabilities.
- Supports cross-browser testing (Chromium, Firefox, WebKit).
- Easy to set up and use with good documentation.
- Fast and efficient, with parallel test execution.
- Integrates well with CI/CD pipelines.
- Can be used with Mock Service Worker (MSW) to mock API requests.
- Cons:
- Additional learning curve for developers familiar with React Testing Library and Vitest.
- May require more setup for certain advanced use cases.

## Decision

We have decided to adopt Playwright for both E2E and integration testing in the Boxtribute front-end project. Playwright provides comprehensive testing capabilities, supports cross-browser testing, and integrates well with our existing CI/CD pipeline. Additionally, Playwright can be used with Mock Service Worker (MSW) to mock API requests, allowing us to test the application in isolation.

## Consequences

- **Positive**:

- Improved test coverage with comprehensive E2E and integration tests.
- Ability to test the application across different browsers.
- Faster and more efficient testing with parallel test execution.
- Better integration with our CI/CD pipeline.
- Consistent test results by mocking API requests with MSW.

- **Negative**:
- Additional learning curve for developers.
- Potential need for additional setup for advanced use cases.

## Implementation

1. Set up Playwright in the project by following the [installation guide](https://playwright.dev/docs/intro).
2. Write E2E and integration tests using Playwright, utilizing MSW to mock API requests.
3. Integrate Playwright tests into the CI/CD pipeline.
4. Gradually replace existing E2E and integration tests written with React Testing Library and Vitest with Playwright tests.

## References

- [Playwright Documentation](https://playwright.dev/docs/intro)
- [React Testing Library Documentation](https://testing-library.com/docs/react-testing-library/intro)
- [Vitest Documentation](https://vitest.dev/)
- [Mock Service Worker Documentation](https://mswjs.io/docs/)
2 changes: 2 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ TEST_AUTH0_MANAGEMENT_API_CLIENT_ID=ZBDcEypTHMwn23ScgeaMqwzMxO5epguH
TEST_AUTH0_MANAGEMENT_API_CLIENT_SECRET=

ENVIRONMENT=development

USE_MSW=false
4 changes: 4 additions & 0 deletions front/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { setupWorker } from "msw/browser";
import { handlers } from "../tests/mswHandlers";

export const worker = setupWorker(...handlers);
7 changes: 0 additions & 7 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@
"@storybook/test": "^8.4.7",
"@types/react-big-calendar": "^1.16.0",
"@types/react-table": "^7.7.20",
"msw": "^2.7.0",
"mutationobserver-shim": "^0.3.7",
"storybook": "^8.4.7"
},
"scripts": {
"build": "tsc && vite build",
"dev": "vite",
"preview": "vite preview",
"test": "TZ=UTC vitest",
"test:coverage": "TZ=UTC vitest run --coverage",
"upload:test-report": "./node_modules/.bin/codecov",
"tsc:check": "tsc --noEmit",
"tsc:precommit": "tsc-files --noEmit",
"lint": "eslint --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --ignore-path ../.eslintignore",
Expand All @@ -58,8 +54,5 @@
"format:write": "prettier --write --ignore-path ../.eslintignore",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"msw": {
"workerDirectory": "public"
}
}
Loading
Loading