diff --git a/test/parallel/test-module-loading-error.js b/test/parallel/test-module-loading-error.js index d78f61de60fa14..1bff2c4a7c7f5c 100644 --- a/test/parallel/test-module-loading-error.js +++ b/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$/ +);