Skip to content

Commit

Permalink
test: use strict assertions in module loader test
Browse files Browse the repository at this point in the history
Replace calls to assert.equal() and assert.notEqual() with
assert.strictEqual() and assert.strictNotEqual() respectively.

PR-URL: #9263
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
bnoordhuis authored and Myles Borins committed Nov 22, 2016
1 parent 0c32b03 commit 88e60c2
Showing 1 changed file with 49 additions and 48 deletions.
97 changes: 49 additions & 48 deletions test/sequential/test-module-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ var fs = require('fs');
console.error('load test-module-loading.js');

// assert that this is the main module.
assert.equal(require.main.id, '.', 'main module should have id of \'.\'');
assert.equal(require.main, module, 'require.main should === module');
assert.equal(process.mainModule, module,
'process.mainModule should === 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 that it's *not* the main module in the required module.
require('../fixtures/not-main-module.js');

// require a file with a request that includes the extension
var a_js = require('../fixtures/a.js');
assert.equal(42, a_js.number);
assert.strictEqual(42, a_js.number);

// require a file without any extensions
var foo_no_ext = require('../fixtures/foo');
assert.equal('ok', foo_no_ext.foo);
assert.strictEqual('ok', foo_no_ext.foo);

var a = require('../fixtures/a');
var c = require('../fixtures/b/c');
Expand All @@ -31,54 +31,54 @@ var d3 = require(path.join(__dirname, '../fixtures/b/d'));
// Relative
var d4 = require('../fixtures/b/d');

assert.equal(false, false, 'testing the test program.');
assert.strictEqual(false, false, 'testing the test program.');

assert.ok(a.A instanceof Function);
assert.equal('A', a.A());
assert.strictEqual('A', a.A());

assert.ok(a.C instanceof Function);
assert.equal('C', a.C());
assert.strictEqual('C', a.C());

assert.ok(a.D instanceof Function);
assert.equal('D', a.D());
assert.strictEqual('D', a.D());

assert.ok(d.D instanceof Function);
assert.equal('D', d.D());
assert.strictEqual('D', d.D());

assert.ok(d2.D instanceof Function);
assert.equal('D', d2.D());
assert.strictEqual('D', d2.D());

assert.ok(d3.D instanceof Function);
assert.equal('D', d3.D());
assert.strictEqual('D', d3.D());

assert.ok(d4.D instanceof Function);
assert.equal('D', d4.D());
assert.strictEqual('D', d4.D());

assert.ok((new a.SomeClass()) instanceof c.SomeClass);

console.error('test index.js modules ids and relative loading');
const one = require('../fixtures/nested-index/one');
const two = require('../fixtures/nested-index/two');
assert.notEqual(one.hello, two.hello);
assert.notStrictEqual(one.hello, two.hello);

console.error('test index.js in a folder with a trailing slash');
const three = require('../fixtures/nested-index/three');
const threeFolder = require('../fixtures/nested-index/three/');
const threeIndex = require('../fixtures/nested-index/three/index.js');
assert.equal(threeFolder, threeIndex);
assert.notEqual(threeFolder, three);
assert.strictEqual(threeFolder, threeIndex);
assert.notStrictEqual(threeFolder, three);

console.error('test package.json require() loading');
assert.equal(require('../fixtures/packages/main').ok, 'ok',
'Failed loading package');
assert.equal(require('../fixtures/packages/main-index').ok, 'ok',
'Failed loading package with index.js in main subdir');
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');

console.error('test cycles containing a .. path');
const root = require('../fixtures/cycles/root');
const foo = require('../fixtures/cycles/folder/foo');
assert.equal(root.foo, foo);
assert.equal(root.sayHello(), root.hello);
assert.strictEqual(root.foo, foo);
assert.strictEqual(root.sayHello(), root.hello);

console.error('test node_modules folders');
// asserts are in the fixtures files themselves,
Expand All @@ -97,23 +97,24 @@ try {
require('../fixtures/throws_error');
} catch (e) {
errorThrown = true;
assert.equal('blah', e.message);
assert.strictEqual('blah', e.message);
}

assert.equal(require('path').dirname(__filename), __dirname);
assert.strictEqual(require('path').dirname(__filename), __dirname);

console.error('load custom file types with extensions');
require.extensions['.test'] = function(module, filename) {
var content = fs.readFileSync(filename).toString();
assert.equal('this is custom source\n', content);
assert.strictEqual('this is custom source\n', content);
content = content.replace('this is custom source',
'exports.test = \'passed\'');
module._compile(content, filename);
};

assert.equal(require('../fixtures/registerExt').test, 'passed');
assert.strictEqual(require('../fixtures/registerExt').test, 'passed');
// unknown extension, load as .js
assert.equal(require('../fixtures/registerExt.hello.world').test, 'passed');
assert.strictEqual(require('../fixtures/registerExt.hello.world').test,
'passed');

console.error('load custom file types that return non-strings');
require.extensions['.test'] = function(module, filename) {
Expand All @@ -122,16 +123,16 @@ require.extensions['.test'] = function(module, filename) {
};
};

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

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

// Should not attempt to load a directory
try {
require('../fixtures/empty');
} catch (err) {
assert.equal(err.message, 'Cannot find module \'../fixtures/empty\'');
assert.strictEqual(err.message, 'Cannot find module \'../fixtures/empty\'');
}

// Check load order is as expected
Expand All @@ -143,31 +144,31 @@ const msg = 'Load order incorrect.';
require.extensions['.reg'] = require.extensions['.js'];
require.extensions['.reg2'] = require.extensions['.js'];

assert.equal(require(loadOrder + 'file1').file1, 'file1', msg);
assert.equal(require(loadOrder + 'file2').file2, 'file2.js', msg);
assert.strictEqual(require(loadOrder + 'file1').file1, 'file1', msg);
assert.strictEqual(require(loadOrder + 'file2').file2, 'file2.js', msg);
try {
require(loadOrder + 'file3');
} catch (e) {
// Not a real .node module, but we know we require'd the right thing.
assert.ok(e.message.replace(/\\/g, '/').match(/file3\.node/));
}
assert.equal(require(loadOrder + 'file4').file4, 'file4.reg', msg);
assert.equal(require(loadOrder + 'file5').file5, 'file5.reg2', msg);
assert.equal(require(loadOrder + 'file6').file6, 'file6/index.js', msg);
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);
try {
require(loadOrder + 'file7');
} catch (e) {
assert.ok(e.message.replace(/\\/g, '/').match(/file7\/index\.node/));
}
assert.equal(require(loadOrder + 'file8').file8, 'file8/index.reg', msg);
assert.equal(require(loadOrder + 'file9').file9, 'file9/index.reg2', msg);
assert.strictEqual(require(loadOrder + 'file8').file8, 'file8/index.reg', msg);
assert.strictEqual(require(loadOrder + 'file9').file9, 'file9/index.reg2', msg);


// make sure that module.require() is the same as
// doing require() inside of that module.
var parent = require('../fixtures/module-require/parent/');
var child = require('../fixtures/module-require/child/');
assert.equal(child.loaded, parent.loaded);
assert.strictEqual(child.loaded, parent.loaded);


// #1357 Loading JSON files with require()
Expand Down Expand Up @@ -256,29 +257,29 @@ assert.throws(function() {

process.on('exit', function() {
assert.ok(a.A instanceof Function);
assert.equal('A done', a.A());
assert.strictEqual('A done', a.A());

assert.ok(a.C instanceof Function);
assert.equal('C done', a.C());
assert.strictEqual('C done', a.C());

assert.ok(a.D instanceof Function);
assert.equal('D done', a.D());
assert.strictEqual('D done', a.D());

assert.ok(d.D instanceof Function);
assert.equal('D done', d.D());
assert.strictEqual('D done', d.D());

assert.ok(d2.D instanceof Function);
assert.equal('D done', d2.D());
assert.strictEqual('D done', d2.D());

assert.equal(true, errorThrown);
assert.strictEqual(true, errorThrown);

console.log('exit');
});


// #1440 Loading files with a byte order marker.
assert.equal(42, require('../fixtures/utf8-bom.js'));
assert.equal(42, require('../fixtures/utf8-bom.json'));
assert.strictEqual(42, require('../fixtures/utf8-bom.js'));
assert.strictEqual(42, require('../fixtures/utf8-bom.json'));

// Error on the first line of a module should
// have the correct line number
Expand Down

0 comments on commit 88e60c2

Please sign in to comment.