@exodus/test 1.0.0-rc.56 → 1.0.0-rc.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/jest.config.js +7 -8
- package/src/jest.environment.js +2 -2
- package/src/jest.js +2 -2
- package/src/jest.mock.js +5 -0
package/package.json
CHANGED
package/src/jest.config.js
CHANGED
|
@@ -101,29 +101,28 @@ export async function installJestEnvironment(jestGlobals) {
|
|
|
101
101
|
if (c.restoreMocks) beforeEach(() => jest.restoreAllMocks())
|
|
102
102
|
if (c.resetModules) beforeEach(() => jest.resetModules())
|
|
103
103
|
|
|
104
|
-
let
|
|
104
|
+
let dynamicImport
|
|
105
105
|
if (process.env.EXODUS_TEST_ENVIRONMENT === 'bundle') {
|
|
106
106
|
const preloaded = new Map(EXODUS_TEST_PRELOADED) // eslint-disable-line no-undef
|
|
107
|
-
|
|
107
|
+
dynamicImport = async (name) => {
|
|
108
108
|
if (preloaded.has(name)) return preloaded.get(name)()
|
|
109
109
|
assert.fail('Requiring non-bundled plugins from bundle is unsupported')
|
|
110
110
|
}
|
|
111
111
|
} else if (config.rootDir) {
|
|
112
112
|
const { resolve } = await import('node:path')
|
|
113
|
-
|
|
114
|
-
require = createRequire(resolve(config.rootDir, 'package.json'))
|
|
113
|
+
dynamicImport = (path) => import(resolve(config.rootDir, path))
|
|
115
114
|
} else {
|
|
116
|
-
|
|
115
|
+
dynamicImport = async () => assert.fail('Unreachable: importing plugins without a rootDir')
|
|
117
116
|
}
|
|
118
117
|
|
|
119
|
-
for (const file of c.setupFiles || [])
|
|
118
|
+
for (const file of c.setupFiles || []) await dynamicImport(file)
|
|
120
119
|
|
|
121
120
|
if (Object.hasOwn(specialEnvironments, c.testEnvironment)) {
|
|
122
121
|
const { setup } = specialEnvironments[c.testEnvironment]
|
|
123
|
-
await setup(
|
|
122
|
+
await setup(dynamicImport, engine, jestGlobals, c.testEnvironmentOptions)
|
|
124
123
|
}
|
|
125
124
|
|
|
126
|
-
for (const file of c.setupFilesAfterEnv || [])
|
|
125
|
+
for (const file of c.setupFilesAfterEnv || []) await dynamicImport(file)
|
|
127
126
|
|
|
128
127
|
// @jest/globals import auto-mocking is disabled until https://github.com/nodejs/node/issues/53807 is resolved
|
|
129
128
|
/*
|
package/src/jest.environment.js
CHANGED
|
@@ -3,8 +3,8 @@ export const specialEnvironments = {
|
|
|
3
3
|
|
|
4
4
|
jsdom: {
|
|
5
5
|
dependencies: ['jsdom'],
|
|
6
|
-
setup: (
|
|
7
|
-
const { JSDOM, VirtualConsole } =
|
|
6
|
+
setup: async (dynamicImport) => {
|
|
7
|
+
const { JSDOM, VirtualConsole } = await dynamicImport('jsdom')
|
|
8
8
|
const virtualConsole = new VirtualConsole()
|
|
9
9
|
const dom = new JSDOM('<!DOCTYPE html>', {
|
|
10
10
|
url: 'http://localhost/',
|
package/src/jest.js
CHANGED
|
@@ -51,7 +51,7 @@ const eachCallerLocation = []
|
|
|
51
51
|
const makeEach =
|
|
52
52
|
(impl) =>
|
|
53
53
|
(list, ...rest) =>
|
|
54
|
-
(template, fn) => {
|
|
54
|
+
(template, fn, ...restArgs) => {
|
|
55
55
|
eachCallerLocation.unshift(getCallerLocation())
|
|
56
56
|
// Hack for common testing with simple arrow functions, until we can disable esbuild minification
|
|
57
57
|
const formatArg = (x) => (x && x instanceof Function && `${x}` === '()=>{}' ? '() => {}' : x)
|
|
@@ -86,7 +86,7 @@ const makeEach =
|
|
|
86
86
|
if (length > 0) name = utilFormat(name, ...args.slice(0, length).map(formatArg))
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
impl(name, () => (Array.isArray(args) ? fn(...args) : fn(args)))
|
|
89
|
+
impl(name, () => (Array.isArray(args) ? fn(...args) : fn(args)), ...restArgs)
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
eachCallerLocation.shift()
|
package/src/jest.mock.js
CHANGED
|
@@ -264,6 +264,11 @@ function jestmock(name, mocker, { override = false } = {}) {
|
|
|
264
264
|
if (insideEsbuild) {
|
|
265
265
|
// esbuild handles unwrapping just default exports for us
|
|
266
266
|
assert(!likelyESM) // should not be reachable
|
|
267
|
+
const { default: defaultExport, __esModule, ...namedExports } = value // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
268
|
+
// Don't override defaultExport, as that's processed with esbuild
|
|
269
|
+
// Add named exports though for further static named imports from that module
|
|
270
|
+
// type:module and esbuild can be combined e.g. when testing typescript packages
|
|
271
|
+
if (__esModule) obj.namedExports = namedExports
|
|
267
272
|
} else if (likelyESM && isObject(value) && value.__esModule === true) {
|
|
268
273
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
269
274
|
const { default: defaultExport, __esModule, ...namedExports } = value
|