Socket
Socket
Sign inDemoInstall

@japa/base-reporter

Package Overview
Dependencies
50
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @japa/base-reporter

Base reporter to create customized testing reporters for Japa


Version published
Weekly downloads
8.2K
decreased by-13.73%
Maintainers
2
Install size
2.56 MB
Created
Weekly downloads
 

Readme

Source

Japa Base Reporter

Base reporter to create customized testing reporters for Japa

The Base reporter abstracts the repetitive parts of creating a tests reporters.

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

Setup

Install the package from npm registry as follows:

npm i @japa/base-reporter

# Yarn lovers
yarn add @japa/base-reporter
import { BaseReporter } from '@japa/base-reporter'

class MyReporter extends BaseReporter {}

export const reporterFn = (myReporterOptions = {}) => {
  const myReporter = new MyReporter(myReporterOptions)
  return myReporter.boot.bind(reporter)
}

Handlers

The Base reporter invokes following methods as it receives the events from the runner. You can implement these methods to display the tests progress.

import type {
  TestEndNode,
  SuiteEndNode,
  GroupEndNode,
  TestStartNode,
  RunnerEndNode,
  GroupStartNode,
  SuiteStartNode,
  RunnerStartNode,
} from '@japa/core'

class SpecReporter extends BaseReporter {
  protected onTestStart(payload: TestStartNode) {
    console.log('test started')
  }
  protected onTestEnd(payload: TestEndNode) {
    console.log('test endeded')
  }

  protected onGroupStart(payload: GroupStartNode) {
    console.log('group started')
  }
  protected onGroupEnd(payload: GroupEndNode) {
    console.log('group ended')
  }

  protected onSuiteStart(payload: SuiteStartNode) {
    console.log('suite started')
  }
  protected onSuiteEnd(payload: SuiteEndNode) {
    console.log('suite ended')
  }

  protected async start(payload: RunnerStartNode) {
    console.log('test runner started. You can run async operations here')
  }
  protected async end(payload: RunnerEndNode) {
    console.log('test runner ended. You can run async operations here')
  }
}

Inherited properties

The following properties are available on the BaseReporter. These properties are available only after the boot method is called.

runner

Reference to underlying tests runner instance.

this.runner

currentFileName

Reference to the file name for which tests are getting executed. The filename is only available inside the test or group handlers.

this.currentFileName

currentSuiteName

Reference to the suite name for which tests are getting executed. The suite name is only available after the onSuiteStart handler call.

this.currentSuiteName

uncaughtExceptions

Uncaught exceptions collected while tests are running. We rely on process.on('uncaughtException') event to collect uncaught exceptions and display them with their stack trace at the end.

Printing tests summary

After all the tests have been finished, you can call the printSummary method to print a detailed summary of all tests alongside pretty diffs and pretty error stack trace.

You should call the printSummary method from the end handler.

class SpecReporter extends BaseReporter {
  protected async end() {
    const summary = await this.runner.getSummary()
    await this.printSummary(summary)
  }
}

FAQs

Last updated on 03 Mar 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc