docsify/test/README.md
John Hildenbiddle c49c39a4a2
refactor: Update test environments and lint configuration (#1736)
* Update test environments and lint configuration

Update Jest (unit + integration) and Playwright (e2e) test environments. Includes stability improvements for e2e tests using newer, more stable methods per the Playwright docs.

- Update Jest 26 => 27
- Update Jest-related libs (babel parser)
- Update Playwright 1.8 => Playwright Test 1.18
- Update GitHub CI (action versions, job parallelization, and matrices)
- Update ESLint 5 => 8
- Update ESLint-related libs (parser, prettier, Jest, Playwright)
- Fix test failures on M1-based Macs
- Fix e2e stability issues by replacing PW $ method calls
- Fix ESLint errors
- Fix incorrect CI flag on Jest runs (-ci => --ci)
- Refactor e2e test runner from Jest to Playwright Test
- Refactor e2e test files for Playwright Test
- Refactor fix-lint script name to lint:fix for consistency
- Refactor npm scripts order for readability
- Remove unnecessary configs and libs
- Remove example image snapshots
2022-01-30 21:40:21 -06:00

71 lines
2.1 KiB
Markdown

# Docsify Testing
## Environment
- [Jest](https://jestjs.io): A test framework used for assertions, mocks, spies, etc.
- [Playwright](https://playwright.dev): A test automation tool for launching browsers and manipulating the DOM.
- [Jest-Playwright](https://github.com/playwright-community/jest-playwright): A Jest preset that simplifies using Jest and Playwright together
## Test files
- E2E tests are located in `/test/e2e/` and use [Jest](https://jestjs.io) + [Playwright](https://playwright.dev).
- Integration tests are located in `/test/integration/` and use [Jest](https://jestjs.io).
- Unit tests located in `/test/unit/` and use [Jest](https://jestjs.io).
## Global Variables
- `process.env.TEST_HOST`: Test server ip:port
## CLI commands
```bash
# Run all tests
npm run test
# Run test types
npm run test:e2e
npm run test:integration
npm run test:unit
# Run test file
npm run test -- -i /path/to/file.test.js
# Run matching test files
npm run test -- -i /path/to/*.test.js
# Run matching test name(s)
npm run test -- -t \"describe() or test() name\"
# Run matching test name(s) in file
npm run test -- -i /path/to/file.test.js -t \"describe() or test() name\"
# Run all example tests
npm run test -- -i /test/**/example.test.js
# Run specific example test file
npm run test -- -i /path/to/example.test.js
# ------------------------------------------------------------------------------
# Update snapshots for matching test files
npm run test -- -u -i /path/to/*.test.js
# Update snapshots for matching test name(s)
npm run test -- -u -t \"describe() or test() name\"
# Update snapshots for matching test name(s) in file
npm run test -- -u -i /path/to/file.test.js -t \"describe() or test() name\"
# ------------------------------------------------------------------------------
# Start manual test server instance. Useful for previewing test fixtures.
# Root: /test/e2e/fixtures/
# Routes: /docs, /lib,
node ./test/config/server.js --start
```
## Resource
- [UI Testing Best Practices](https://github.com/NoriSte/ui-testing-best-practices)
- [Using Jest with Playwright](https://playwright.tech/blog/using-jest-with-playwright)