Skip to content

Commit

Permalink
Allow customization of the ARTIFACTS_PATH via WP_ARTIFACTS_PATH env v…
Browse files Browse the repository at this point in the history
…ar (#35371)
  • Loading branch information
thomasplevy authored Oct 9, 2021
1 parent 0d2011f commit ef26639
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Enhancements

- The bundled `jest-dev-server` dependency has been updated to the next major version `^5.0.3` ([#34560](https://github.com/WordPress/gutenberg/pull/34560)).
- Allow customization of the `ARTIFACTS_PATH` in the `jest-environment-puppeteer` failed test reporter via the `WP_ARTIFACTS_PATH` environment variable ([#35371](https://github.com/WordPress/gutenberg/pull/35371)).

## 18.0.1 (2021-09-09)

Expand Down
6 changes: 6 additions & 0 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ This script automatically detects the best config to start Puppeteer but sometim

We enforce that all tests run serially in the current process using [--runInBand](https://jestjs.io/docs/en/cli#runinband) Jest CLI option to avoid conflicts between tests caused by the fact that they share the same WordPress instance.

#### Failed Test Artifacts

When tests fail, both a screenshot and an HTML snapshot will be taken of the page and stored in the `artifacts/` directory at the root of your project. These snapshots may help debug failed tests during development or when running tests in a CI environment.

The `artifacts/` directory can be customized by setting the `WP_ARTIFACTS_PATH` environment variable to the relative path of the desired directory within your project's root. For example: to change the default directory from `artifacts/` to `my/custom/artifacts`, you could use `WP_ARTIFACTS_PATH=my/custom/artifacts npm run test:e2e`.

#### Advanced information

It uses [Jest](https://jestjs.io/) behind the scenes and you are able to use all of its [CLI options](https://jestjs.io/docs/en/cli.html). You can also run `./node_modules/.bin/wp-scripts test:e2e --help` or `npm run test:e2e:help` (as mentioned above) to view all of the available options. Learn more in the [Advanced Usage](#advanced-usage) section.
Expand Down
7 changes: 5 additions & 2 deletions packages/scripts/config/jest-environment-puppeteer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ const KEYS = {
};

const root = process.env.GITHUB_WORKSPACE || process.cwd();
const ARTIFACTS_PATH = path.join( root, 'artifacts' );
const ARTIFACTS_PATH = path.resolve(
root,
process.env.WP_ARTIFACTS_PATH || 'artifacts'
);

class PuppeteerEnvironment extends NodeEnvironment {
// Jest is not available here, so we have to reverse engineer
Expand Down Expand Up @@ -171,7 +174,7 @@ class PuppeteerEnvironment extends NodeEnvironment {
await this.global.jestPuppeteer.resetBrowser();

try {
await mkdir( ARTIFACTS_PATH );
await mkdir( ARTIFACTS_PATH, { recursive: true } );
} catch ( err ) {
if ( err.code !== 'EEXIST' ) {
throw err;
Expand Down

0 comments on commit ef26639

Please sign in to comment.