Registry /
testing / newman-reporter-ctrf-json
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
CTRFReporter
✓ import CTRFReporter from 'newman-reporter-ctrf-json';
✗ import { CTRFReporter } from 'newman-reporter-ctrf-json';
For programmatic use, the reporter is typically imported as a default export (a constructor function) for Newman's API, rather than a named export. Most users will interact via the Newman CLI and not directly import this package.
CTRFReporter (CJS)
✓ const CTRFReporter = require('newman-reporter-ctrf-json');
CommonJS import for environments that do not support ES Modules. This pattern aligns with how many Node.js plugins, especially reporters, expose their primary interface.
Newman programmatic usage
✓ newman.run({ reporters: ['cli', 'ctrf-json'], reporter: { 'ctrf-json': { export: 'report.json' } } });
The most common programmatic use involves specifying 'ctrf-json' as a string in the `reporters` array of Newman's `run` options, letting Newman handle the internal loading of the reporter.
This quickstart demonstrates how to programmatically run a Postman collection using Newman and generate a CTRF JSON report. It shows how to specify the `ctrf-json` reporter and its output path within a Node.js script.
import newman from 'newman';
import path from 'path';
import fs from 'fs';
// Create dummy Postman collection and environment files for a runnable example
const collectionPath = path.join(__dirname, 'postman_collection.json');
const environmentPath = path.join(__dirname, 'postman_environment.json');
const ctrfOutputPath = path.join(__dirname, 'ctrf-report.json');
if (!fs.existsSync(collectionPath)) {
fs.writeFileSync(collectionPath, JSON.stringify({
info: { _postman_id: 'a1b2c3d4-e5f6-7890-1234-567890abcdef', name: 'Example Test Collection' },
item: [
{ name: 'Get Request', request: { url: 'https://postman-echo.com/get?foo=bar', method: 'GET' }, event: [{ listen: 'test', script: { exec: ['pm.test("Status code is 200", function () { pm.response.to.have.status(200); });'], type: 'text/javascript' } }] },
{ name: 'Post Request', request: { url: 'https://postman-echo.com/post', method: 'POST', body: { mode: 'raw', raw: '{"key":"value"}', options: { raw: { language: 'json' } } } }, event: [{ listen: 'test', script: { exec: ['pm.test("Response has key", function () { pm.expect(pm.response.json().data).to.have.property("key"); });'], type: 'text/javascript' } }] }
]
}, null, 2));
}
if (!fs.existsSync(environmentPath)) {
fs.writeFileSync(environmentPath, JSON.stringify({
id: 'fedcba98-7654-3210-fedc-ba9876543210', name: 'Test Environment', values: [{ key: 'baseUrl', value: 'https://postman-echo.com', enabled: true }]
}, null, 2));
}
console.log('Running Newman with CTRF JSON Reporter...');
// Run Newman programmatically with the CTRF JSON reporter
newman.run({
collection: collectionPath,
environment: environmentPath,
reporters: ['cli', 'ctrf-json'], // Use 'cli' for console output, 'ctrf-json' for the report
reporter: {
'ctrf-json': {
export: ctrfOutputPath // Specify the output path for the CTRF report
}
}
}, function (err, summary) {
if (err) {
console.error('Collection run encountered an error:', err);
}
if (summary && summary.run && summary.run.error) {
console.error('Collection run failed:', summary.run.error);
} else {
console.log('Collection run completed successfully!');
if (fs.existsSync(ctrfOutputPath)) {
const report = fs.readFileSync(ctrfOutputPath, 'utf8');
console.log(`CTRF report generated at ${ctrfOutputPath}. First 200 characters:\n${report.substring(0, 200)}...`);
} else {
console.warn('CTRF report file not found, check reporter configuration or Newman execution.');
}
}
});
Errors
Common errors & fixes
Error: Reporter 'ctrf-json' not found.
The `newman-reporter-ctrf-json` package is either not installed, or Newman cannot locate it in its search paths (e.g., `node_modules` for local installation, or global `node_modules` for global installation).
fixInstall the reporter package. For global Newman usage: `npm install -g newman newman-reporter-ctrf-json`. For local project usage: `npm install --save-dev newman newman-reporter-ctrf-json`.
CTRF report file not generated at specified path.
This can be due to an incorrect output path, insufficient file permissions for the specified directory, or an error during Newman's test execution that prevented the reporter from finalizing and writing the file.
fixVerify that the path provided to `--reporter-ctrf-json-export` (CLI) or `reporter['ctrf-json'].export` (programmatic API) is valid and that the process has write permissions for that directory. Check Newman's console output for any preceding errors.
Audit
Dependencies
newmanrequiredThis package is a reporter for Newman and requires it to execute tests.