npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nikkoni/ipc-mocha-reporter

v0.1.4

Published

### 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.

Downloads

19

Readme

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