mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
This makes a effort to make sure all of these errors will actually also show the received input. On top of that it refactors a few tests for better maintainability. It will also change the returned type to always be a simple typeof instead of special handling null. PR-URL: https://github.com/nodejs/node/pull/19445 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
'use strict';
|
|
// Flags: --expose-internals
|
|
|
|
// This test ensures that the type checking of ModuleMap throws
|
|
// errors appropriately
|
|
|
|
const common = require('../common');
|
|
|
|
const { URL } = require('url');
|
|
const Loader = require('internal/modules/esm/Loader');
|
|
const ModuleMap = require('internal/modules/esm/ModuleMap');
|
|
const ModuleJob = require('internal/modules/esm/ModuleJob');
|
|
const createDynamicModule = require('internal/modules/esm/CreateDynamicModule');
|
|
|
|
const stubModuleUrl = new URL('file://tmp/test');
|
|
const stubModule = createDynamicModule(['default'], stubModuleUrl);
|
|
const loader = new Loader();
|
|
const moduleMap = new ModuleMap();
|
|
const moduleJob = new ModuleJob(loader, stubModule.module,
|
|
() => new Promise(() => {}));
|
|
|
|
common.expectsError(
|
|
() => moduleMap.get(1),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "url" argument must be of type string. Received type number'
|
|
}
|
|
);
|
|
|
|
common.expectsError(
|
|
() => moduleMap.set(1, moduleJob),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "url" argument must be of type string. Received type number'
|
|
}
|
|
);
|
|
|
|
common.expectsError(
|
|
() => moduleMap.set('somestring', 'notamodulejob'),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "job" argument must be of type ModuleJob. ' +
|
|
'Received type string'
|
|
}
|
|
);
|
|
|
|
common.expectsError(
|
|
() => moduleMap.has(1),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "url" argument must be of type string. Received type number'
|
|
}
|
|
);
|