Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: match expected errors in tests from internal/errors
  • Loading branch information
rauno56 committed Mar 21, 2017
commit f7556d53bf39bd7135705638d1189de5a70971cb
4 changes: 3 additions & 1 deletion test/parallel/test-cli-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions test/parallel/test-internal-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down
7 changes: 5 additions & 2 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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}",
Expand Down
8 changes: 6 additions & 2 deletions test/sequential/test-module-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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': {
Expand Down