Skip to content

Commit

Permalink
test: add common.expectRequiredModule()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
  • Loading branch information
joyeecheung authored and targos committed May 11, 2024
1 parent 5e731da commit 1f8eaec
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const net = require('net');
const path = require('path');
const { inspect } = require('util');
const { isMainThread } = require('worker_threads');
const { isModuleNamespaceObject } = require('util/types');

const tmpdir = require('./tmpdir');
const bits = ['arm64', 'loong64', 'mips', 'mipsel', 'ppc64', 'riscv64', 's390x', 'x64']
Expand Down Expand Up @@ -938,6 +939,18 @@ function getPrintedStackTrace(stderr) {
return result;
}

/**
* Check the exports of require(esm).
* TODO(joyeecheung): use it in all the test-require-module-* tests to minimize changes
* if/when we change the layout of the result returned by require(esm).
* @param {object} mod result returned by require()
* @param {object} expectation shape of expected namespace.
*/
function expectRequiredModule(mod, expectation) {
assert(isModuleNamespaceObject(mod));
assert.deepStrictEqual({ ...mod }, { ...expectation });
}

const common = {
allowGlobals,
buildType,
Expand All @@ -946,6 +959,7 @@ const common = {
createZeroFilledFile,
defaultAutoSelectFamilyAttemptTimeout,
expectsError,
expectRequiredModule,
expectWarning,
gcUntil,
getArrayBufferViews,
Expand Down

0 comments on commit 1f8eaec

Please sign in to comment.