Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1f8eaec

Browse filesBrowse files
joyeecheungtargos
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 5e731da commit 1f8eaec
Copy full SHA for 1f8eaec

File tree

Expand file treeCollapse file tree

1 file changed

+14
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-0
lines changed
Open diff view settings
Collapse file

‎test/common/index.js‎

Copy file name to clipboardExpand all lines: test/common/index.js
+14Lines changed: 14 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.