GeezerVison is showing github.com — test: add common.expectRequiredModule() · nodejs/node@1f8eaec
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: test/common/index.js +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,6 +32,7 @@ const net = require('net'); |
32 | 32 | const path = require('path'); |
33 | 33 | const { inspect } = require('util'); |
34 | 34 | const { isMainThread } = require('worker_threads'); |
| 35 | +const { isModuleNamespaceObject } = require('util/types'); |
35 | 36 |
|
36 | 37 | const tmpdir = require('./tmpdir'); |
37 | 38 | const bits = ['arm64', 'loong64', 'mips', 'mipsel', 'ppc64', 'riscv64', 's390x', 'x64'] |
@@ -938,6 +939,18 @@ function getPrintedStackTrace(stderr) { |
938 | 939 | return result; |
939 | 940 | } |
940 | 941 |
|
| 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 | + |
941 | 954 | const common = { |
942 | 955 | allowGlobals, |
943 | 956 | buildType, |
@@ -946,6 +959,7 @@ const common = { |
946 | 959 | createZeroFilledFile, |
947 | 960 | defaultAutoSelectFamilyAttemptTimeout, |
948 | 961 | expectsError, |
| 962 | + expectRequiredModule, |
949 | 963 | expectWarning, |
950 | 964 | gcUntil, |
951 | 965 | getArrayBufferViews, |
|