Skip to content

Commit

Permalink
format case test and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jun 26, 2018
1 parent d434368 commit a235f08
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class Loader {
);

if (typeof format !== 'string')
throw new ERR_INVALID_RETURN_PROPERTY(
'module format', 'loader resolve', 'format', format
throw new ERR_INVALID_RETURN_PROPERTY_VALUE(
'string', 'loader resolve', 'format', format
);

if (format === 'builtin')
Expand Down
11 changes: 11 additions & 0 deletions test/es-module/test-esm-loader-invalid-format.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-invalid-format.mjs
import { expectsError, mustCall } from '../common';
import assert from 'assert';

import('../fixtures/es-modules/test-esm-ok.mjs')
.then(assert.fail, expectsError({
code: 'ERR_INVALID_RETURN_PROPERTY_VALUE',
message: 'Expected string to be returned for the "format" from the ' +
'"loader resolve" function but got type undefined.'
}))
.then(mustCall());
8 changes: 8 additions & 0 deletions test/fixtures/es-module-loaders/loader-invalid-format.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export async function resolve(specifier, parentModuleURL, defaultResolve) {
if (parentModuleURL && specifier === '../fixtures/es-modules/test-esm-ok.mjs') {
return {
url: 'file:///asdf'
};
}
return defaultResolve(specifier, parentModuleURL);
}

0 comments on commit a235f08

Please sign in to comment.