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

docs: various doc improvements #9396

Merged
merged 8 commits into from
Dec 9, 2022
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
docs: update test runner docs
Closes #9367
  • Loading branch information
OrKoN committed Dec 9, 2022
commit 9b86dc462a3ba963ab03ada17d8dba378e1c4aee
24 changes: 9 additions & 15 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Puppeteer unit tests
# Puppeteer tests

Unit tests in Puppeteer are written using [Mocha] as the test runner and [Expect] as the assertions library.

Expand All @@ -25,19 +25,11 @@ The best place to look is an existing test to see how they use the helpers.

## Skipping tests in specific conditions

Tests that are not expected to pass in Firefox can be skipped. You can skip an individual test by using `itFailsFirefox` rather than `it`. Similarly you can skip a describe block with `describeFailsFirefox`.

There is also `describeChromeOnly` and `itChromeOnly` which will only execute the test if running in Chromium. Note that this is different from `describeFailsFirefox`: the goal is to get any `FailsFirefox` calls passing in Firefox, whereas `describeChromeOnly` should be used to test behaviour that will only ever apply in Chromium.

There are also tests that assume a normal install flow, with browser binaries ending up in `.local-<browser>`, for example. Such tests are skipped with
`itOnlyRegularInstall` which checks `BINARY` and `PUPPETEER_ALT_INSTALL` environment variables.

[mocha]: https://mochajs.org/
[expect]: https://www.npmjs.com/package/expect
To skip tests edit the [TestExpecations](https://github.com/puppeteer/puppeteer/blob/main/test/TestExpectations.json) file. See [test runner documentation](https://github.com/puppeteer/puppeteer/tree/main/tools/mochaRunner) for more details.

## Running tests

- To run all tests:
- To run all tests applicable for your platform:

```bash
npm test
Expand All @@ -46,7 +38,7 @@ npm test
- **Important**: don't forget to first build the code if you're testing local changes:

```bash
npm run build:test && npm test
npm run build && npm test
```

- To run a specific test, substitute the `it` with `it.only`:
Expand All @@ -60,12 +52,11 @@ npm run build:test && npm test
});
```

- To disable a specific test, substitute the `it` with `xit` (mnemonic rule: '_cross it_'):
- To disable a specific test, substitute the `it` with `it.skip`:

```ts
...
// Using "xit" to skip specific test
xit('should work', async function({server, page}) {
it.skip('should work', async function({server, page}) {
const {server, page} = getTestState();
const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok).toBe(true);
Expand All @@ -83,3 +74,6 @@ npm run test:chrome:headful
```bash
BINARY=<path-to-executable> npm run test:chrome:headless # Or npm run test:firefox
```

[mocha]: https://mochajs.org/
[expect]: https://www.npmjs.com/package/expect