Custom Mocha reporter that sends test data to IPC channels. Useful when you want to get test information in the separate process or when running Mocha programmatically.
Disclaimer: This package uses node-ipc in version 9.2.1 which should be free from malicious code
Defines whether reporter is run in client or server mode.
Available options:
- client - use Unix/Windows sockets - reporter run as client
- server - use Unix/Windows sockets - reporter run as server
- client-net - use TCP, TLS or UDP sockets - reporter run as client
- server-net - use TCP, TLS or UDP sockets - reporter run as server
More information about sockets and their advantages/disadvantages can be found in node-ipc
documentation.
The id of this socket or service.
This field has higher priority over id in nodeIpcConfig
object.
Type: string
If true all reporter data will be passed directly to ipc.
If false only test states will be sent.
Type: boolean
Default: false
Object passed to node-ipc
.
You can use it to set hostname, port, logging or more advanced options.
All available fields can be found in node-ipc
documentation.
npm i @nikkoni/ipc-mocha-reporter
yarn add @nikkoni/ipc-mocha-reporter
There are multiple ways you can set reporter in Mocha
"reporter": "@nikkoni/ipc-mocha-reporter",
"reporter-option": ["ipcMode=client", "ipcSocketId=custom-id"], // array, not object
You can also use JavaScript object, YAML or JSONC as seen here
import Mocha from 'mocha';
const mocha = new Mocha();
mocha.reporter('@nikkoni/ipc-mocha-reporter', { ipcMode: 'client', ipcSocketId: 'custom-id' });
mocha --reporter "@nikkoni/ipc-mocha-reporter" --reporter-options "ipcMode=client,ipcSocketId=custom-id"
const { defineConfig } = require('cypress')
module.exports = defineConfig({
reporter: '@nikkoni/ipc-mocha-reporter',
reporterOptions: {
ipcMode: 'client-net',
ipcSocketId: 'custom-id',
nodeIpcConfig: {
silent: false
}
}
})
import cypress from 'cypress';
cypress
.run({
reporter: '@nikkoni/ipc-mocha-reporter',
reporterOptions: {
ipcMode: 'client-net',
ipcSocketId: 'custom-id',
nodeIpcConfig: {
silent: false
}
}
})
cypress run --reporter "@nikkoni/ipc-mocha-reporter" --reporter-options "ipcMode=client,ipcSocketId=custom-id"
Event names are the same as mocha event names.
If sendAllData parameter is set to false the following data will be sent:
Event constant name | Event name | Data type |
---|---|---|
EVENT_RUN_BEGIN | start | {} |
EVENT_SUITE_BEGIN | suite | [ {[title]: "pending"} ] |
EVENT_TEST_PASS | pass | [ {[title]: "pass"} ] |
EVENT_TEST_FAIL | fail | [ {[title]: "fail"} ] |
EVENT_SUITE_END | suite end | [ {[title]: state} ] |
EVENT_RUN_END | end | {} |
If sendAllData parameter is set to true data types will be the same as mocha listener argument.
There is an additional event kill
that you can use to disconnect and force kill reporter process.
Example in JavaScript
import Mocha from 'mocha';
import ipc from 'node-ipc'
const mocha = new Mocha();
mocha.reporter(
'@nikkoni/ipc-mocha-reporter',
{ ipcMode: 'client', ipcSocketId: 'ipc-reporter' },
);
ipc.config.id = 'ipc-reporter';
ipc.serve(() => {
ipc.server.on(RunnerConstants.EVENT_TEST_PASS, (data) => {
const [[name, state]] = Object.entries(data);
console.log(`Test ${name} is ${state}`);
});
});
ipc.server.start();
mochaRunner = mocha.run();