Skip to content

Commit

Permalink
Update test docs for Puppeteer browser inspection
Browse files Browse the repository at this point in the history
Includes tip regarding `await jestPuppeteer.debug()` with ESLint config changes to allow `jestPuppeteer` as a known global
  • Loading branch information
colinrotherham committed Apr 21, 2023
1 parent 2b13f01 commit 4f0e257
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
6 changes: 6 additions & 0 deletions docs/releasing/testing-and-linting.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ We write functional tests for every component to check the output of our Nunjuck

If a component uses JavaScript, we also write functional tests in a `[component name].test.js` file, for example [checkboxes.test.js](../../src/govuk/components/checkboxes/checkboxes.test.js). These component tests check that interactions, such as a mouse click, have the expected result.

If you want to inspect a test that's running in the browser, configure Jest Puppeteer in non-headless mode with the environment variable `HEADLESS=false` and then use [Jest Puppeteer's debug mode](https://github.com/argos-ci/jest-puppeteer/blob/main/README.md#debug-mode) to pause the test execution.

```
HEADLESS=false npx jest --watch src/govuk/components/tag/accessibility.test.mjs
```

You should also test component Javascript logic with unit tests, in a `[component name].unit.test.mjs` file. These tests are better suited for testing behind-the-scenes logic, or in cases where the final output of some logic is not a change to the component markup.

### Global tests
Expand Down
11 changes: 0 additions & 11 deletions shared/lib/.eslintrc.js

This file was deleted.

7 changes: 4 additions & 3 deletions src/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
},
{
// Matches 'JavaScript component tests' in jest.config.mjs
// to ignore unknown 'page' and 'browser' Puppeteer globals
// to ignore unknown Jest Puppeteer globals
files: [
'**/components/globals.test.mjs',
'**/components/*/*.test.{js,mjs}'
Expand All @@ -56,8 +56,9 @@ module.exports = {
'**/*.unit.test.{js,mjs}'
],
globals: {
page: true,
browser: true
page: 'readonly',
browser: 'readonly',
jestPuppeteer: 'readonly'
}
}
]
Expand Down

0 comments on commit 4f0e257

Please sign in to comment.