@exodus/test 1.0.0-rc.41 → 1.0.0-rc.43

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/bin/bundle.js CHANGED
@@ -28,8 +28,6 @@ const readSnapshots = async (files, resolvers) => {
28
28
  return snapshots
29
29
  }
30
30
 
31
- // These packages throw on import
32
- const blockedDeps = ['@pollyjs/adapter-node-http', '@pollyjs/node-server']
33
31
  const loadPipeline = [
34
32
  function (source, filepath) {
35
33
  return source
@@ -37,18 +35,6 @@ const loadPipeline = [
37
35
  .replace(/\b(__dirname|import\.meta\.dirname)\b/g, JSON.stringify(dirname(filepath)))
38
36
  .replace(/\b(__filename|import\.meta\.filename)\b/g, JSON.stringify(filepath))
39
37
  },
40
- function (source, filepath) {
41
- // Just a convenience wrapper to show pretty errors instead of generic bundle-apis/empty/module-throw.cjs
42
- for (const pkg of blockedDeps) {
43
- const str = `require(${JSON.stringify(pkg)})`
44
- assert(!str.includes("'"))
45
- const err = `module unsupported in bundled form: ${pkg}\n loaded from ${filepath}`
46
- const rep = `((() => { throw new Error(${JSON.stringify(err)}) })())`
47
- for (const sub of [str, str.replaceAll('"', "'")]) source = source.replace(sub, rep)
48
- }
49
-
50
- return source
51
- },
52
38
  ]
53
39
 
54
40
  const options = {}
@@ -256,8 +242,6 @@ export const build = async (...files) => {
256
242
  bindings: api('empty/function-throw.cjs'),
257
243
  'node-gyp-build': api('empty/function-throw.cjs'),
258
244
  ws: api('ws.cjs'),
259
- // unsupported deps
260
- ...Object.fromEntries(blockedDeps.map((n) => [n, api('empty/module-throw.cjs')])),
261
245
  },
262
246
  sourcemap: ['hermes', 'jsc', 'd8'].includes(options.platform) ? 'inline' : 'linked', // FIXME?
263
247
  sourcesContent: false,
package/bin/index.js CHANGED
@@ -185,6 +185,11 @@ const resolveRequire = (query) => require.resolve(query)
185
185
  const resolveImport = import.meta.resolve && ((query) => fileURLToPath(import.meta.resolve(query)))
186
186
 
187
187
  const args = []
188
+
189
+ if (haveModuleMocks && ['node:test', 'node:pure'].includes(options.engine)) {
190
+ args.push('--experimental-test-module-mocks')
191
+ }
192
+
188
193
  if (options.pure) {
189
194
  if (options.bundle) {
190
195
  assert(!options.coverage, `Can not use --coverage with ${options.engine} engine`)
@@ -200,7 +205,6 @@ if (options.pure) {
200
205
  } else if (options.engine === 'node:test') {
201
206
  args.push('--test', '--no-warnings=ExperimentalWarning', '--test-reporter=spec')
202
207
 
203
- if (haveModuleMocks) args.push('--experimental-test-module-mocks')
204
208
  if (haveSnapshots) args.push('--experimental-test-snapshots')
205
209
 
206
210
  if (options.writeSnapshots) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/test",
3
- "version": "1.0.0-rc.41",
3
+ "version": "1.0.0-rc.43",
4
4
  "author": "Exodus Movement, Inc.",
5
5
  "description": "A test suite runner",
6
6
  "homepage": "https://github.com/ExodusMovement/test",
@@ -110,7 +110,7 @@
110
110
  "c8": "^9.1.0",
111
111
  "constants-browserify": "^1.0.0",
112
112
  "crypto-browserify": "^3.12.0",
113
- "esbuild": "~0.21.5",
113
+ "esbuild": "~0.23.1",
114
114
  "events": "^3.3.0",
115
115
  "expect": "^29.7.0",
116
116
  "fast-glob": "^3.2.11",
@@ -124,7 +124,7 @@
124
124
  "stream-browserify": "^3.0.0",
125
125
  "text-encoding": "^0.7.0",
126
126
  "timers-browserify": "^2.0.12",
127
- "tsx": "^4.16.2",
127
+ "tsx": "^4.19.0",
128
128
  "url": "^0.11.0",
129
129
  "util": "^0.12.5"
130
130
  },
@@ -391,6 +391,14 @@ const mock = {
391
391
  },
392
392
  }
393
393
 
394
+ if (process.env.EXODUS_TEST_ENGINE === 'node:pure') {
395
+ // Try load module mocks from node:test, if present
396
+ try {
397
+ const nodeTest = require('node:test')
398
+ mock.module = nodeTest.mock.module.bind(nodeTest.mock)
399
+ } catch {}
400
+ }
401
+
394
402
  const beforeEach = (fn) => context.hooks.beforeEach.push(fn)
395
403
  const afterEach = (fn) => context.hooks.afterEach.push(fn)
396
404
  const before = (fn) => context.hooks.before.push(fn)
@@ -30,51 +30,4 @@ export const specialEnvironments = {
30
30
  } catch {}
31
31
  },
32
32
  },
33
-
34
- // Reproduces setup-polly-jest/jest-environment-node and hacks into 'setup-polly-jest'.pollyJest
35
- 'setup-polly-jest/jest-environment-node': {
36
- dependencies: ['@pollyjs/core', 'setup-polly-jest', 'setup-polly-jest/lib/common'],
37
- setup: async (require, engine) => {
38
- const { getTestNamePath } = await import('./dark.cjs')
39
- // polly has bad defer impl in case if it finds MessageChannel but not process.* (e.g. on deno), forever blocking
40
- const { MessageChannel } = globalThis
41
- if (MessageChannel) globalThis.MessageChannel = undefined
42
- const { Polly } = require('@pollyjs/core')
43
- const pollyJest = require('setup-polly-jest')
44
- const {
45
- JestPollyGlobals,
46
- createPollyContextAccessor,
47
- } = require('setup-polly-jest/lib/common')
48
- if (MessageChannel) globalThis.MessageChannel = MessageChannel
49
- const pollyGlobals = new JestPollyGlobals(globalThis)
50
- pollyGlobals.isJestPollyEnvironment = true
51
- pollyJest.setupPolly = (options) => {
52
- if (!pollyGlobals.isJestPollyEnvironment) return
53
-
54
- engine.before(() => {
55
- pollyGlobals.isPollyActive = true
56
- pollyGlobals.pollyContext.options = options
57
- })
58
-
59
- engine.after(() => {
60
- pollyGlobals.isPollyActive = false
61
- pollyGlobals.pollyContext.options = null
62
- })
63
-
64
- return createPollyContextAccessor(pollyGlobals)
65
- }
66
-
67
- engine.beforeEach((t) => {
68
- if (!pollyGlobals.isPollyActive) return
69
- const name = getTestNamePath(t).join('/')
70
- pollyGlobals.pollyContext.polly = new Polly(name, pollyGlobals.pollyContext.options)
71
- })
72
-
73
- engine.afterEach(async () => {
74
- if (!pollyGlobals.pollyContext.polly) return
75
- await pollyGlobals.pollyContext.polly.stop()
76
- pollyGlobals.pollyContext.polly = null
77
- })
78
- },
79
- },
80
33
  }
package/src/jest.js CHANGED
@@ -203,6 +203,10 @@ export const jest = {
203
203
  },
204
204
  websocketRecord,
205
205
  websocketReplay,
206
+ websocketNoop: () => {
207
+ globalThis.WebSocket = jest.fn()
208
+ return globalThis.WebSocket
209
+ },
206
210
  },
207
211
  },
208
212
  setTimeout: (x) => {
@@ -94,7 +94,10 @@ const snapInline = (obj, inline) => {
94
94
  assert(inline !== undefined, 'Inline Snapshots generation is not supported')
95
95
  assert(typeof inline === 'string')
96
96
  maybeSetupSerializers()
97
- getAssert().strictEqual(serialize(obj).trim(), inline.trim())
97
+ let trimmed = inline.trim()
98
+ const prefix = inline.slice(0, inline.indexOf(trimmed)).split('\n').find(Boolean)
99
+ if (prefix && /^[ \t]+$/u.test(prefix)) trimmed = trimmed.replaceAll(`\n${prefix}`, '\n')
100
+ getAssert().strictEqual(serialize(obj).trim(), trimmed)
98
101
  }
99
102
 
100
103
  const deepMerge = (obj, matcher) => {