{"id":11125,"library":"jasmine-reporters","title":"Jasmine Reporters","description":"jasmine-reporters is a collection of JavaScript reporter classes designed for the Jasmine BDD testing framework. As of version 2.5.2, it primarily supports Jasmine 2.x, with a dedicated branch and older npm versions available for Jasmine 1.x compatibility. The library offers a variety of output formats, including standard options like JUnit XML, NUnit XML, and TAP (Test Anything Protocol), alongside specialized reporters for build systems such as TeamCity and AppVeyor, and a colorized Terminal Reporter. It differentiates itself by providing robust support for both Node.js environments and in-browser testing via PhantomJS, including mechanisms for local filesystem writes in headless browser contexts. While no explicit release cadence is documented, major versions of jasmine-reporters historically align with significant Jasmine framework updates, requiring users to match the reporter library version to their Jasmine version.","status":"active","version":"2.5.2","language":"javascript","source_language":"en","source_url":"git://github.com/larrymyers/jasmine-reporters","tags":["javascript"],"install":[{"cmd":"npm install jasmine-reporters","lang":"bash","label":"npm"},{"cmd":"yarn add jasmine-reporters","lang":"bash","label":"yarn"},{"cmd":"pnpm add jasmine-reporters","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package provides reporters for the Jasmine BDD testing framework. It is a peer dependency; ensure your Jasmine version is compatible with the jasmine-reporters version.","package":"jasmine","optional":false},{"reason":"Required for browser-side file writing functionality when running tests via PhantomJS, particularly for JUnitXmlReporter and NUnitXmlReporter.","package":"phantomjs-prebuilt","optional":true}],"imports":[{"note":"All reporters are named exports in ESM. In CommonJS, they are properties of the default export object.","wrong":"import JUnitXmlReporter from 'jasmine-reporters';","symbol":"JUnitXmlReporter","correct":"import { JUnitXmlReporter } from 'jasmine-reporters';"},{"note":"For CommonJS, the module exports an object containing all reporters as properties. Direct destructuring can work but accessing via the `reporters` object is the canonical pattern shown in documentation.","wrong":"const { JUnitXmlReporter } = require('jasmine-reporters');","symbol":"reporters","correct":"const reporters = require('jasmine-reporters');\nconst junitReporter = new reporters.JUnitXmlReporter(/* ... */);"},{"note":"When used in browser environments by including the script tag, the reporters are exposed globally under the `jasmineReporters` object.","symbol":"jasmineReporters (global)","correct":"var junitReporter = new jasmineReporters.JUnitXmlReporter(/* ... */);"}],"quickstart":{"code":"const Jasmine = require('jasmine');\nconst reporters = require('jasmine-reporters');\nconst path = require('path');\n\nconst jasmine = new Jasmine();\n\n// Configure a JUnit XML Reporter\nconst junitReporter = new reporters.JUnitXmlReporter({\n  savePath: path.join(__dirname, 'test-results'), // Directory to save XML files\n  filePrefix: 'test-result-',\n  consolidateAll: true, // Consolidate all specs into a single XML file per suite\n  use misfortunes: true\n});\n\n// Add the reporter to Jasmine\njasmine.addReporter(junitReporter);\n\n// Define a simple spec file for demonstration\n// In a real project, these would be separate files.\nconst specCode = `\ndescribe('A suite', function() {\n  it('contains spec with an expectation', function() {\n    expect(true).toBe(true);\n  });\n  it('contains another spec', function() {\n    expect(1 + 1).toBe(2);\n  });\n});\n`;\n\n// Create a temporary spec file for Jasmine to find\nconst fs = require('fs');\nconst specFilePath = path.join(__dirname, 'temp-spec.js');\nfs.writeFileSync(specFilePath, specCode);\n\n// Configure Jasmine to find specs\njasmine.specDir = __dirname;\njasmine.specFiles = ['temp-spec.js'];\n\n// Execute the tests\njasmine.execute();\n\n// Clean up temporary file after tests (simplified, should use 'afterAll' in real test suite)\nprocess.on('exit', () => {\n  if (fs.existsSync(specFilePath)) {\n    fs.unlinkSync(specFilePath);\n  }\n  console.log('Test execution complete. Check test-results directory.');\n});","lang":"javascript","description":"This quickstart demonstrates how to set up and use the JUnitXmlReporter with Jasmine in a Node.js environment, showing how to instantiate the reporter and add it to Jasmine, then execute a basic test suite."},"warnings":[{"fix":"Ensure your jasmine-reporters version matches your Jasmine framework's major version. For Jasmine 1.x, use `npm install jasmine-reporters@^1.0.0`. For Jasmine 2.x, use `npm install jasmine-reporters@^2.0.0` or higher.","message":"Version 2.x of jasmine-reporters is built exclusively for Jasmine 2.x. Using it with Jasmine 1.x will lead to runtime errors due to API incompatibilities. Conversely, older 1.x versions of jasmine-reporters are incompatible with Jasmine 2.x.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Update your reporter instantiation calls. In browsers, use `new jasmineReporters.ReporterName(...)`. In Node.js, use `const reporters = require('jasmine-reporters'); new reporters.ReporterName(...)`.","message":"In jasmine-reporters 2.x, reporters are no longer registered directly on the global `jasmine` object (e.g., `new jasmine.JUnitXmlReporter()`). Instead, they are accessed via the `jasmineReporters` global object in browsers or as properties of the `require('jasmine-reporters')` object in Node.js.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Refactor reporter constructor calls to pass a single object with key-value pairs for configuration options, e.g., `new reporters.JUnitXmlReporter({ savePath: '...', consolidateAll: true })`.","message":"Configuration for reporters in jasmine-reporters 2.x moved from positional arguments to a single configuration object. Older 1.x code using multiple arguments will fail or behave unexpectedly.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"It is strongly recommended to use the `phantomjs.runner.sh` script provided by `jasmine-reporters` as it handles the `__phantom_writeFile` injection. If using a custom runner, ensure you manually inject this method and handle test completion detection.","message":"When using `JUnitXmlReporter` or `NUnitXmlReporter` for in-browser tests run via PhantomJS, a special `__phantom_writeFile` method must be injected into the PhantomJS environment to enable file system writes. Using a custom PhantomJS runner without this injection will prevent output files from being created.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"For jasmine-reporters 2.x, use `new jasmineReporters.JUnitXmlReporter(...)` in browsers, or `new require('jasmine-reporters').JUnitXmlReporter(...)` in Node.js.","cause":"Attempting to instantiate a reporter using the Jasmine 1.x API (`jasmine.ReporterName`) with jasmine-reporters 2.x.","error":"TypeError: jasmine.JUnitXmlReporter is not a constructor"},{"fix":"In Node.js, use `const reporters = require('jasmine-reporters');`. In a browser, ensure the jasmine-reporters script is loaded via a `<script>` tag before your test setup code.","cause":"Trying to use the `jasmineReporters` global object in a Node.js environment or in a browser without the jasmine-reporters script being loaded.","error":"ReferenceError: jasmineReporters is not defined"},{"fix":"Ensure the directory specified in the `savePath` option exists before running tests. You may need to create it programmatically using `fs.mkdirSync(path, { recursive: true })` in Node.js.","cause":"The `savePath` directory specified for XML reporters (JUnit, NUnit) does not exist, and the reporter does not automatically create it.","error":"ENOENT: no such file or directory, open '...'"}],"ecosystem":"npm"}