From d61b558e8df85cb60d09ca3e5b09653b4477cea7 Mon Sep 17 00:00:00 2001 From: Monkey Do Date: Tue, 30 Nov 2021 14:02:54 +0100 Subject: [PATCH] Update mocha-json usage instructions Cherry pick commit ceb9822f8b07d0b13c526c659140f92c94f5b4af --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 855867f..0d175a6 100644 --- a/README.md +++ b/README.md @@ -307,12 +307,22 @@ Configuration of `uniqueOutputName`, `suiteNameTemplate`, `classNameTemplate`, ` - Mocha version [v7.2.0](https://github.com/mochajs/mocha/releases/tag/v7.2.0) or higher - Usage of [json](https://mochajs.org/#json) reporter. -You can use the following example configuration in `package.json`: +For Mocha >= [v9.1.0](https://github.com/mochajs/mocha/releases/tag/v9.1.0), you can use the following example configuration in `package.json`: ```json "scripts": { "test": "mocha --reporter json --reporter-option output=test-results.json" } ``` + +For Mocha < v9.1, the command should look like this: +```json +"scripts": { + "test": "mocha --reporter json > test-results.json" +} +``` +Additionally, test processing might fail if any of your tests write anything on standard output. +Before version [v9.1.0](https://github.com/mochajs/mocha/releases/tag/v9.1.0), Mocha doesn't have the option to store `json` output directly to the file, and we have to rely on redirecting its standard output ([mocha#4607](https://github.com/mochajs/mocha/pull/4607)). +Please update Mocha to version [v9.1.0](https://github.com/mochajs/mocha/releases/tag/v9.1.0) or above if you encounter this issue.