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

feat: add mocha reporter #116

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ node --test \

Available reporters:

- [bail](https://www.npmjs.com/package/@reporters/bail) - bail on first failure
- [github](https://www.npmjs.com/package/@reporters/github) - report to github actions
- [jUnit](https://www.npmjs.com/package/@reporters/junit) - report to jUnit
- [mocha](https://www.npmjs.com/package/@reporters/mocha) - use any mocha reporter with `node:test`
- [silent](https://www.npmjs.com/package/@reporters/silent) - a silent reporter
- [bail](https://www.npmjs.com/package/@reporters/bail) - bail on first failure
- [testwatch](https://www.npmjs.com/package/@reporters/testwatch) - An interactive REPL for `node:test` watch mode.
- [slow](https://www.npmjs.com/package/@reporters/slow) - report slow tests
- [testwatch](https://www.npmjs.com/package/@reporters/testwatch) - An interactive REPL for `node:test` watch mode.
2 changes: 1 addition & 1 deletion packages/bail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = async function* bail(source) {
/* c8 ignore start */
yield `\n\u001b[31m✖ Bailing on failed test: ${event.data.name}\u001b[0m\n`;
throw new Error('Bail');
/* c8 ignore stop */
}
/* c8 ignore stop */
}
};
61 changes: 0 additions & 61 deletions packages/github/tests/output.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "\n\n tests\n ✔ is ok\n 1) fails\n ✔ is a diagnostic\n 2) should fail\n\n more tests\n ✔ is ok\n\n - is skipped\n - is a todo\n ✔ top level diagnostic\n\n 4 passing (*ms)\n 2 pending\n 2 failing\n\n 1) \n tests\n fails:\n Error [ERR_TEST_FAILURE]: this is an error\n at async Promise.all (index 0)\n\n 2) \n tests\n should fail:\n Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:\n\n assert(false)\n\n \n\n\n\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "\n\n 1) should fail\n ✔ should pass\n\n 1 passing (*ms)\n 1 failing\n\n 1) \n should fail:\n Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:\n\n assert(false)\n\n \n\n\n\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is ok'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests fails'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is a diagnostic'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests should fail'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' more tests is ok'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is skipped'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is a todo'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' top level diagnostic'\n}\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is ok'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests fails'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is a diagnostic'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests should fail'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' more tests is ok'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is skipped'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is a todo'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' top level diagnostic'\n}\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'invalid' imported from CWD/packages/mocha/index.js\n *\n *\n *\n *\n *\n *\n *\n *\n *\n * {\n code: 'ERR_MODULE_NOT_FOUND'\n}\nError: invalid reporter \"invalid\"\n *\n *\n",
"stdout": "",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "\n\n tests\n ✔ is ok\n 1) fails\n ✔ is a diagnostic\n 2) should fail\n\n more tests\n ✔ is ok\n\n - is skipped\n - is a todo\n ✔ top level diagnostic\n\n 4 passing (*ms)\n 2 pending\n 2 failing\n\n 1) \n tests\n fails:\n Error [ERR_TEST_FAILURE]: this is an error\n \n\n 2) \n tests\n should fail:\n Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:\n\n assert(false)\n\n \n\n\n\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "\n\n 1) should fail\n ✔ should pass\n\n 1 passing (*ms)\n 1 failing\n\n 1) \n should fail:\n Error [ERR_TEST_FAILURE]: false == true\n \n\n\n\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is ok'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests fails'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is a diagnostic'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests should fail'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' more tests is ok'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is skipped'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is a todo'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' top level diagnostic'\n}\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is ok'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests fails'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is a diagnostic'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests should fail'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' more tests is ok'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is skipped'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is a todo'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' top level diagnostic'\n}\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'invalid' imported from CWD/packages/mocha/index.js\n *\n *\n *\n *\n *\n *\n *\n *\n *\n * {\n code: 'ERR_MODULE_NOT_FOUND'\n}\nError: invalid reporter \"invalid\"\n *\n *\n",
"stdout": "",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "\n\n tests\n ✔ is ok\n 1) fails\n ✔ is a diagnostic\n 2) should fail\n\n more tests\n ✔ is ok\n\n - is skipped\n - is a todo\n ✔ top level diagnostic\n\n 4 passing (*ms)\n 2 pending\n 2 failing\n\n 1) \n tests\n fails:\n Error [ERR_TEST_FAILURE]: this is an error\n \n\n 2) \n tests\n should fail:\n Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:\n\n assert(false)\n\n \n\n\n\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "\n\n 1) should fail\n ✔ should pass\n\n 1 passing (*ms)\n 1 failing\n\n 1) \n should fail:\n Error [ERR_TEST_FAILURE]: The expression evaluated to a falsy value:\n\n assert(false)\n\n \n\n\n\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is ok'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests fails'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is a diagnostic'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests should fail'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' more tests is ok'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is skipped'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is a todo'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' top level diagnostic'\n}\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "",
"stdout": "{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is ok'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests fails'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests is a diagnostic'\n}\n{\n state: 'failed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' tests should fail'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' more tests is ok'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is skipped'\n}\n{\n state: 'pending',\n isPending: true,\n currentRetry: 0,\n fullTitle: ' is a todo'\n}\n{\n state: 'passed',\n isPending: false,\n currentRetry: 0,\n fullTitle: ' top level diagnostic'\n}\n",
"exitCode": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stderr": "Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'invalid' imported from CWD/packages/mocha/index.js\n *\n *\n *\n *\n *\n *\n *\n *\n *\n * {\n code: 'ERR_MODULE_NOT_FOUND'\n}\nError: invalid reporter \"invalid\"\n *\n *\n",
"stdout": "",
"exitCode": 1
}
32 changes: 32 additions & 0 deletions packages/mocha/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[![npm version](https://img.shields.io/npm/v/@reporters/mocha)](https://www.npmjs.com/package/@reporters/mocha) ![tests](https://github.com/MoLow/reporters/actions/workflows/test.yaml/badge.svg?branch=main) [![codecov](https://codecov.io/gh/MoLow/reporters/branch/main/graph/badge.svg?token=0LFVC8SCQV)](https://codecov.io/gh/MoLow/reporters)

# Mocha reporters for `node:test`
Use this custom reporter to use [mocha reporters](https://mochajs.org/#reporters) with `node:test`.
Both built-in and custom mocha reporters such as [mochawesome](https://www.npmjs.com/package/mochawesome) are supported.

## Installation

```bash
npm install --save-dev @reporters/mocha
```
or
```bash
yarn add --dev @reporters/mocha
```

## Usage

Specify the desired mocha reporter inside the [mocha configuration file](https://mochajs.org/#configuring-mocha-nodejs), e.g. `.mocharc.js`:
```js
module.exports = {
reporter: '@reporters/mocha'
}
```

Then run the tests with `node:test`:

```bash
node --test --test-reporter=@reporters/mocha
```


Loading
Loading