Skip to content

Commit 986bfa2

Browse files
joyeecheungmarco-ippolito
authored andcommitted
test: add common.expectRequiredModule()
To minimize changes if/when we change the layout of the result returned by require(esm). PR-URL: #52868 Fixes: #52864 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 794e450 commit 986bfa2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/common/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const net = require('net');
3232
const path = require('path');
3333
const { inspect } = require('util');
3434
const { isMainThread } = require('worker_threads');
35+
const { isModuleNamespaceObject } = require('util/types');
3536

3637
const tmpdir = require('./tmpdir');
3738
const bits = ['arm64', 'loong64', 'mips', 'mipsel', 'ppc64', 'riscv64', 's390x', 'x64']
@@ -933,6 +934,18 @@ function getPrintedStackTrace(stderr) {
933934
return result;
934935
}
935936

937+
/**
938+
* Check the exports of require(esm).
939+
* TODO(joyeecheung): use it in all the test-require-module-* tests to minimize changes
940+
* if/when we change the layout of the result returned by require(esm).
941+
* @param {object} mod result returned by require()
942+
* @param {object} expectation shape of expected namespace.
943+
*/
944+
function expectRequiredModule(mod, expectation) {
945+
assert(isModuleNamespaceObject(mod));
946+
assert.deepStrictEqual({ ...mod }, { ...expectation });
947+
}
948+
936949
const common = {
937950
allowGlobals,
938951
buildType,
@@ -941,6 +954,7 @@ const common = {
941954
createZeroFilledFile,
942955
defaultAutoSelectFamilyAttemptTimeout,
943956
expectsError,
957+
expectRequiredModule,
944958
expectWarning,
945959
gcUntil,
946960
getArrayBufferViews,

0 commit comments

Comments
 (0)