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: 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>
  • Loading branch information
joyeecheung authored and nodejs-github-bot committed May 9, 2024
1 parent 1291d3d commit 7443cbc
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 7443cbc

Please sign in to comment.