test: check args on SourceTextModule cachedData

PR-URL: https://github.com/nodejs/node/pull/32956
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
This commit is contained in:
Juan José Arboleda 2020-04-20 18:34:23 -05:00 committed by Anna Henningsen
parent 042c7496b2
commit 766b3c18a9
No known key found for this signature in database
GPG Key ID: A94130F0BFC8EBE9

View File

@ -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();
})();