Skip to content

Commit

Permalink
test case refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jun 18, 2018
1 parent 233cf2a commit d434368
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
14 changes: 8 additions & 6 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -1207,18 +1207,20 @@ is not supported.
<a id="ERR_INVALID_RETURN_PROPERTY"></a>
### ERR_INVALID_RETURN_PROPERTY

Thrown in case a function option does not return an expected property type.
Thrown in case a function option does not provide a valid value for one of its
returned object properties on execution.

<a id="ERR_INVALID_RETURN_PROPERTY_STRING"></a>
### ERR_INVALID_RETURN_PROPERTY_STRING
<a id="ERR_INVALID_RETURN_PROPERTY_VALUE"></a>
### ERR_INVALID_RETURN_PROPERTY_VALUE

Thrown in case a function option does not return an expected string property
type.
Thrown in case a function option does not provide an expected value
type for one of its returned object properties on execution.

<a id="ERR_INVALID_RETURN_VALUE"></a>
### ERR_INVALID_RETURN_VALUE

Thrown in case a function option does not return an expected value on execution.
Thrown in case a function option does not return an expected value
type on execution.
For example when a function is expected to return a promise.

<a id="ERR_INVALID_SYNC_FORK_INPUT"></a>
Expand Down
12 changes: 6 additions & 6 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,18 +682,18 @@ E('ERR_INVALID_PROTOCOL',
E('ERR_INVALID_REPL_EVAL_CONFIG',
'Cannot specify both "breakEvalOnSigint" and "eval" for REPL', TypeError);
E('ERR_INVALID_RETURN_PROPERTY', (input, name, prop, value) => {
return `Expected a valid ${input} to be returned for the "${prop}" from the` +
` "${name}" function but got ${value}.`;
}, TypeError);
E('ERR_INVALID_RETURN_PROPERTY_VALUE', (input, name, prop, value) => {
let type;
if (value && value.constructor && value.constructor.name) {
type = `instance of ${value.constructor.name}`;
} else {
type = `type ${typeof value}`;
}
return `Expected ${input} to be returned for the ${prop} from the ` +
`"${name}" function but got ${type}.`;
}, TypeError);
E('ERR_INVALID_RETURN_PROPERTY_STRING', (input, name, prop, value) => {
return `Expected a valid ${input} to be returned for the ${prop} from the ` +
`"${name}" function but got ${value}.`;
return `Expected ${input} to be returned for the "${prop}" from the` +
` "${name}" function but got ${type}.`;
}, TypeError);
E('ERR_INVALID_RETURN_VALUE', (input, name, value) => {
let type;
Expand Down
12 changes: 6 additions & 6 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_RETURN_PROPERTY,
ERR_INVALID_RETURN_PROPERTY_STRING,
ERR_INVALID_RETURN_PROPERTY_VALUE,
ERR_INVALID_RETURN_VALUE,
ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK,
ERR_UNKNOWN_MODULE_FORMAT
Expand Down Expand Up @@ -65,13 +65,13 @@ class Loader {
const { url, format } = resolved;

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

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

if (format === 'builtin')
Expand All @@ -81,14 +81,14 @@ class Loader {
try {
new URL(url);
} catch (e) {
throw new ERR_INVALID_RETURN_PROPERTY_STRING(
throw new ERR_INVALID_RETURN_PROPERTY(
'url', 'loader resolve', 'url', url
);
}
}

if (format !== 'dynamic' && !url.startsWith('file:'))
throw new ERR_INVALID_RETURN_PROPERTY_STRING(
throw new ERR_INVALID_RETURN_PROPERTY(
'file: url', 'loader resolve', 'url', url
);

Expand Down
7 changes: 4 additions & 3 deletions test/es-module/test-esm-loader-invalid-url.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import assert from 'assert';

import('../fixtures/es-modules/test-esm-ok.mjs')
.then(assert.fail, expectsError({
code: 'ERR_INVALID_RETURN_PROPERTY_STRING',
message: 'Expected a valid url to be returned for the url from the "loader ' +
'resolve" function but got ../fixtures/es-modules/test-esm-ok.mjs.'
code: 'ERR_INVALID_RETURN_PROPERTY',
message: 'Expected a valid url to be returned for the "url" from the ' +
'"loader resolve" function but got ' +
'../fixtures/es-modules/test-esm-ok.mjs.'
}))
.then(mustCall());

0 comments on commit d434368

Please sign in to comment.