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 19, 2023
1 parent a3cec69 commit 4f5f7e5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
2 changes: 2 additions & 0 deletions docs/releasing/testing-and-linting.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ 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.

When running tests in [headless Chrome](https://developers.google.com/web/updates/2017/04/headless-chrome) it's useful to configure [`{ headless: false }`](../../jest-puppeteer.config.js) and run `await jestPuppeteer.debug()` from the test. This pauses an open browser for inspection.

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
1 change: 1 addition & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
*/
'--no-startup-window'
],
headless: false,
waitForInitialPage: false
},

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 4f5f7e5

Please sign in to comment.