Skip to content

Commit

Permalink
Added a test for using the provided loader to load reporters
Browse files Browse the repository at this point in the history
  • Loading branch information
sgravrock committed Jan 9, 2022
1 parent e248807 commit 1ae44b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/command.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const path = require('path');
const fs = require('fs');
const Loader = require('./loader');

exports = module.exports = Command;

Expand Down Expand Up @@ -166,7 +165,7 @@ async function registerReporter(reporterModuleName, jasmine) {
let Reporter;

try {
Reporter = await (jasmine.loader || new Loader()).load(resolveReporter(reporterModuleName));
Reporter = await jasmine.loader.load(resolveReporter(reporterModuleName));
} catch (e) {
throw new Error('Failed to load reporter module '+ reporterModuleName +
'\nUnderlying error: ' + e.stack + '\n(end underlying error)');
Expand Down
11 changes: 11 additions & 0 deletions spec/command_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const path = require('path');
const Command = require('../lib/command');
const Loader = require("../lib/loader");

const projectBaseDir = 'spec/fixtures/sample_empty_project/';
const spec = path.join(projectBaseDir, 'spec');
Expand Down Expand Up @@ -54,6 +55,7 @@ describe('command', function() {

this.fakeJasmine = jasmine.createSpyObj('jasmine', ['loadConfigFile', 'addHelperFiles', 'addRequires', 'showColors', 'execute',
'randomizeTests', 'seed', 'coreVersion', 'clearReporters', 'addReporter']);
this.fakeJasmine.loader = new Loader();
this.fakeJasmine.env = jasmine.createSpyObj('env', ['configure']);
this.fakeJasmine.execute.and.returnValue(Promise.resolve());
});
Expand Down Expand Up @@ -272,6 +274,15 @@ describe('command', function() {
expect(this.fakeJasmine.addReporter).toHaveBeenCalledWith(jasmine.any(Reporter));
});

it('uses the provided loader to load reporters', async function() {
const reporterPath = path.resolve(path.join(__dirname, 'fixtures', 'customReporter.js'));
spyOn(this.fakeJasmine.loader, 'load').and.callThrough();

await this.command.run(this.fakeJasmine, ['--reporter=' + reporterPath]);

expect(this.fakeJasmine.loader.load).toHaveBeenCalledWith(reporterPath);
});

it('can specify a reporter that is an ES module', async function() {
await this.command.run(this.fakeJasmine, ['--reporter=./spec/fixtures/customReporter.mjs']);
expect(this.fakeJasmine.clearReporters).toHaveBeenCalled();
Expand Down

0 comments on commit 1ae44b5

Please sign in to comment.