Skip to content

Commit

Permalink
Allow instantiated reporters to be provided in the configuration
Browse files Browse the repository at this point in the history
This supports more complex scenarios than the --reporter= CLI flag
(multiple reporters, reporters that need configuration, reporters
that aren't default exports, etc) without pushing the complexity of
all of those scenarios into Jasmine or requiring the user to move
to programmatic usage.

See #77 and #159.
  • Loading branch information
sgravrock committed Oct 22, 2022
1 parent afbd58a commit 949b98f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions spec/jasmine_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 949b98f

Please sign in to comment.