diff --git a/lib/jasmine.js b/lib/jasmine.js index 1ac5c4cc..3a90ad5a 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -384,6 +384,24 @@ class Jasmine { if(config.spec_files) { this.addMatchingSpecFiles(config.spec_files); } + + /** + * An array of reporters. Each object in the array will be passed to + * {@link Jasmine#addReporter|addReporter}. + * + * This provides a middle ground between the --reporter= CLI option and full + * programmatic usage. Note that because reporters are objects with methods, + * this option can only be used in JavaScript config files + * (e.g `spec/support/jasmine.js`), not JSON. + * @name Configuration#reporters + * @type Reporter[] | undefined + * @see custom_reporter + */ + if (config.reporters) { + for (const r of config.reporters) { + this.addReporter(r); + } + } } addRequires(requires) { diff --git a/spec/jasmine_spec.js b/spec/jasmine_spec.js index efd697f9..49440e3b 100644 --- a/spec/jasmine_spec.js +++ b/spec/jasmine_spec.js @@ -385,6 +385,17 @@ describe('Jasmine', function() { expect(this.fixtureJasmine.alwaysListPendingSpecs_).toBeTrue(); }); + + it('adds specified reporters', function() { + const reporter1 = {id: 'reporter1'}; + const reporter2 = {id: 'reporter2'}; + this.configObject.reporters = [reporter1, reporter2]; + + this.fixtureJasmine.loadConfig(this.configObject); + + expect(this.fixtureJasmine.env.addReporter).toHaveBeenCalledWith(reporter1); + expect(this.fixtureJasmine.env.addReporter).toHaveBeenCalledWith(reporter2); + }); }); describe('from a file', function() {