Jasmine JSON Test Reporter (Legacy)
This `jasmine-json-test-reporter` package offers a custom Jasmine reporter designed to output test results to a specified file in JSON format. It was created to provide more detailed and customizable JSON output than Protractor's `resultJsonOutputFile` option, and to allow dynamic assignment of output filenames, a feature not available in Protractor's configuration at the time. The package is currently at version `1.0.0-beta`, indicating it never reached a stable release. It appears to be unmaintained, with no recent updates or active development. For current projects requiring Jasmine JSON reporting, the actively maintained `jasmine-ctrf-json-reporter` (which adheres to the Common Test Report Format standard) is a recommended, modern alternative. This original package is primarily of historical interest or for maintaining legacy systems still reliant on its specific output structure.
Common errors
-
ReferenceError: require is not defined in ES module scope
cause Attempting to use `require()` from this CommonJS-only package in an ES Module context.fixIn a Node.js ES Module file (e.g., `.mjs` or when `type: "module"` in `package.json`), you can bridge to CommonJS using `import { createRequire } from 'module'; const require = createRequire(import.meta.url);` before using `require('jasmine-json-test-reporter')`. Alternatively, ensure your build setup correctly transpiles CommonJS imports for browser environments, or migrate to a modern ES-module compatible reporter.
Warnings
- deprecated The `jasmine-json-test-reporter` package is unmaintained and considered abandoned. Its `1.0.0-beta` status indicates it never reached a stable release, and it is not recommended for new projects. Users are strongly advised to migrate.
- breaking This package is likely incompatible with modern versions of Jasmine (e.g., Jasmine 3.x, 4.x, or 5.x) and newer Node.js environments due to lack of updates. This can lead to unexpected behavior, runtime errors, or incorrect reporting.
- gotcha This package exclusively uses CommonJS `require()` syntax. It does not support ES Modules (`import`/`export`) natively and will cause 'require is not defined' errors in ES Module-only environments without specific loader configurations or transpilation.
Install
-
npm install jasmine-json-test-reporter -
yarn add jasmine-json-test-reporter -
pnpm add jasmine-json-test-reporter
Imports
- JSONReporter
import { JSONReporter } from 'jasmine-json-test-reporter';const JSONReporter = require('jasmine-json-test-reporter');
Quickstart
const JSONReporter = require('jasmine-json-test-reporter');
// Configure and add the reporter to Jasmine
jasmine.getEnv().addReporter(new JSONReporter({
file: 'jasmine-test-results.json',
beautify: true,
indentationLevel: 4 // used if beautify === true
}));
// Example Jasmine spec (assuming it runs after reporter setup)
describe('Example Suite', function() {
it('should demonstrate a passing test', function() {
expect(true).toBe(true);
});
it('should demonstrate a failing test', function() {
expect(false).toBe(true); // This will fail
});
});