diff --git a/test/parallel/test-cli-syntax.js b/test/parallel/test-cli-syntax.js index d7781eddffbb42..c94780e6293933 100644 --- a/test/parallel/test-cli-syntax.js +++ b/test/parallel/test-cli-syntax.js @@ -4,6 +4,7 @@ const common = require('../common'); const assert = require('assert'); const spawnSync = require('child_process').spawnSync; const path = require('path'); +const errors = require('../../lib/internal/errors'); const node = process.execPath; @@ -76,7 +77,8 @@ const syntaxArgs = [ assert.strictEqual(c.stdout, '', 'stdout produced'); // stderr should have a module not found error message - const match = c.stderr.match(/^Error: Cannot find module/m); + const expectedError = new errors.Error('MODULE_NOT_FOUND', file); + const match = c.stderr.match(expectedError.message); assert(match, 'stderr incorrect'); assert.strictEqual(c.status, 1, 'code == ' + c.status); diff --git a/test/parallel/test-internal-modules.js b/test/parallel/test-internal-modules.js index 2f11ca18dd6b34..014edba89b09a9 100644 --- a/test/parallel/test-internal-modules.js +++ b/test/parallel/test-internal-modules.js @@ -2,10 +2,13 @@ const common = require('../common'); const path = require('path'); const assert = require('assert'); +const errors = require('../../lib/internal/errors'); +const internalModuleName = 'internal/freelist'; +const expectedError = new errors.Error('MODULE_NOT_FOUND', internalModuleName); assert.throws(function() { - require('internal/freelist'); -}, /^Error: Cannot find module 'internal\/freelist'$/); + require(internalModuleName); +}, new RegExp(expectedError.message)); assert.strictEqual( require(path.join(common.fixturesDir, 'internal-modules')), diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index b6de19856985ed..20eebcad808fdd 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -23,6 +23,7 @@ 'use strict'; const common = require('../common'); const assert = require('assert'); +const errors = require('../../lib/internal/errors'); common.globalCheck = false; common.refreshTmpDir(); @@ -343,8 +344,10 @@ function error_test() { expect: 'undefined\n' + prompt_unix }, // REPL should get a normal require() function, not one that allows // access to internal modules without the --expose_internals flag. - { client: client_unix, send: 'require("internal/repl")', - expect: /^Error: Cannot find module 'internal\/repl'/ }, + { + client: client_unix, send: 'require("internal/repl")', + expect: new RegExp(new errors.Error('MODULE_NOT_FOUND', 'internal/repl').message) + }, // REPL should handle quotes within regexp literal in multiline mode { client: client_unix, send: "function x(s) {\nreturn s.replace(/'/,'');\n}", diff --git a/test/sequential/test-module-loading.js b/test/sequential/test-module-loading.js index 1894bc20165b14..bd1714b66feb2b 100644 --- a/test/sequential/test-module-loading.js +++ b/test/sequential/test-module-loading.js @@ -24,6 +24,7 @@ require('../common'); const assert = require('assert'); const path = require('path'); const fs = require('fs'); +const errors = require('../../lib/internal/errors'); console.error('load test-module-loading.js'); @@ -120,8 +121,10 @@ console.error('test name clashes'); const my_path = require('../fixtures/path'); assert.ok(my_path.path_func instanceof Function); // this one does not exist and should throw -assert.throws(function() { require('./utils'); }, - /^Error: Cannot find module '.\/utils'$/); +const notFoundPath = './utils'; +const notFoundError = new errors.Error('MODULE_NOT_FOUND', notFoundPath); +assert.throws(function() { require(notFoundPath); }, + new RegExp(notFoundError.message)); let errorThrown = false; try { @@ -224,6 +227,7 @@ const children = module.children.reduce(function red(set, child) { assert.deepStrictEqual(children, { 'common.js': {}, + '../lib/internal/errors.js': {}, 'fixtures/not-main-module.js': {}, 'fixtures/a.js': { 'fixtures/b/c.js': {