Skip to content

Commit 1ae44b5

Browse files
committed
Added a test for using the provided loader to load reporters
1 parent e248807 commit 1ae44b5

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/command.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const path = require('path');
22
const fs = require('fs');
3-
const Loader = require('./loader');
43

54
exports = module.exports = Command;
65

@@ -166,7 +165,7 @@ async function registerReporter(reporterModuleName, jasmine) {
166165
let Reporter;
167166

168167
try {
169-
Reporter = await (jasmine.loader || new Loader()).load(resolveReporter(reporterModuleName));
168+
Reporter = await jasmine.loader.load(resolveReporter(reporterModuleName));
170169
} catch (e) {
171170
throw new Error('Failed to load reporter module '+ reporterModuleName +
172171
'\nUnderlying error: ' + e.stack + '\n(end underlying error)');

spec/command_spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require('fs');
22
const path = require('path');
33
const Command = require('../lib/command');
4+
const Loader = require("../lib/loader");
45

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

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

277+
it('uses the provided loader to load reporters', async function() {
278+
const reporterPath = path.resolve(path.join(__dirname, 'fixtures', 'customReporter.js'));
279+
spyOn(this.fakeJasmine.loader, 'load').and.callThrough();
280+
281+
await this.command.run(this.fakeJasmine, ['--reporter=' + reporterPath]);
282+
283+
expect(this.fakeJasmine.loader.load).toHaveBeenCalledWith(reporterPath);
284+
});
285+
275286
it('can specify a reporter that is an ES module', async function() {
276287
await this.command.run(this.fakeJasmine, ['--reporter=./spec/fixtures/customReporter.mjs']);
277288
expect(this.fakeJasmine.clearReporters).toHaveBeenCalled();

0 commit comments

Comments
 (0)