Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

japa/synthetic-events

Repository files navigation

@japa/synthetic-events

Dummy events to build a Japa tests reporter

github-actions-image npm-image license-image typescript-image

Synthetic events emits a variety of dummy events you can use to build a test reporter for Japa.

Installation

Install the package from npm registry as follows.

npm i -D @japa/synthetic-events

# yarn
yarn add -D @japa/synthetic-events

Usage

In the following example, the yourReporter refers to the implementation of the reporter. Feel free to change the implementation.

import { Emitter, Runner } from '@japa/core'
import { fire } from '@japa/synthetic-events'

const emitter = new Emitter()
const runner = new Runner(emitter)

yourReporter()(runner, emitter)
runner['boot']()

fire(emitter)
import type { Emitter, Runner } from '@japa/core'

export function yourReporter() {
  return function (runner: Runner, emitter: Emitter) {
    emitter.on('suite:start', (suite) => console.log(suite.name))
    emitter.on('group:start', (group) => console.log(`  ${group.title}`))
    emitter.on('test:end', (test) => {
      console.log(`    > ${test.title} (${test.duration})`)
    })
  }
}