Skip to content

Commit

Permalink
test: refactor test-module-loading assertions
Browse files Browse the repository at this point in the history
When there are three arguments in strictEqual() call and
AssertionError exists, the previous two values are not printed.
This improves debugging messages visibility
when there is a fail.
The messages were removed where the instruction
is self-explanatory.

PR-URL: #21833
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
bpinhosilva authored and Trott committed Jul 18, 2018
1 parent 6dbaea7 commit 373aae1
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions test/sequential/test-module-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ const backslash = /\\/g;

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

// assert that this is the main module.
assert.strictEqual(require.main.id, '.', 'main module should have id of \'.\'');
assert.strictEqual(require.main, module, 'require.main should === module');
assert.strictEqual(process.mainModule, module,
'process.mainModule should === module');
assert.strictEqual(require.main.id, '.');
assert.strictEqual(require.main, module);
assert.strictEqual(process.mainModule, module);

// assert that it's *not* the main module in the required module.
require('../fixtures/not-main-module.js');

Expand Down Expand Up @@ -102,12 +101,9 @@ const d2 = require('../fixtures/b/d');
assert.notStrictEqual(threeFolder, three);
}

assert.strictEqual(require('../fixtures/packages/index').ok, 'ok',
'Failed loading package');
assert.strictEqual(require('../fixtures/packages/main').ok, 'ok',
'Failed loading package');
assert.strictEqual(require('../fixtures/packages/main-index').ok, 'ok',
'Failed loading package with index.js in main subdir');
assert.strictEqual(require('../fixtures/packages/index').ok, 'ok');
assert.strictEqual(require('../fixtures/packages/main').ok, 'ok');
assert.strictEqual(require('../fixtures/packages/main-index').ok, 'ok');

{
console.error('test cycles containing a .. path');
Expand Down Expand Up @@ -165,8 +161,7 @@ require.extensions['.test'] = function(module) {

assert.strictEqual(require('../fixtures/registerExt2').custom, 'passed');

assert.strictEqual(require('../fixtures/foo').foo, 'ok',
'require module with no extension');
assert.strictEqual(require('../fixtures/foo').foo, 'ok');

// Should not attempt to load a directory
try {
Expand All @@ -181,13 +176,12 @@ try {
console.error('load order');

const loadOrder = '../fixtures/module-load-order/';
const msg = 'Load order incorrect.';

require.extensions['.reg'] = require.extensions['.js'];
require.extensions['.reg2'] = require.extensions['.js'];

assert.strictEqual(require(`${loadOrder}file1`).file1, 'file1', msg);
assert.strictEqual(require(`${loadOrder}file2`).file2, 'file2.js', msg);
assert.strictEqual(require(`${loadOrder}file1`).file1, 'file1');
assert.strictEqual(require(`${loadOrder}file2`).file2, 'file2.js');
try {
require(`${loadOrder}file3`);
} catch (e) {
Expand All @@ -197,9 +191,10 @@ try {
else
assert.ok(/file3\.node/.test(e.message.replace(backslash, '/')));
}
assert.strictEqual(require(`${loadOrder}file4`).file4, 'file4.reg', msg);
assert.strictEqual(require(`${loadOrder}file5`).file5, 'file5.reg2', msg);
assert.strictEqual(require(`${loadOrder}file6`).file6, 'file6/index.js', msg);

assert.strictEqual(require(`${loadOrder}file4`).file4, 'file4.reg');
assert.strictEqual(require(`${loadOrder}file5`).file5, 'file5.reg2');
assert.strictEqual(require(`${loadOrder}file6`).file6, 'file6/index.js');
try {
require(`${loadOrder}file7`);
} catch (e) {
Expand All @@ -208,10 +203,9 @@ try {
else
assert.ok(/file7\/index\.node/.test(e.message.replace(backslash, '/')));
}
assert.strictEqual(require(`${loadOrder}file8`).file8, 'file8/index.reg',
msg);
assert.strictEqual(require(`${loadOrder}file9`).file9, 'file9/index.reg2',
msg);

assert.strictEqual(require(`${loadOrder}file8`).file8, 'file8/index.reg');
assert.strictEqual(require(`${loadOrder}file9`).file9, 'file9/index.reg2');
}

{
Expand Down

0 comments on commit 373aae1

Please sign in to comment.