Skip to content

Commit

Permalink
Docs: Demonstrate how to load custom reporter from local script
Browse files Browse the repository at this point in the history
It is not currently valid to pass `./foo.js` to `--reporter` because
cli/run.js and cli/find-reporter.js would be running require() relative
to where the qunit package is installed instead of the project directory.

We could make this work in the future, but this is how it works today.
  • Loading branch information
Krinkle committed Jul 22, 2024
1 parent c73e8e5 commit df5f7f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,16 @@ By default, the TAP reporter is used. This allows you to pair QUnit with any [TA
qunit test/ | tap-min
```

To change the reporting from QUnit itself, use `qunit --reporter <name>` to set a different reporter, where `<name>` can be the name of a built-in reporter, or an Node module that implements the [QUnit Reporter API](./api/callbacks/QUnit.on.md#reporter-api). The reporter will be loaded and initialised automatically.
To change the reporting from QUnit itself, use `qunit --reporter <name>` to set a different reporter, where `<name>` can be the name of a built-in reporter, or a Node module (e.g. npm package) that implements the [QUnit Reporter API](./api/callbacks/QUnit.on.md#reporter-api). The reporter will be loaded and initialised automatically.

To load a reporter from a local Node.js script, use `--require` instead.

Example:

```sh
qunit --reporter tap
qunit --reporter qunit-reporter-example
```

Built-in reporters:

Expand All @@ -157,6 +166,8 @@ qunit --require ./test/setup.js
QUnit.config.noglobals = true;
QUnit.config.notrycatch = true;

require('../build/my-custom-reporter.js').init(QUnit);

global.MyApp = require('./index');
```

Expand Down
2 changes: 2 additions & 0 deletions test/cli/fixtures/npm-reporter/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"version": "1.0.0",
"name": "npm-reporter",
"private": true,
"keywords": [
"qunit-plugin",
"js-reporter"
]
}

0 comments on commit df5f7f5

Please sign in to comment.