Skip to content

Commit

Permalink
Update test docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jhildenbiddle committed Dec 2, 2023
1 parent 71a5fd3 commit 4756e59
Showing 1 changed file with 47 additions and 35 deletions.
82 changes: 47 additions & 35 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,79 @@

- [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
- Integration tests are located in `/test/integration/` and use [Jest](https://jestjs.io).
- E2E tests are located in `/test/e2e/` and use [Jest](https://jestjs.io) + [Playwright](https://playwright.dev).

## CLI commands

```bash
# Run all tests
npm run test
npm t

# Run test types
npm run test:e2e
npm run test:integration
npm run test:unit
```

### Unit / Integration (Jest)

```bash
# Run test file(s)
npm run test:unit -- -i ./path/to/file.test.js
npm run test:unit -- -i ./path/to/*.test.js

# Run test file
npm run test -- -i /path/to/file.test.js
# Run test name(s)
npm run test:unit -- -t "my test"

# Run matching test files
npm run test -- -i /path/to/*.test.js
# Run test name(s) in file
npm run test:unit -- -i ./path/to/file.test.js -t "my test"

# 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\"
# Update snapshots
npm run test:unit -- -u

# Run all example tests
npm run test -- -i /test/**/example.test.js
# Update snapshots for test file(s)
npm run test:unit -- -u -i ./path/to/file.test.js
npm run test:unit -- -u -i ./path/to/*.test.js

# Run specific example test file
npm run test -- -i /path/to/example.test.js
# Update snapshots for test name(s)
npm run test:unit -- -u -t "my test"

# ------------------------------------------------------------------------------
# Update snapshots for test name(s) in file
npm run test:unit -- -u -i ./path/to/file.test.js -t "my test"
```

# Update snapshots for matching test files
npm run test -- -u -i /path/to/*.test.js
### E2E (Playwright)

# Update snapshots for matching test name(s)
npm run test -- -u -t \"describe() or test() name\"
```bash
# Run test file(s)
npm run test:e2e -- ./path/to/file.test.js
npm run test:e2e -- ./path/to/*.test.js

# Update snapshots for matching test name(s) in file
npm run test -- -u -i /path/to/file.test.js -t \"describe() or test() name\"
# Run test name(s)
npm run test:e2e -- -g "my test"

# Run test name(s) in file
npm run test:e2e -- ./path/to/file.test.js -g "my test"

# ------------------------------------------------------------------------------

# Start manual test server instance. Useful for previewing test fixtures.
# Root: /test/e2e/fixtures/
# Routes: /docs, /lib,
node ./test/config/server.js --start
```
# Update snapshots
npm run test:e2e -- -u

## Resource
# Update snapshots for test file(s)
npm run test:e2e -- -u ./path/to/file.test.js
npm run test:e2e -- -u ./path/to/*.test.js

- [UI Testing Best Practices](https://github.com/NoriSte/ui-testing-best-practices)
- [Using Jest with Playwright](https://playwright.tech/blog/using-jest-with-playwright)
# Update snapshots for test name(s)
npm run test:e2e -- -u -g "my test"

# Update snapshots for test name(s) in file
npm run test:e2e -- -u ./path/to/file.test.js -g "my test"
```

0 comments on commit 4756e59

Please sign in to comment.