Commit 1bffcb16 authored by Dan Allen's avatar Dan Allen
Browse files

allow coverage npm script to be run per package and document how to invoke it [skip ci]

parent 8c92bd9d
Loading
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -687,7 +687,7 @@ This project uses {url-mocha}[mocha] to run the tests and the assertion library
Mocha is configured in [.path]_.mocharc.js_.
The build script is automatically configured to lint your JavaScript code, which it does once all the tests pass.

To run the test suite, use:
To run the test suite and linter, use:

 $ npm run build

@@ -733,7 +733,11 @@ You can include the linter as well:

 $ npm build --package ui-loader

This filter works for all npm scripts.
You can include multiple packages using the syntax `{a,b}` enclosed in single quotes.

 $ npm build --package '{playbook-builder,ui-loader}'

The `--package` filter works for all npm scripts.

If you're working on tests or refactoring the code under test, you can run the test suite continuously by adding the `--watch` option:

@@ -752,6 +756,13 @@ We can use this, for instance, to specify which files to watch:

Run `npx mocha --help` to discover other options.

If you want to run the code coverage on a single package, use the `--package-filter` option followed by the name of the package offset by an equals sign (not a space).

 $ npm run coverage --package-filter=ui-loader

The `--package` option doesn't work in this instance since it conficts with npx.
In fact, you can always use the `--package-filter` option in all previous examples.

=== Select or Skip Tests

You can run select tests by appending `.only` to the `describe` and/or `it` method calls (e.g., `it.only()`.
+2 −1
Original line number Diff line number Diff line
@@ -33,8 +33,9 @@ function logCoverageReportPath () {
function resolveSpec () {
  const spec = process.argv[2]
  if (spec && !spec.startsWith('-')) return spec
  const packageFilter = process.env.npm_config_package_filter || process.env.npm_config_package || '*'
  return process.env.npm_package_json === require('node:path').join(process.env.npm_config_local_prefix, 'package.json')
    ? `packages/${process.env.npm_config_package || '*'}/test/**/*-test.js`
    ? `packages/${packageFilter}/test/**/*-test.js`
    : 'test/**/*-test.js'
}