パッケージの詳細

js-reporters

js-reporters243kMIT2.1.0

Common reporter interface for JavaScript testing frameworks.

readme

js-reporters

Chat on Gitter Build Status Coverage Status npm npm

The Common Reporter Interface (CRI) for JavaScript Testing Frameworks.

Avoid this: Do this:

Specification

See Common Reporter Interface for the latest version of the specification.

See also:

  • example, illustrates how reporting works in practice.
  • frameworks, studies various popular testing frameworks.
  • Integrations, a list of real-world implementations.

Help with AsciiDoc (used for the standard document):

Background

In 2014, the QUnit team started discussing the possibility of interoperability between JavaScript testing frameworks such as QUnit, Mocha, Jasmine, Intern, Buster, etc. The "Common Reporter Interface" would be an allow integrations for output formats and communication bridges to be shared between frameworks. This would also benefit high-level consumers of these frameworks such as Karma, BrowserStack, SauceLabs, Testling, by having a standard machine-readable interface.

Our mission is to deliver:

  • a common JavaScript API, e.g. based on EventEmitter featuring .on() and .off().
  • a minimum viable set of events with standardized event names and event data.
  • a minimum viable set of concepts behind those events to allow consumers to set expectations (e.g. define what "pass", "fail", "skip", "todo", and "pending" mean).
  • work with participating testing frameworks to support the Common Reporter Interface.

Would you be interested in discussing this with us further? Please join in!

js-reporters Package

Usage

Listen to the events and receive the emitted data:

// Use automatic discovery of the framework adapter.
const runner = JsReporters.autoRegister();

// Listen to standard events, from any testing framework.
runner.on('testEnd', (test) => {
  console.log('Test %s has errors:', test.fullName.join(' '), test.errors);
});

runner.on('runEnd', (run) => {
  const counts = run.testCounts;

  console.log('Testsuite status: %s', run.status);
  console.log('Total %d tests: %d passed, %d failed, %d skipped',
    counts.total,
    counts.passed,
    counts.failed,
    counts.skipped
  );
  console.log('Total duration: %d', run.runtime);
});

// Or use one of the built-in reporters.
JsReporters.TapReporter.init(runner);

Runtime support

  • Internet Explorer 9+
  • Edge 15+ (Legacy)
  • Edge 80+ (Chromium-based)
  • Safari 9+
  • Firefox 45+
  • Chrome 58+
  • Node.js 10+

Adapter support

Testing framework Supported Last checked Unresolved
QUnit 1.20+ qunit@2.14.1 (Apr 2021)
Jasmine 2.1+ jasmine@3.7.0 (Apr 2021)
Mocha 1.18+ mocha@8.3.2 (Apr 2021)

See also past issues.

API

autoRegister()

Automatically detects which testing framework you use and attaches any adapters as needed, and returns a compatible runner object. If no framework is found, it will throw an Error.

JsReporters.autoRegister();

Integrations

Runners:

Reporters:

  • TAP, implements the Test Anything Protocol for command-line output.
  • browserstack-runner, runs JavaScript unit tests remotely in multiple browsers, summarize the results by browser, and fail or pass the continuous integration build accordingly.
  • Add your own, and let us know!

Cross-project coordination

Testing frameworks:

Reporters and proxy layers:

Credits

Testing Powered By SauceLabs

更新履歴

Changelog for the js-reporters package. See spec/ for the CRI standard.

2.1.0 / 2021-06-06

Added

  • QUnitAdapter: Support for todo tests. (Timo Tijhof) #140

2.0.0 / 2021-04-04

This release provides a simplified spec, with various properties and features removed. Overall the new spec is considered narrower than the previous one. Existing reporters that support old producers should naturally support new producers as well. Existing producers can choose to remain unchanged or to remove older portions in a future release.

Added

  • Add SummaryReporter implementation.

Changed

  • Spec: Rewrite current proposal into a formal specification at spec/. (Timo Tijhof)
  • Spec: Remove "todo" from Assertion event data. #119
  • Spec: Remove "tests" and "childSuites" from SuiteStart and SuiteEnd event data.
  • Spec: Prefer null instead of undefined for optional fields.
  • TapReporter: Improve formatting of multi-line strings. #109

Fixed

  • TapReporter: Fix support objects with cycles, avoiding uncaught errors. (Zachary Mulgrew) #104
  • TapReporter: Defend against mocked console object. #125
  • MochaAdapter: Fix support for Mocha 8, due to changes in STATE_PENDING. #116

Removed

  • Remove support for Node.js 8 and older. This release requires Node.js 10 or later. (Browser support has not changed and remains IE 9+, see README.)
  • Helpers: Remove the Assertion, Test, and Suite classes.
  • Helpers: Remove collectSuite{Start,StartData,EndData} methods.

1.2.3 / 2020-09-07

Changed

  • TapReporter: Align actual with expected in TAP output. (Robert Jackson) #107

Fixed

  • Helpers: Correct spelling in autoRegister() error message. (P. Roebuck) #108
  • TapReporter: Revert "Fix YAML syntax". #110

1.2.2 / 2019-05-13

Fixed

  • TapReporter: Fix YAML syntax. (jeberger) #110

1.2.1 / 2017-07-04

Changed

  • TapReporter: Print "actual:", "expected:" even if undefined. (Martin Olsson)

Fixed

  • TapReporter: Drop accidentally committed console.warn() statement. (Martin Olsson)

1.2.0 / 2017-03-22

Added

  • TapReporter: Improve TAP information and styling. (Florentin Simion)
  • TapReporter: Support todo test in TAP reporter. (Trent Willis)
  • Docs: Add API docs for the js-reporters package. (Florentin Simion)