From 92c7e0620f83f0db76a5b8264d6e4b380176f869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Mon, 20 Apr 2020 18:34:23 -0500 Subject: [PATCH] test: check args on SourceTextModule cachedData PR-URL: https://github.com/nodejs/node/pull/32956 Reviewed-By: Anna Henningsen Reviewed-By: Gus Caplan --- test/parallel/test-vm-module-errors.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/parallel/test-vm-module-errors.js b/test/parallel/test-vm-module-errors.js index 5f36f9339fe41a..d14296b1e9ebde 100644 --- a/test/parallel/test-vm-module-errors.js +++ b/test/parallel/test-vm-module-errors.js @@ -209,6 +209,22 @@ async function checkInvalidOptionForEvaluate() { }); } +function checkInvalidCachedData() { + [true, false, 'foo', {}, Array, function() {}].forEach((invalidArg) => { + const message = 'The "options.cachedData" property must be an ' + + 'instance of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(invalidArg); + assert.throws( + () => new SourceTextModule('import "foo";', { cachedData: invalidArg }), + { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + message, + } + ); + }); +} + const finished = common.mustCall(); (async function main() { @@ -217,5 +233,6 @@ const finished = common.mustCall(); await checkLinking(); await checkExecution(); await checkInvalidOptionForEvaluate(); + checkInvalidCachedData(); finished(); })();