Skip to content

Commit e2a9380

Browse files
committed
Fixed loading of external reporters in the default configuration
* Fixes #189
1 parent 80b6c4c commit e2a9380

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/loader.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ function Loader(options) {
1111

1212
Loader.prototype.load = function(modulePath) {
1313
if ((this.alwaysImport && !modulePath.endsWith('.json')) || modulePath.endsWith('.mjs')) {
14-
// The ES module spec requires import paths to be valid URLs. As of v14,
15-
// Node enforces this on Windows but not on other OSes. On OS X, import
16-
// paths that are URLs must not contain parent directory references.
17-
const url = `file://${this.resolvePath_(modulePath)}`;
18-
return this.import_(url)
14+
let importSpecifier;
15+
16+
if (modulePath.indexOf('/') === -1) {
17+
importSpecifier = modulePath;
18+
} else {
19+
// The ES module spec requires import paths to be valid URLs. As of v14,
20+
// Node enforces this on Windows but not on other OSes. On OS X, import
21+
// paths that are URLs must not contain parent directory references.
22+
importSpecifier = `file://${this.resolvePath_(modulePath)}`;
23+
}
24+
25+
return this.import_(importSpecifier)
1926
.then(
2027
mod => mod.default,
2128
e => {

spec/loader_spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ describe('loader', function() {
3939
});
4040
});
4141

42+
it('imports non-local modules', async function() {
43+
const payload = {default: {}};
44+
const requireShim = jasmine.createSpy('requireShim');
45+
const importShim = jasmine.createSpy('importShim')
46+
.and.returnValue(Promise.resolve(payload));
47+
const loader = new Loader({requireShim, importShim});
48+
loader.alwaysImport = true;
49+
50+
const result = await loader.load('some-module');
51+
52+
expect(result).toBe(payload.default);
53+
expect(requireShim).not.toHaveBeenCalled();
54+
expect(importShim).toHaveBeenCalledWith('some-module');
55+
});
56+
4257
it('uses require to load JSON files', async function() {
4358
const requireShim = jasmine.createSpy('requireShim')
4459
.and.returnValue(Promise.resolve());

0 commit comments

Comments
 (0)