test: make module testing stricter
In test-module-loading-error: * Do not skip the rest of the test just because we are running on a platform for which the test does not know the expected system error message. Simply skip the message validation but run the remainder of the test. * Use assert.throws() in place of try/catch * Make checks more strict. Instead of partial string matches, match the entire string. Add check for Error name to at least do some validation in situations where we do not have the system error message. PR-URL: https://github.com/nodejs/node/pull/11116 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
e116cbe320
commit
8b04bc9fa0
@ -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'],
|
||||
@ -12,27 +10,23 @@ const error_desc = {
|
||||
};
|
||||
const dlerror_msg = error_desc[process.platform];
|
||||
|
||||
if (!dlerror_msg) {
|
||||
common.skip('platform not supported.');
|
||||
return;
|
||||
}
|
||||
assert.throws(
|
||||
() => { require('../fixtures/module-loading-error.node'); },
|
||||
(e) => {
|
||||
if (dlerror_msg && !dlerror_msg.some((msg) => e.message.includes(msg)))
|
||||
return false;
|
||||
if (e.name !== 'Error')
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
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,
|
||||
/^AssertionError: missing path$/
|
||||
);
|
||||
|
||||
try {
|
||||
require();
|
||||
} catch (e) {
|
||||
assert.ok(e.toString().includes('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$/
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user