Permalink
Browse files

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: #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>
  • Loading branch information...
Trott authored and jasnell committed Feb 2, 2017
1 parent e116cbe commit 8b04bc9fa0b21efd51bb2b42880aa0cf727e2108
Showing with 19 additions and 25 deletions.
  1. +19 −25 test/parallel/test-module-loading-error.js
@@ -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;
}
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)))
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$/
);

0 comments on commit 8b04bc9

Please sign in to comment.