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 <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>
  • Loading branch information
joyeecheung authored and marco-ippolito committed Jun 17, 2024
1 parent 794e450 commit 986bfa2
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 @@ -933,6 +934,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 @@ -941,6 +954,7 @@ const common = {
createZeroFilledFile,
defaultAutoSelectFamilyAttemptTimeout,
expectsError,
expectRequiredModule,
expectWarning,
gcUntil,
getArrayBufferViews,
Expand Down

0 comments on commit 986bfa2

Please sign in to comment.