Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make module testing stricter #11116

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
44 changes: 19 additions & 25 deletions test/parallel/test-module-loading-error.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');

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

const error_desc = {
win32: ['%1 is not a valid Win32 application'],
linux: ['file too short', 'Exec format error'],
Expand All @@ -12,27 +10,23 @@ const error_desc = {
};
const dlerror_msg = error_desc[process.platform];

if (!dlerror_msg) {
common.skip('platform not supported.');
return;
}

try {
require('../fixtures/module-loading-error.node');
} catch (e) {
assert.strictEqual(dlerror_msg.some((errMsgCase) => {
return e.toString().indexOf(errMsgCase) !== -1;
}), true);
}
assert.throws(
() => { require('../fixtures/module-loading-error.node'); },
(e) => {
if (dlerror_msg && !dlerror_msg.some((msg) => e.message.includes(msg)))
Copy link
Contributor

@cjihrig cjihrig Feb 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be open to writing this check like this:

// Skip platforms where the error is not known.
if (!dlerror_msg)
  return true;

return e.name === 'Error' && dlerror_msg.some((msg) => e.message.includes(msg));

EDIT: Nevermind. We don't need to skip the e.name check on any platforms.

return false;
if (e.name !== 'Error')
return false;
return true;
}
);

try {
require();
} catch (e) {
assert.ok(e.toString().includes('missing path'));
}
assert.throws(
require,
/^AssertionError: missing path$/
);

try {
require({});
} catch (e) {
assert.ok(e.toString().includes('path must be a string'));
}
assert.throws(
() => { require({}); },
/^AssertionError: path must be a string$/
);