From f43fc6b6cc07281e48684f2a614ba3a90b976d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Fri, 15 Jan 2021 12:31:46 -0500 Subject: [PATCH] test: improve coverage for `Module` getters PR-URL: https://github.com/nodejs/node/pull/36950 Reviewed-By: Rich Trott Reviewed-By: Antoine du Hamel --- test/parallel/test-vm-module-errors.js | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-vm-module-errors.js b/test/parallel/test-vm-module-errors.js index 942e2f370dfff8..25b43c3e4df9d0 100644 --- a/test/parallel/test-vm-module-errors.js +++ b/test/parallel/test-vm-module-errors.js @@ -6,7 +6,7 @@ const common = require('../common'); const assert = require('assert'); -const { SourceTextModule, createContext } = require('vm'); +const { SourceTextModule, createContext, Module } = require('vm'); async function createEmptyLinkedModule() { const m = new SourceTextModule(''); @@ -205,6 +205,17 @@ async function checkInvalidOptionForEvaluate() { "Received type string ('a-string')", code: 'ERR_INVALID_ARG_TYPE' }); + + { + ['link', 'evaluate'].forEach(async (method) => { + await assert.rejects(async () => { + await Module.prototype[method](); + }, { + code: 'ERR_VM_MODULE_NOT_MODULE', + message: /Provided module is not an instance of Module/ + }); + }); + } } function checkInvalidCachedData() { @@ -223,6 +234,19 @@ function checkInvalidCachedData() { }); } +function checkGettersErrors() { + const getters = ['identifier', 'context', 'namespace', 'status', 'error']; + getters.forEach((getter) => { + assert.throws(() => { + // eslint-disable-next-line no-unused-expressions + Module.prototype[getter]; + }, { + code: 'ERR_VM_MODULE_NOT_MODULE', + message: /Provided module is not an instance of Module/ + }); + }); +} + const finished = common.mustCall(); (async function main() { @@ -232,5 +256,6 @@ const finished = common.mustCall(); await checkExecution(); await checkInvalidOptionForEvaluate(); checkInvalidCachedData(); + checkGettersErrors(); finished(); })().then(common.mustCall());