Jasmine CTRF JSON Reporter
jasmine-ctrf-json-reporter is a utility package that provides a Jasmine test results reporter, specifically designed to output test reports conforming to the Common Test Report Format (CTRF) schema. This package addresses the challenge of inconsistent test report formats across various programming languages and testing frameworks by offering a standardized output. The current stable version is `0.0.7`. While a formal release cadence is not explicitly stated, the project demonstrates ongoing maintenance with recent dependency updates and minor version bumps. Its primary differentiator is its strict adherence to the CTRF open standard, which enables uniform validation, merging, comparison, and analysis of test results, regardless of the underlying testing tool or language. This consistency significantly simplifies integration into CI/CD pipelines and provides a universal reporting schema that facilitates better programmatic analysis of test outcomes.
Common errors
-
ReferenceError: CtrfReporter is not defined
cause The `CtrfReporter` class was not imported or required correctly, or the module path is incorrect.fixEnsure you have `npm install --save-dev jasmine-ctrf-json-reporter` and use `const CtrfReporter = require('jasmine-ctrf-json-reporter');` for CommonJS or `import CtrfReporter from 'jasmine-ctrf-json-reporter';` for ESM. -
Error: Cannot find module 'jasmine-ctrf-json-reporter'
cause The package has not been installed or is not accessible in the current environment.fixRun `npm install --save-dev jasmine-ctrf-json-reporter` to add the package to your project. -
TypeError: jasmine.getEnv(...).addReporter is not a function
cause This error typically occurs if you're trying to add the reporter outside of a context where `jasmine.getEnv()` is available, or if Jasmine itself isn't properly set up.fixEnsure your reporter setup code is run within a Jasmine test environment, typically in a helper file loaded by Jasmine before test execution. -
File 'ctrf/ctrf-report.json' not found after tests complete.
cause The reporter did not execute, or the output directory/file name was customized and not found at the expected location.fixVerify the reporter is correctly added to `jasmine.getEnv().addReporter()` and check the `outputDir` and `outputFile` options. Ensure the test run completes without errors that might prevent the report from being written.
Warnings
- gotcha This package is still in early development (v0.0.x). While efforts are made for stability, the API may undergo breaking changes in minor versions. Always review the changelog when updating.
- gotcha The reporter is configured by adding it directly to the Jasmine environment (`jasmine.getEnv().addReporter()`), not through `jasmine.json` or other configuration files. Ensure this line is present in your `spec/support/jasmine.js` or similar setup file.
- gotcha The `outputFile` and `outputDir` options have default values (`ctrf-report.json` and `ctrf/`). If these are not specified, the output will be generated in the default location. Ensure your CI/CD pipelines are aware of these defaults or configure custom paths explicitly.
Install
-
npm install jasmine-ctrf-json-reporter -
yarn add jasmine-ctrf-json-reporter -
pnpm add jasmine-ctrf-json-reporter
Imports
- CtrfReporter
const CtrfReporter = require('jasmine-ctrf-json-reporter');import CtrfReporter from 'jasmine-ctrf-json-reporter';
- ctrf
import ctrf from 'jasmine-ctrf-json-reporter';
import { ctrf } from 'jasmine-ctrf-json-reporter'; - ReporterOptions
import { ReporterOptions } from 'jasmine-ctrf-json-reporter';import type { ReporterOptions } from 'jasmine-ctrf-json-reporter';
Quickstart
import CtrfReporter, { ctrf } from 'jasmine-ctrf-json-reporter';
// In your Jasmine helper file (e.g., spec/support/jasmine.js or .ts)
// It's recommended to configure the reporter here.
jasmine.getEnv().addReporter(
new CtrfReporter({
outputFile: 'my-custom-ctrf-report.json', // Optional: Custom output file name
outputDir: 'reports/ctrf-output', // Optional: Custom output directory
appName: 'MyFeatureApp', // Optional: Application name
appVersion: '1.2.3', // Optional: Application version
osPlatform: process.env.OS_PLATFORM ?? 'web', // Dynamically set OS platform
osRelease: process.env.OS_RELEASE ?? 'latest',
buildName: 'CI-Pipeline-Build', // Optional: Build name
buildNumber: process.env.BUILD_NUMBER ?? 'unknown' // Dynamic build number
})
);
// Example of usage within a test file (e.g., spec/my-feature.spec.ts)
describe('User Management Module', () => {
it('should successfully register a new user', () => {
// Attach custom metadata to this specific test result
ctrf.extra({ owner: 'user-auth-team', priority: 'high', testId: 'UM-001' });
// ... actual test logic for user registration ...
expect(true).toBe(true); // Placeholder for actual test
});
it('should validate email format during registration', () => {
// This test might not need extra metadata
expect(false).toBe(false); // Another placeholder test
});
});