{"library":"newman-reporter-ctrf-json","title":"Newman CTRF JSON Reporter","description":"newman-reporter-ctrf-json is a test reporter for Postman Newman, designed to output test execution results in the Common Test Report Format (CTRF) JSON specification. This standardized format enables machine-readable and consistent reporting across diverse testing tools and platforms, significantly streamlining integration into CI/CD pipelines for centralized test result analysis. Currently at version 0.0.13, the package is in early development, with iterative updates addressing bug fixes and minor enhancements, as indicated by recent `0.0.13-next-1` and `0.0.13` releases. Its primary advantage lies in providing a structured, interoperable JSON output, distinct from Newman's default proprietary JSON format, making it ideal for systems that consume CTRF.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install newman-reporter-ctrf-json"],"cli":null},"imports":["import CTRFReporter from 'newman-reporter-ctrf-json';","const CTRFReporter = require('newman-reporter-ctrf-json');","newman.run({ reporters: ['cli', 'ctrf-json'], reporter: { 'ctrf-json': { export: 'report.json' } } });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import newman from 'newman';\nimport path from 'path';\nimport fs from 'fs';\n\n// Create dummy Postman collection and environment files for a runnable example\nconst collectionPath = path.join(__dirname, 'postman_collection.json');\nconst environmentPath = path.join(__dirname, 'postman_environment.json');\nconst ctrfOutputPath = path.join(__dirname, 'ctrf-report.json');\n\nif (!fs.existsSync(collectionPath)) {\n  fs.writeFileSync(collectionPath, JSON.stringify({\n    info: { _postman_id: 'a1b2c3d4-e5f6-7890-1234-567890abcdef', name: 'Example Test Collection' },\n    item: [\n      { 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' } }] },\n      { 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' } }] }\n    ]\n  }, null, 2));\n}\n\nif (!fs.existsSync(environmentPath)) {\n  fs.writeFileSync(environmentPath, JSON.stringify({\n    id: 'fedcba98-7654-3210-fedc-ba9876543210', name: 'Test Environment', values: [{ key: 'baseUrl', value: 'https://postman-echo.com', enabled: true }]\n  }, null, 2));\n}\n\nconsole.log('Running Newman with CTRF JSON Reporter...');\n\n// Run Newman programmatically with the CTRF JSON reporter\nnewman.run({\n    collection: collectionPath,\n    environment: environmentPath,\n    reporters: ['cli', 'ctrf-json'], // Use 'cli' for console output, 'ctrf-json' for the report\n    reporter: {\n        'ctrf-json': {\n            export: ctrfOutputPath // Specify the output path for the CTRF report\n        }\n    }\n}, function (err, summary) {\n    if (err) {\n        console.error('Collection run encountered an error:', err);\n    }\n    if (summary && summary.run && summary.run.error) {\n        console.error('Collection run failed:', summary.run.error);\n    } else {\n        console.log('Collection run completed successfully!');\n        if (fs.existsSync(ctrfOutputPath)) {\n            const report = fs.readFileSync(ctrfOutputPath, 'utf8');\n            console.log(`CTRF report generated at ${ctrfOutputPath}. First 200 characters:\\n${report.substring(0, 200)}...`);\n        } else {\n            console.warn('CTRF report file not found, check reporter configuration or Newman execution.');\n        }\n    }\n});\n","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}