Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: add common.expectRequiredModule()
To minimize changes if/when we change the layout of the
result returned by require(esm).
  • Loading branch information
joyeecheung committed May 7, 2024
commit 6ea1c51794500d6b4dfc735043538b12847f7950
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));
Comment thread
anonrig marked this conversation as resolved.
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