@nikkoni/ipc-mocha-reporter

0.1.4 • Public • Published

IPC Mocha Reporter 🧱

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.

build CodeQL npm version npm downloads
Mocha reporter Cypress reporter

Table of Contents


Disclaimer: This package uses node-ipc in version 9.2.1 which should be free from malicious code

Configuration

ipcMode

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.

ipcSocketId

The id of this socket or service.
This field has higher priority over id in nodeIpcConfig object.
Type: string

sendAllData

If true all reporter data will be passed directly to ipc.
If false only test states will be sent.

Type: boolean
Default: false

nodeIpcConfig

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.


Instalation

NPM

npm i @nikkoni/ipc-mocha-reporter

Yarn

yarn add @nikkoni/ipc-mocha-reporter

Usage

Mocha

There are multiple ways you can set reporter in Mocha

.mocharc.json

  "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

Run programmatically

  import Mocha from 'mocha';

  const mocha = new Mocha();
  mocha.reporter('@nikkoni/ipc-mocha-reporter', { ipcMode: 'client', ipcSocketId: 'custom-id' });

From command-line / bash script

mocha --reporter "@nikkoni/ipc-mocha-reporter" --reporter-options "ipcMode=client,ipcSocketId=custom-id"

Cypress

cypress.config.js

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  reporter: '@nikkoni/ipc-mocha-reporter',
  reporterOptions: {
    ipcMode: 'client-net',
    ipcSocketId: 'custom-id',
    nodeIpcConfig: {
      silent: false
    }
  }
})

Run programmatically

import cypress from 'cypress';

cypress
  .run({
    reporter: '@nikkoni/ipc-mocha-reporter',
    reporterOptions: {
      ipcMode: 'client-net',
      ipcSocketId: 'custom-id',
      nodeIpcConfig: {
        silent: false
      }
    }
  })

From command-line / bash script

cypress run --reporter "@nikkoni/ipc-mocha-reporter" --reporter-options "ipcMode=client,ipcSocketId=custom-id"

Events

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

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();

Package Sidebar

Install

npm i @nikkoni/ipc-mocha-reporter

Weekly Downloads

3

Version

0.1.4

License

ISC

Unpacked Size

20.4 kB

Total Files

14

Last publish

Collaborators

  • mmuii
  • jonaszpotoniec