test: refactor test-module-loading assertions

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: https://github.com/nodejs/node/pull/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>
pull/21833/merge
Bruno Pinho 2018-07-16 10:53:02 -03:00 committed by Rich Trott
parent 6dbaea779f
commit 373aae1f86
1 changed files with 17 additions and 23 deletions

View File

@ -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');
@ -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');
@ -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 {
@ -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) {
@ -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) {
@ -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');
}
{