@provino/dialect-jest 0.0.0-stage → 0.1.0-rc.1

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/dist/index.js ADDED
@@ -0,0 +1,528 @@
1
+ import { defineDialect, defineHoistPolicy, moduleRef } from "@provino/policy";
2
+
3
+ // src/expect-policy.ts
4
+ /**
5
+ * Jest 30.5's `expect` policy.
6
+ * @public
7
+ */
8
+ const jestExpectPolicy = {
9
+ matcherNamespace: "jest",
10
+ pollFailsOnTimeout: true,
11
+ diffContextLines: 5,
12
+ valueFormatter: "pretty-format",
13
+ matcherTable: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "jestExpectTable"),
14
+ outsideTestCounts: "next-test",
15
+ errorShape: "matcher-result",
16
+ equality: {
17
+ errors: "message",
18
+ invalidDate: "unequal"
19
+ },
20
+ soft: false,
21
+ poll: {
22
+ enabled: false,
23
+ intervalMs: 50,
24
+ timeoutMs: 1e3
25
+ },
26
+ requireAssertions: false,
27
+ expand: false
28
+ };
29
+
30
+ // src/hoist-policy.ts
31
+ /**
32
+ * The names a factory may read: the plugin's `ALLOWED_IDENTIFIERS` (index.ts L36-L96), its fixed list
33
+ * plus every own name of `globalThis`, worked out when the module loads and sorted, as the plugin
34
+ * does. So the list follows the Node running the transform, as real Jest's does.
35
+ */
36
+ const ALLOWED_IDENTIFIERS = [.../* @__PURE__ */ new Set([
37
+ "Array",
38
+ "ArrayBuffer",
39
+ "Boolean",
40
+ "BigInt",
41
+ "DataView",
42
+ "Date",
43
+ "Error",
44
+ "EvalError",
45
+ "Float32Array",
46
+ "Float64Array",
47
+ "Function",
48
+ "Generator",
49
+ "GeneratorFunction",
50
+ "Infinity",
51
+ "Int16Array",
52
+ "Int32Array",
53
+ "Int8Array",
54
+ "InternalError",
55
+ "Intl",
56
+ "JSON",
57
+ "Map",
58
+ "Math",
59
+ "NaN",
60
+ "Number",
61
+ "Object",
62
+ "Promise",
63
+ "Proxy",
64
+ "RangeError",
65
+ "ReferenceError",
66
+ "Reflect",
67
+ "RegExp",
68
+ "Set",
69
+ "String",
70
+ "Symbol",
71
+ "SyntaxError",
72
+ "TypeError",
73
+ "URIError",
74
+ "Uint16Array",
75
+ "Uint32Array",
76
+ "Uint8Array",
77
+ "Uint8ClampedArray",
78
+ "WeakMap",
79
+ "WeakSet",
80
+ "arguments",
81
+ "console",
82
+ "expect",
83
+ "isNaN",
84
+ "jest",
85
+ "parseFloat",
86
+ "parseInt",
87
+ "exports",
88
+ "require",
89
+ "module",
90
+ "__filename",
91
+ "__dirname",
92
+ "undefined",
93
+ ...Object.getOwnPropertyNames(globalThis)
94
+ ])].toSorted();
95
+ /**
96
+ * Jest 30.5's mock-hoisting policy.
97
+ * @public
98
+ */
99
+ const jestHoistPolicy = defineHoistPolicy({
100
+ id: "jest-30.5",
101
+ objects: [
102
+ {
103
+ kind: "global",
104
+ name: "jest"
105
+ },
106
+ {
107
+ kind: "import",
108
+ module: "@jest/globals",
109
+ exportName: "jest"
110
+ },
111
+ {
112
+ kind: "namespace-member",
113
+ module: "@jest/globals",
114
+ exportName: "jest"
115
+ }
116
+ ],
117
+ hoistCalls: {
118
+ mock: "path-factory-options",
119
+ unmock: "one-string",
120
+ deepUnmock: "one-string",
121
+ enableAutomock: "no-args",
122
+ disableAutomock: "no-args"
123
+ },
124
+ hoistValues: [],
125
+ rewriteImportArg: [],
126
+ chainable: true,
127
+ placement: "enclosing-block",
128
+ topLevelGuards: [],
129
+ factoryReferences: {
130
+ allowGlobals: new Set(ALLOWED_IDENTIFIERS),
131
+ allowPattern: /^(?:[mM][oO][cC][kK]|(?:__)?cov)/,
132
+ hoistPureConsts: true
133
+ },
134
+ runnerModules: ["@jest/globals"],
135
+ reExports: "in-order",
136
+ rewrittenCalls: "detached",
137
+ messages: {
138
+ HOIST_FACTORY_OUT_OF_SCOPE: `The module factory of \`jest.mock()\` is not allowed to reference any out-of-scope variables.
139
+ Invalid variable access: {name}
140
+ Allowed objects: ${ALLOWED_IDENTIFIERS.join(", ")}.\nNote: This is a precaution to guard against uninitialized mock variables. If it is ensured that the mock is required lazily, variable names prefixed with \`mock\` (case insensitive) are permitted.
141
+ `,
142
+ HOIST_FACTORY_NOT_FUNCTION: "The second argument of `jest.mock` must be an inline function.\n",
143
+ HOIST_NOT_TOP_LEVEL: "Jest hoists within the enclosing block; {call} has no top-level rule.",
144
+ HOIST_NESTED: "Jest allows {call} inside another hoisted call.",
145
+ HOIST_EXPORTED: "Jest does not restrict exporting the result of {call}.",
146
+ HOIST_EXPORTED_VALUE: "Jest has no hoisted values; {call} is not one."
147
+ }
148
+ });
149
+
150
+ // src/mock-policy.ts
151
+ /**
152
+ * Jest 30.5's mock policy.
153
+ * @public
154
+ */
155
+ const jestMockPolicy = {
156
+ resetTo: "empty",
157
+ defaultName: "jest.fn()",
158
+ between: {
159
+ order: [
160
+ "clear",
161
+ "reset",
162
+ "restore"
163
+ ],
164
+ clear: false,
165
+ reset: false,
166
+ restore: false,
167
+ unstubEnvs: false,
168
+ unstubGlobals: false
169
+ },
170
+ classMockPrototype: "own",
171
+ spyNameFromMethod: false,
172
+ functionName: "mockConstructor",
173
+ newCall: "apply",
174
+ valueShorthandsThrowOnNew: false,
175
+ fnOfMockReturnsSame: false,
176
+ copyStaticProps: false,
177
+ settledResults: false,
178
+ lastCallKey: "after-first-call",
179
+ clearReplacesStateObject: true,
180
+ mockPropertyWritable: true,
181
+ withImplementationReturnsMock: false,
182
+ getImplPrefersOnce: false,
183
+ spyReportsBridgeImpl: true,
184
+ isMockAcceptsObjects: true,
185
+ spyInstall: "assign",
186
+ messages: {
187
+ "spy-primitive": "Cannot use spyOn on a primitive value; {type} given",
188
+ "spy-no-key": "No property name supplied",
189
+ "spy-missing": "Property `{key}` does not exist in the provided object",
190
+ "spy-not-a-function": "Cannot spy on the `{key}` property because it is not a function; {type} given instead.",
191
+ "spy-not-a-function-primitive": "Cannot spy on the `{key}` property because it is not a function; {type} given instead. If you are trying to mock a property, use `jest.replaceProperty(object, '{key}', value)` instead.",
192
+ "spy-not-configurable": "Property `{key}` is not declared configurable",
193
+ "spy-no-access-type": "Property `{key}` does not have access type {type}",
194
+ "spy-read-only": "Cannot assign to read only property '{key}' of object '{tag}'",
195
+ "replace-primitive": "Cannot use replaceProperty on a primitive value; {type} given",
196
+ "replace-no-key": "No property name supplied",
197
+ "replace-missing": "Property `{key}` does not exist in the provided object",
198
+ "replace-not-configurable": "Property `{key}` is not declared configurable",
199
+ "replace-getter": "Cannot replace the `{key}` property because it has a getter. Use `jest.spyOn(object, '{key}', 'get').mockReturnValue(value)` instead.",
200
+ "replace-setter": "Cannot replace the `{key}` property because it has a setter. Use `jest.spyOn(object, '{key}', 'set').mockReturnValue(value)` instead.",
201
+ "replace-function": "Cannot replace the `{key}` property because it is a function. Use `jest.spyOn(object, '{key}')` instead."
202
+ }
203
+ };
204
+
205
+ // src/dialect.ts
206
+ /**
207
+ * Jest 30.5's policy: every key the research gives a Jest value for, layered over the neutral
208
+ * policy by `resolvePolicy`. This is `jestDialect.policy`, typed as the overrides it is (a
209
+ * `Dialect`'s own `policy` is the overrides or a factory).
210
+ * @public
211
+ */
212
+ const jestPolicy = {
213
+ core: {
214
+ hookOrder: {
215
+ beforeAll: "declaration",
216
+ beforeEach: "declaration",
217
+ afterEach: "declaration",
218
+ afterAll: "declaration"
219
+ },
220
+ eachHooksForConcurrent: false,
221
+ firstArg: "done-if-arity",
222
+ allowGeneratorFns: true,
223
+ timeouts: {
224
+ test: 5e3,
225
+ hook: 5e3,
226
+ teardown: 5e3,
227
+ catchSyncOverrun: false,
228
+ zero: "default"
229
+ },
230
+ nameSeparator: " ",
231
+ testNamePatternFlags: "i",
232
+ missingTestFn: "throw",
233
+ asyncDescribe: "throw",
234
+ nonPromiseReturn: "fail",
235
+ formatEachTitle: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "formatEachTitle"),
236
+ formatValue: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "formatValue"),
237
+ shuffle: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "jestShuffle"),
238
+ shapeTestError: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "shapeTestError"),
239
+ boundaryTurns: {
240
+ hookStart: 7,
241
+ hookEnd: 14,
242
+ fnStart: 7,
243
+ fnEnd: 13,
244
+ testStart: 35,
245
+ testEnd: 11,
246
+ skippedTest: 18,
247
+ suiteStart: 7,
248
+ suiteEnd: 9,
249
+ runStart: 14,
250
+ retry: 7,
251
+ retryEnd: 9,
252
+ retryExit: 1
253
+ },
254
+ doneDeprecatedMessage: null,
255
+ eachTitleTruncate: null,
256
+ retry: {
257
+ timing: "deferred",
258
+ keepEarlierErrors: false,
259
+ functionCondition: "call"
260
+ },
261
+ allowOnly: "always",
262
+ maxConcurrency: 5,
263
+ unawaitedAsyncAssertion: "ignore",
264
+ hookReturnsCleanup: false,
265
+ injectGlobals: true,
266
+ globalsBeforeSetupFiles: ["jest"],
267
+ collect: {
268
+ describeBody: "immediate",
269
+ describeReturnValue: "error",
270
+ lateRegistration: "fail-file",
271
+ emptyDescribe: "fail-file-if-hooks",
272
+ nestedInTest: "fail-test",
273
+ todoWithFn: "throw",
274
+ eachTableError: "failing-test"
275
+ },
276
+ hooks: {
277
+ afterError: "continue",
278
+ beforeAllError: "attach-to-tests",
279
+ nestedHooksAfterBeforeAllError: "run",
280
+ afterAllError: "unhandled",
281
+ timeoutCountsTestTimeout: false,
282
+ skippedBlock: "run-before-all"
283
+ },
284
+ concurrency: {
285
+ grouping: "hoist-to-first",
286
+ limitHooks: false
287
+ },
288
+ errors: {
289
+ lateErrors: "fail-owner",
290
+ processListeners: "per-file",
291
+ waitForUnhandledRejections: false,
292
+ hasAssertionsWhenFailed: "skip"
293
+ },
294
+ focus: {
295
+ scope: "file",
296
+ insideSkip: "runs"
297
+ },
298
+ status: {
299
+ todoUnderSkip: "skipped",
300
+ expectFail: "body"
301
+ },
302
+ locationFrame: "caller"
303
+ },
304
+ lazy: { readInBeforeAll: "error" },
305
+ mock: jestMockPolicy,
306
+ timers: {
307
+ toFakeDefault: "all",
308
+ loopLimit: 1e5,
309
+ legacyAvailable: true,
310
+ enableGlobally: false,
311
+ optionNames: "do-not-fake",
312
+ advanceToNextTimerHonorsSteps: true,
313
+ notFaked: "warn",
314
+ setSystemTimeWithoutFakes: "warn-noop",
315
+ fakeTemporal: true,
316
+ facadeReturns: "lifecycle",
317
+ messages: { notFaked: "A function to advance timers was called but the timers APIs are not replaced with fake timers. Call `jest.useFakeTimers()` in this test file or enable fake timers for all tests by setting 'fakeTimers': {'enableGlobally': true} in Jest configuration file.\nStack Trace:\n{stack}" }
318
+ },
319
+ module: {
320
+ factoryShape: "module-value",
321
+ rootMocksAutoApply: true,
322
+ automock: false,
323
+ actual: "sync-require",
324
+ resetModulesBetween: false,
325
+ injectCjsGlobals: true,
326
+ interopDefault: "babel",
327
+ resetModulesClearsMocks: false,
328
+ awaitFactory: false,
329
+ requireVirtualFlag: true,
330
+ virtualRelative: true,
331
+ mockValueOwner: "module-registry",
332
+ mockResolveKind: "require",
333
+ edgeResolveKind: "importer-format",
334
+ moduleSyncCondition: "import-and-sync-require",
335
+ mocksReachShared: true,
336
+ reevaluateHookingExternals: true,
337
+ reevaluatePatchingExternals: true,
338
+ stackFrameNames: "mapped-name",
339
+ nativeLoadPatches: "skip",
340
+ automockShape: "metadata",
341
+ unmockedPathPatterns: [],
342
+ missingFactoryExport: "undefined",
343
+ messages: {
344
+ "module-missing": "Cannot find module '{specifier}' from '{from}'\n\nTo mock a module that does not exist on disk, pass `{virtual: true}` in the mock options. See https://jestjs.io/docs/jest-object#jestmockmodulename-factory-options",
345
+ "unmock-module-missing": "Cannot find module '{specifier}' from '{from}'",
346
+ "automock-no-metadata": "Failed to get mock metadata: {id}\n\nSee: https://jestjs.io/docs/manual-mocks#content",
347
+ "nested-isolation": "{caller} cannot be nested inside another {caller} or {other}.",
348
+ "transform-failed": "{file}: {message}",
349
+ "module-not-found": "Cannot find module '{specifier}' from '{from}'",
350
+ "require-esm": "Must use import to load ES Module: {path}\n\nThe file contains ESM syntax (import/export) that could not be executed as CommonJS. Either:\n - Configure a transform (e.g. babel-jest) that compiles this file to CommonJS (see https://jestjs.io/docs/code-transformation)\n - If the file is in \"node_modules\", allow it to be transformed by adjusting \"transformIgnorePatterns\" (see https://jestjs.io/docs/configuration#transformignorepatterns-arraystring)\n - Use Node v24.9+ where Jest supports require(esm) natively (see https://jestjs.io/docs/ecmascript-modules#require-of-esm)"
351
+ },
352
+ mapperMiss: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "formatMapperMiss")
353
+ },
354
+ snapshot: {
355
+ header: "// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing",
356
+ keyJoin: " ",
357
+ hintJoin: ": ",
358
+ dirName: "__snapshots__",
359
+ extension: ".snap",
360
+ format: {
361
+ escapeString: false,
362
+ printBasicPrototype: false,
363
+ maxOutputLength: null,
364
+ extra: {}
365
+ },
366
+ obsolete: {
367
+ failLocal: true,
368
+ failCI: true
369
+ },
370
+ obsoleteFiles: "report",
371
+ ciUpdate: "none",
372
+ updateEnvVar: null,
373
+ throwErrorBody: "message",
374
+ inline: {
375
+ indent: "column0",
376
+ formatter: "prettier",
377
+ writer: moduleRef(import.meta.resolve("@provino/dialect-jest/inline-snapshots"), "jestInlineSnapshotWriter"),
378
+ prettierPath: null
379
+ },
380
+ resolverFactory: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "jestSnapshotResolver"),
381
+ contextView: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "jestSnapshotStateView"),
382
+ printer: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "jestSnapshotPrinter")
383
+ },
384
+ expect: jestExpectPolicy,
385
+ orchestrator: {
386
+ include: ["**/__tests__/**/*.?([mc])[jt]s?(x)", "**/?(*.)+(spec|test).?([mc])[jt]s?(x)"],
387
+ exclude: ["**/node_modules/**"],
388
+ bail: { checkAfter: "file" },
389
+ watchDefault: "never",
390
+ watch: {
391
+ initialRun: "changed",
392
+ interruptedFiles: "drop"
393
+ },
394
+ changedFiles: moduleRef(import.meta.resolve("@provino/dialect-jest/affected"), "jestChangedFiles"),
395
+ affected: {
396
+ extractor: moduleRef(import.meta.resolve("@provino/dialect-jest/affected"), "jestDependencyExtractor"),
397
+ mockEdges: {
398
+ dir: "__mocks__",
399
+ adjacent: true,
400
+ byName: true
401
+ },
402
+ invalidateAll: "none",
403
+ graph: "static",
404
+ conditions: "none"
405
+ },
406
+ environmentConditions: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "jestEnvironmentConditions"),
407
+ globMatchesOn: "absolute-path",
408
+ todoOnlyFile: "pass",
409
+ noTestsFile: "fail",
410
+ consoleOrigin: "stack",
411
+ processObject: "per-file",
412
+ passWithNoTests: false,
413
+ exitCodes: {
414
+ failure: 1,
415
+ noTests: 1,
416
+ unhandled: 1,
417
+ usage: 1
418
+ },
419
+ unhandledErrors: "fail-run",
420
+ coverageProvider: "istanbul",
421
+ coverageReporters: [
422
+ "json",
423
+ "text",
424
+ "lcov",
425
+ "clover"
426
+ ],
427
+ slowTestThresholdMs: 5e3,
428
+ isolationDefault: { default: "registry" },
429
+ envDefault: "node",
430
+ environmentPragmas: ["jest-environment"],
431
+ pool: { default: "forks" },
432
+ inBand: {
433
+ single: true,
434
+ fastFileCount: 20,
435
+ slowMs: 1e3
436
+ },
437
+ shard: { fallback: "sha1-slice" },
438
+ sequence: { unknownFirst: true },
439
+ globalSetup: {
440
+ signature: "global-and-project-config",
441
+ teardownOrder: "in-order",
442
+ failure: moduleRef(import.meta.resolve("@provino/dialect-jest/global-setup"), "globalSetupFailure")
443
+ }
444
+ },
445
+ report: {
446
+ displaySeparator: " › ",
447
+ defaultReporters: ["default"],
448
+ listTestsForSingleFile: true,
449
+ failureTitleBullet: " ● ",
450
+ resultStatusSkipped: "pending"
451
+ },
452
+ coverage: {
453
+ thresholdGrouping: "every-match",
454
+ globThresholdScope: "per-file",
455
+ includeUntestedByDefault: true,
456
+ reportsDirectory: "coverage",
457
+ v8Conversion: "v8-to-istanbul",
458
+ v8HitCounts: true,
459
+ v8Hashbang: "removed",
460
+ istanbulVariable: "__coverage__",
461
+ thresholdMessages: {
462
+ belowMinimum: "Jest: Coverage for {metric} ({actual}%) does not meet \"{name}\" threshold ({threshold}%)",
463
+ aboveMaximumUncovered: "Jest: Uncovered count for {metric} ({actual}) exceeds {name} threshold ({threshold})",
464
+ notFound: "Jest: Coverage data for {path} was not found."
465
+ }
466
+ }
467
+ };
468
+ /**
469
+ * The served specifiers a `moduleNameMapper` rule takes over. `@jest/globals` is answered before
470
+ * the mapper (jest-runtime `requireModuleOrMock`), but `expect`, `@jest/expect` and `jest-mock` go
471
+ * through it as any bare specifier does. Recorded: `resolve/alias-order`, `resolve/alias-jest-mock`.
472
+ * Jest's own runner takes a mapped `expect` too, which crashes every file (`resolve/alias-expect`,
473
+ * `resolve/alias-jest-expect`); Provino's runner keeps its own and only the project's requires see
474
+ * the mapped module (a proposed DIVERGENCE).
475
+ */
476
+ const JEST_MAPPABLE_MODULES = [
477
+ "@jest/expect",
478
+ "expect",
479
+ "jest-mock"
480
+ ];
481
+ /** The specifiers the Jest dialect serves from its facades (U9). */
482
+ const JEST_SERVED_MODULES = ["@jest/globals", ...JEST_MAPPABLE_MODULES];
483
+ /**
484
+ * The globals Jest 30.5 injects into a test file: jest-circus's (`describe`, `it`, `test`, the
485
+ * hooks, their `f`/`x` aliases), `expect`, and the `jest` object. `jestGlobals` returns exactly
486
+ * these keys.
487
+ * research: jest-circus 30.5.2 `jestAdapterInit` (`globalsObject`), read from source, not recorded
488
+ */
489
+ const JEST_GLOBAL_NAMES = [
490
+ "afterAll",
491
+ "afterEach",
492
+ "beforeAll",
493
+ "beforeEach",
494
+ "describe",
495
+ "expect",
496
+ "fdescribe",
497
+ "fit",
498
+ "it",
499
+ "jest",
500
+ "test",
501
+ "xdescribe",
502
+ "xit",
503
+ "xtest"
504
+ ];
505
+ /**
506
+ * The Jest 30.5 dialect: its policy values and the globals it injects. The config reader, the CLI
507
+ * flags and the `@jest/globals` facade come with T11.x and T11.10 (B14, B17).
508
+ * @public
509
+ */
510
+ const jestDialect = defineDialect({
511
+ name: "jest",
512
+ version: "30.5",
513
+ policy: jestPolicy,
514
+ globals: {
515
+ factory: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "jestGlobals"),
516
+ names: JEST_GLOBAL_NAMES
517
+ },
518
+ loader: { hoist: jestHoistPolicy },
519
+ environmentResolver: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "jestEnvironmentFor"),
520
+ moduleScope: {
521
+ names: ["jest"],
522
+ modules: JEST_SERVED_MODULES,
523
+ mappable: JEST_MAPPABLE_MODULES,
524
+ factory: moduleRef(import.meta.resolve("@provino/dialect-jest/runtime"), "jestModuleScope")
525
+ }
526
+ });
527
+
528
+ export { jestDialect, jestExpectPolicy, jestHoistPolicy, jestMockPolicy, jestPolicy };
@@ -0,0 +1,6 @@
1
+ import { InlineSnapshotWriterFactory } from "@provino/types";
2
+ /**
3
+ * The Jest dialect's inline snapshot writer (`snapshot.inline.writer`).
4
+ * @public
5
+ */
6
+ export declare const jestInlineSnapshotWriter: InlineSnapshotWriterFactory;