Skip to content

Commit 36ffc3f

Browse files
joyeecheungeliphazbouye
authored andcommitted
test: add common.expectRequiredModule()
To minimize changes if/when we change the layout of the result returned by require(esm). PR-URL: nodejs#52868 Fixes: nodejs#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 e698d7d commit 36ffc3f

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']
@@ -938,6 +939,18 @@ function getPrintedStackTrace(stderr) {
938939
return result;
939940
}
940941

942+
/**
943+
* Check the exports of require(esm).
944+
* TODO(joyeecheung): use it in all the test-require-module-* tests to minimize changes
945+
* if/when we change the layout of the result returned by require(esm).
946+
* @param {object} mod result returned by require()
947+
* @param {object} expectation shape of expected namespace.
948+
*/
949+
function expectRequiredModule(mod, expectation) {
950+
assert(isModuleNamespaceObject(mod));
951+
assert.deepStrictEqual({ ...mod }, { ...expectation });
952+
}
953+
941954
const common = {
942955
allowGlobals,
943956
buildType,
@@ -946,6 +959,7 @@ const common = {
946959
createZeroFilledFile,
947960
defaultAutoSelectFamilyAttemptTimeout,
948961
expectsError,
962+
expectRequiredModule,
949963
expectWarning,
950964
gcUntil,
951965
getArrayBufferViews,

0 commit comments

Comments
 (0)