Skip to content

Commit f7556d5

Browse files
committed
test: match expected errors in tests from internal/errors
1 parent cc5e4cb commit f7556d5

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

test/parallel/test-cli-syntax.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const common = require('../common');
44
const assert = require('assert');
55
const spawnSync = require('child_process').spawnSync;
66
const path = require('path');
7+
const errors = require('../../lib/internal/errors');
78

89
const node = process.execPath;
910

@@ -76,7 +77,8 @@ const syntaxArgs = [
7677
assert.strictEqual(c.stdout, '', 'stdout produced');
7778

7879
// stderr should have a module not found error message
79-
const match = c.stderr.match(/^Error: Cannot find module/m);
80+
const expectedError = new errors.Error('MODULE_NOT_FOUND', file);
81+
const match = c.stderr.match(expectedError.message);
8082
assert(match, 'stderr incorrect');
8183

8284
assert.strictEqual(c.status, 1, 'code == ' + c.status);

test/parallel/test-internal-modules.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
const common = require('../common');
33
const path = require('path');
44
const assert = require('assert');
5+
const errors = require('../../lib/internal/errors');
56

7+
const internalModuleName = 'internal/freelist';
8+
const expectedError = new errors.Error('MODULE_NOT_FOUND', internalModuleName);
69
assert.throws(function() {
7-
require('internal/freelist');
8-
}, /^Error: Cannot find module 'internal\/freelist'$/);
10+
require(internalModuleName);
11+
}, new RegExp(expectedError.message));
912

1013
assert.strictEqual(
1114
require(path.join(common.fixturesDir, 'internal-modules')),

test/parallel/test-repl.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'use strict';
2424
const common = require('../common');
2525
const assert = require('assert');
26+
const errors = require('../../lib/internal/errors');
2627

2728
common.globalCheck = false;
2829
common.refreshTmpDir();
@@ -343,8 +344,10 @@ function error_test() {
343344
expect: 'undefined\n' + prompt_unix },
344345
// REPL should get a normal require() function, not one that allows
345346
// access to internal modules without the --expose_internals flag.
346-
{ client: client_unix, send: 'require("internal/repl")',
347-
expect: /^Error: Cannot find module 'internal\/repl'/ },
347+
{
348+
client: client_unix, send: 'require("internal/repl")',
349+
expect: new RegExp(new errors.Error('MODULE_NOT_FOUND', 'internal/repl').message)
350+
},
348351
// REPL should handle quotes within regexp literal in multiline mode
349352
{ client: client_unix,
350353
send: "function x(s) {\nreturn s.replace(/'/,'');\n}",

test/sequential/test-module-loading.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ require('../common');
2424
const assert = require('assert');
2525
const path = require('path');
2626
const fs = require('fs');
27+
const errors = require('../../lib/internal/errors');
2728

2829
console.error('load test-module-loading.js');
2930

@@ -120,8 +121,10 @@ console.error('test name clashes');
120121
const my_path = require('../fixtures/path');
121122
assert.ok(my_path.path_func instanceof Function);
122123
// this one does not exist and should throw
123-
assert.throws(function() { require('./utils'); },
124-
/^Error: Cannot find module '.\/utils'$/);
124+
const notFoundPath = './utils';
125+
const notFoundError = new errors.Error('MODULE_NOT_FOUND', notFoundPath);
126+
assert.throws(function() { require(notFoundPath); },
127+
new RegExp(notFoundError.message));
125128

126129
let errorThrown = false;
127130
try {
@@ -224,6 +227,7 @@ const children = module.children.reduce(function red(set, child) {
224227

225228
assert.deepStrictEqual(children, {
226229
'common.js': {},
230+
'../lib/internal/errors.js': {},
227231
'fixtures/not-main-module.js': {},
228232
'fixtures/a.js': {
229233
'fixtures/b/c.js': {

0 commit comments

Comments
 (0)