@provino/dialect-jest 0.0.0-stage → 0.1.0-rc.0
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/LICENSE +21 -0
- package/README.md +8 -2
- package/THIRD_PARTY_NOTICES.md +266 -0
- package/dist/affected/index.d.ts +13 -0
- package/dist/affected/index.js +424 -0
- package/dist/failure-message.d.ts +245 -0
- package/dist/failure-message.js +125 -0
- package/dist/global-setup/index.d.ts +11 -0
- package/dist/global-setup/index.js +40 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +528 -0
- package/dist/inline-snapshots/index.d.ts +6 -0
- package/dist/inline-snapshots/index.js +263 -0
- package/dist/jest-require.js +42 -0
- package/dist/node/index.d.ts +1716 -0
- package/dist/node/index.js +7307 -0
- package/dist/results/index.d.ts +248 -0
- package/dist/results/index.js +844 -0
- package/dist/runtime/index.d.ts +450 -0
- package/dist/runtime/index.js +3455 -0
- package/package.json +97 -3
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { createExpect } from "@provino/expect";
|
|
2
|
+
import { Mock, MockRegistry, MockTarget, Replaced, SpiedGetter, SpiedMethod, SpiedSetter, SpyableKeys, UnknownFunction } from "@provino/mock";
|
|
3
|
+
import { FakeClock, FakeTimersConfig } from "@provino/timers";
|
|
4
|
+
import { RuntimeApi, SuiteApi, TestApi } from "@provino/core";
|
|
5
|
+
import { EachTableKind, Environment, EnvironmentConditions, EnvironmentResolver, ExpectTable, FormatMapperMiss, FormatValue, GlobalsHost, JsonValue, Pragmas, ShapeTestError, SnapshotPrinter, SnapshotResolverFactory, SnapshotViewMatchResult, SnapshotViewSource, TimersPolicy } from "@provino/types";
|
|
6
|
+
/**
|
|
7
|
+
* Formats a `.each` title as jest-each 30.5.2 does: `%p` through pretty-format, `%j` as JSON
|
|
8
|
+
* (a bigint as `"5n"`, a cycle as `[Circular]`), the other tokens through `util.format`, `%#` and
|
|
9
|
+
* `%$` for the row's index and number, and `$name` for an object row's keys. `kind` is
|
|
10
|
+
* `'template'` for a tagged template's row: only its `$variables` are read.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatEachTitle(template: string, row: readonly unknown[] | Readonly<Record<string, unknown>>, index: number, kind?: EachTableKind): string;
|
|
14
|
+
/**
|
|
15
|
+
* Builds the Jest 30.5 matcher table. The worker loads it once, by `ModuleRef`, after the slot is
|
|
16
|
+
* installed.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export declare function jestExpectTable(): ExpectTable;
|
|
20
|
+
/**
|
|
21
|
+
* jest-resolve prints a one-element target list as that target, and a longer one as JSON, nested
|
|
22
|
+
* one level below the config object's key so its brackets line up there.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare const formatMapperMiss: FormatMapperMiss;
|
|
26
|
+
/**
|
|
27
|
+
* Prints a value as jest-circus prints it in a message: pretty-format, three levels deep.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare const formatValue: FormatValue;
|
|
31
|
+
/**
|
|
32
|
+
* What `jestGlobals` builds the globals from: `GlobalsHost` with the real types of the
|
|
33
|
+
* objects it declares as `object`. `GlobalsFactory` is bivariant in the host, so `jestGlobals`
|
|
34
|
+
* is still a `GlobalsFactory`; through that type it accepts any host, so the worker must pass
|
|
35
|
+
* the one it declares here.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
interface JestGlobalsHost extends GlobalsHost {
|
|
39
|
+
/** Core's global API: `runtime.api`. */
|
|
40
|
+
readonly api: RuntimeApi;
|
|
41
|
+
/** The worker's `expect`, from `createExpect`. */
|
|
42
|
+
readonly expect: ReturnType<typeof createExpect>;
|
|
43
|
+
/** The mock registry of the file running now (the worker's, under isolation `none`). */
|
|
44
|
+
mocks(): MockRegistry;
|
|
45
|
+
/** The fake clock of the file running now, on the environment's global. */
|
|
46
|
+
timers(): FakeClock;
|
|
47
|
+
/** The `timers` slice of the policy: what the timer members follow. */
|
|
48
|
+
readonly timersPolicy: TimersPolicy;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* What `jest.useFakeTimers` takes (Jest's `fakeTimers` config): which globals stay real, whether
|
|
52
|
+
* the clock advances with real time, the loop limit, the start time. `legacyFakeTimers: true` is
|
|
53
|
+
* refused when a test installs it (`TIMERS_LEGACY_UNSUPPORTED`).
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
type JestFakeTimersConfig = Pick<FakeTimersConfig, "now" | "doNotFake" | "advanceTimers" | "timerLimit" | "legacyFakeTimers">;
|
|
57
|
+
/**
|
|
58
|
+
* The timer members of `jest` (jest-runtime 30.5.2 `JestGlobals.ts`), over the fake clock of the file
|
|
59
|
+
* running now. `J` is the object a chained call returns: the global `jest`, or a module's.
|
|
60
|
+
* `useFakeTimers`, `useRealTimers` and `setTimerTickMode` return it (`facadeReturns: 'lifecycle'`);
|
|
61
|
+
* the rest return nothing.
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
interface JestTimerMembers<J> {
|
|
65
|
+
/** Fakes the environment's timers; a second call drops the pending timers first. */
|
|
66
|
+
useFakeTimers(config?: JestFakeTimersConfig): J;
|
|
67
|
+
/** Puts the real timers back. */
|
|
68
|
+
useRealTimers(): J;
|
|
69
|
+
/** Runs every timer until none is left (at most `timerLimit`). */
|
|
70
|
+
runAllTimers(): void;
|
|
71
|
+
runAllTimersAsync(): Promise<void>;
|
|
72
|
+
/** Runs the timers that are pending now, and none a callback adds. */
|
|
73
|
+
runOnlyPendingTimers(): void;
|
|
74
|
+
runOnlyPendingTimersAsync(): Promise<void>;
|
|
75
|
+
/** Moves the clock forward by `msToRun`, firing the timers that fall due. */
|
|
76
|
+
advanceTimersByTime(msToRun: number): void;
|
|
77
|
+
advanceTimersByTimeAsync(msToRun: number): Promise<void>;
|
|
78
|
+
/** Moves the clock to the next `steps` timers (default one). */
|
|
79
|
+
advanceTimersToNextTimer(steps?: number): void;
|
|
80
|
+
advanceTimersToNextTimerAsync(steps?: number): Promise<void>;
|
|
81
|
+
/** Moves the clock to the next 16 ms animation frame. */
|
|
82
|
+
advanceTimersToNextFrame(): void;
|
|
83
|
+
/** Runs the jobs a faked `process.nextTick` or `queueMicrotask` queued. */
|
|
84
|
+
runAllTicks(): void;
|
|
85
|
+
/** Drops every pending timer. */
|
|
86
|
+
clearAllTimers(): void;
|
|
87
|
+
/** How many timers are pending. */
|
|
88
|
+
getTimerCount(): number;
|
|
89
|
+
/** The fake time while timers are fake, else `Date.now()`. */
|
|
90
|
+
now(): number;
|
|
91
|
+
/** Sets the fake time without firing a timer. */
|
|
92
|
+
setSystemTime(now?: number | Date): void;
|
|
93
|
+
/** `Date.now()` as it was before any install. */
|
|
94
|
+
getRealSystemTime(): number;
|
|
95
|
+
/** How the fake clock moves on its own. */
|
|
96
|
+
setTimerTickMode(mode: {
|
|
97
|
+
mode: "manual" | "nextAsync";
|
|
98
|
+
} | {
|
|
99
|
+
mode: "interval";
|
|
100
|
+
delta?: number;
|
|
101
|
+
}): J;
|
|
102
|
+
/** Legacy timers only: always throws, because Provino has no legacy timers. */
|
|
103
|
+
runAllImmediates(): void;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* What `jest.retryTimes` takes. `logErrorsBeforeRetry` keeps the errors of the attempts that were
|
|
107
|
+
* retried on the result (Jest prints them above the file's result); `waitBeforeRetry` is
|
|
108
|
+
* milliseconds. `entireDescribe` retries the whole describe block being collected, not one test.
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
interface JestRetryOptions {
|
|
112
|
+
readonly logErrorsBeforeRetry?: boolean;
|
|
113
|
+
readonly retryImmediately?: boolean;
|
|
114
|
+
readonly waitBeforeRetry?: number;
|
|
115
|
+
readonly entireDescribe?: boolean;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The `jest` global, as far as the worker runtime goes: the module registry methods, which act on
|
|
119
|
+
* the registry of the file running when they are called. `isolateModules` and
|
|
120
|
+
* `isolateModulesAsync` refuse to nest or overlap (on one registry), as Jest does. The mock
|
|
121
|
+
* functions (`fn`, `spyOn`, `replaceProperty`, the three `*AllMocks`) act on the mock registry of
|
|
122
|
+
* the file running. `jest.mock` and friends (B13c) are on each module's own `jest`
|
|
123
|
+
* (`JestModuleObject`).
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
interface JestObject extends JestTimerMembers<JestObject> {
|
|
127
|
+
/** Runs `fn` in an isolated module registry, then returns `jest`. */
|
|
128
|
+
isolateModules(fn: () => void): JestObject;
|
|
129
|
+
/** Runs `fn` in an isolated module registry; resolves with nothing when `fn` has settled. */
|
|
130
|
+
isolateModulesAsync(fn: () => Promise<void>): Promise<void>;
|
|
131
|
+
/** Forgets every module loaded so far in the file, then returns `jest`. */
|
|
132
|
+
resetModules(): JestObject;
|
|
133
|
+
/**
|
|
134
|
+
* Sets the timeout a test or hook with none of its own gets, until this file ends: the tests
|
|
135
|
+
* already declared included (jest-circus reads it when a test runs). `0` leaves the default.
|
|
136
|
+
*/
|
|
137
|
+
setTimeout(timeout: number): JestObject;
|
|
138
|
+
/**
|
|
139
|
+
* Retries a failed test up to `numRetries` times, after the other tests of its describe unless
|
|
140
|
+
* `retryImmediately` (jest-circus's deferred retries). It sets one value for the whole file, as
|
|
141
|
+
* Jest does: each describe reads it when it starts running, and a later call replaces every
|
|
142
|
+
* option. `entireDescribe` retries the whole describe block it is called in (the file at its top
|
|
143
|
+
* level): its hooks and every test below run again while a test fails; it must be called while
|
|
144
|
+
* the file is collected, and sets no file-wide test retry.
|
|
145
|
+
*/
|
|
146
|
+
retryTimes(numRetries: number, options?: JestRetryOptions): JestObject;
|
|
147
|
+
/** The run's random seed (`--seed`, else one drawn per run), the same on every call. */
|
|
148
|
+
getSeed(): number;
|
|
149
|
+
/** Whether the file's environment has been torn down: true for a callback that outlives its file. */
|
|
150
|
+
isEnvironmentTornDown(): boolean;
|
|
151
|
+
/** The argument, typed as mocked (jest-mock's `mocked` is the identity). */
|
|
152
|
+
mocked<T>(item: T): T;
|
|
153
|
+
/** A mock function, running `impl` when it has one. */
|
|
154
|
+
fn<T extends MockTarget = UnknownFunction>(impl?: T): Mock<T>;
|
|
155
|
+
/** Replaces a method with a spy that calls through. */
|
|
156
|
+
spyOn<T extends object, K extends SpyableKeys<T>>(object: T, key: K): SpiedMethod<Required<T>[K]>;
|
|
157
|
+
/** Replaces an accessor's getter with a spy that calls through. */
|
|
158
|
+
spyOn<T extends object, K extends keyof T>(object: T, key: K, access: "get"): SpiedGetter<T[K]>;
|
|
159
|
+
/** Replaces an accessor's setter with a spy that calls through. */
|
|
160
|
+
spyOn<T extends object, K extends keyof T>(object: T, key: K, access: "set"): SpiedSetter<T[K]>;
|
|
161
|
+
/** Whether `value` is a mock function. */
|
|
162
|
+
isMockFunction(value: unknown): value is Mock<UnknownFunction>;
|
|
163
|
+
/** Replaces a data property with `value` until `restore()` or `restoreAllMocks()`. */
|
|
164
|
+
replaceProperty<T extends object, K extends keyof T>(object: T, key: K, value: T[K]): Replaced<T[K]>;
|
|
165
|
+
/** `mockClear` on every mock, then returns `jest`. */
|
|
166
|
+
clearAllMocks(): JestObject;
|
|
167
|
+
/** `mockReset` on every mock, then returns `jest`. */
|
|
168
|
+
resetAllMocks(): JestObject;
|
|
169
|
+
/** Restores every spy and replaced property, then returns `jest`. */
|
|
170
|
+
restoreAllMocks(): JestObject;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* `jest.mock`'s options: `virtual` lets the module not exist on disk.
|
|
174
|
+
* @public
|
|
175
|
+
*/
|
|
176
|
+
interface JestMockOptions {
|
|
177
|
+
readonly virtual?: boolean;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The `jest` each module gets as its own binding (B13c, as jest-runtime's
|
|
181
|
+
* `_createJestObjectFor(from)`): the global's members, plus the module-mock calls, which resolve
|
|
182
|
+
* from the module that makes them. Every chained call returns this module's object.
|
|
183
|
+
* @public
|
|
184
|
+
*/
|
|
185
|
+
interface JestModuleObject extends JestObject {
|
|
186
|
+
useFakeTimers(config?: JestFakeTimersConfig): JestModuleObject;
|
|
187
|
+
useRealTimers(): JestModuleObject;
|
|
188
|
+
setTimerTickMode(mode: {
|
|
189
|
+
mode: "manual" | "nextAsync";
|
|
190
|
+
} | {
|
|
191
|
+
mode: "interval";
|
|
192
|
+
delta?: number;
|
|
193
|
+
}): JestModuleObject;
|
|
194
|
+
/** Mocks `moduleName` for this file, hoisted above the imports: by `factory`, a manual mock, or an automock. */
|
|
195
|
+
mock(moduleName: string, factory?: () => unknown, options?: JestMockOptions): JestModuleObject;
|
|
196
|
+
/** `mock`, not hoisted. */
|
|
197
|
+
doMock(moduleName: string, factory?: () => unknown, options?: JestMockOptions): JestModuleObject;
|
|
198
|
+
/** The real module from now on (hoisted). */
|
|
199
|
+
unmock(moduleName: string): JestModuleObject;
|
|
200
|
+
/** `unmock`, not hoisted. */
|
|
201
|
+
dontMock(moduleName: string): JestModuleObject;
|
|
202
|
+
/** Replaces `moduleName` for this file with `moduleExports`, as an explicit mock (jest-runtime `setMock`). */
|
|
203
|
+
setMock(moduleName: string, moduleExports: unknown): JestModuleObject;
|
|
204
|
+
/** `unmock`: the module and what it imports are real again (Provino unmocks the module itself). */
|
|
205
|
+
deepUnmock(moduleName: string): JestModuleObject;
|
|
206
|
+
/** The real module, whatever is mocked: its own imports still see the mocks. */
|
|
207
|
+
requireActual<T = unknown>(moduleName: string): T;
|
|
208
|
+
/** The mocked module, whether or not it is registered: a manual mock, else an automock. */
|
|
209
|
+
requireMock<T = unknown>(moduleName: string): T;
|
|
210
|
+
/** An automock of the real module, built now and not registered. */
|
|
211
|
+
createMockFromModule<T = unknown>(moduleName: string): T;
|
|
212
|
+
/** Every module the file loads from now on is automocked, unless it is unmocked. */
|
|
213
|
+
enableAutomock(): JestModuleObject;
|
|
214
|
+
disableAutomock(): JestModuleObject;
|
|
215
|
+
isolateModules(fn: () => void): JestModuleObject;
|
|
216
|
+
resetModules(): JestModuleObject;
|
|
217
|
+
setTimeout(timeout: number): JestModuleObject;
|
|
218
|
+
retryTimes(numRetries: number, options?: JestRetryOptions): JestModuleObject;
|
|
219
|
+
/** `enableAutomock`. */
|
|
220
|
+
autoMockOn(): JestModuleObject;
|
|
221
|
+
/** `disableAutomock`. */
|
|
222
|
+
autoMockOff(): JestModuleObject;
|
|
223
|
+
/**
|
|
224
|
+
* Runs `callback` on every automock built from now on, with the module's resolved path and the
|
|
225
|
+
* mock; what it returns is the mock (each callback gets the one before's result).
|
|
226
|
+
*/
|
|
227
|
+
onGenerateMock<T>(callback: (moduleName: string, moduleMock: T) => T): JestModuleObject;
|
|
228
|
+
/** `doMock` for a module the file imports natively: the factory is required. */
|
|
229
|
+
unstable_mockModule(moduleName: string, factory: () => unknown, options?: JestMockOptions): JestModuleObject;
|
|
230
|
+
/** `dontMock`, for `unstable_mockModule`. */
|
|
231
|
+
unstable_unmockModule(moduleName: string): JestModuleObject;
|
|
232
|
+
clearAllMocks(): JestModuleObject;
|
|
233
|
+
resetAllMocks(): JestModuleObject;
|
|
234
|
+
restoreAllMocks(): JestModuleObject;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* The globals Jest 30.5 injects into a test file, exactly: `jestDialect.globals.names` lists
|
|
238
|
+
* these keys. A type alias, not an interface, so it is a `Readonly<Record<string, unknown>>`
|
|
239
|
+
* like a `GlobalsFactory`'s result.
|
|
240
|
+
* @public
|
|
241
|
+
*/
|
|
242
|
+
type JestGlobals = {
|
|
243
|
+
readonly afterAll: RuntimeApi["afterAll"];
|
|
244
|
+
readonly afterEach: RuntimeApi["afterEach"];
|
|
245
|
+
readonly beforeAll: RuntimeApi["beforeAll"];
|
|
246
|
+
readonly beforeEach: RuntimeApi["beforeEach"];
|
|
247
|
+
readonly describe: SuiteApi;
|
|
248
|
+
readonly expect: ReturnType<typeof createExpect>;
|
|
249
|
+
/** `describe.only`. */
|
|
250
|
+
readonly fdescribe: SuiteApi;
|
|
251
|
+
/** `it.only`. */
|
|
252
|
+
readonly fit: TestApi;
|
|
253
|
+
readonly it: TestApi;
|
|
254
|
+
readonly jest: JestObject;
|
|
255
|
+
readonly test: TestApi;
|
|
256
|
+
/** `describe.skip`. */
|
|
257
|
+
readonly xdescribe: SuiteApi;
|
|
258
|
+
/** `it.skip`. */
|
|
259
|
+
readonly xit: TestApi;
|
|
260
|
+
/** `test.skip`. */
|
|
261
|
+
readonly xtest: TestApi;
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* Builds Jest 30.5's injected globals. `describe`, `it`, `test` and the four hooks are core's;
|
|
265
|
+
* the `f` and `x` forms are core's `only` and `skip` modifiers; `expect` is the worker's. Each
|
|
266
|
+
* call returns new objects, and the worker installs them on the environment's global.
|
|
267
|
+
*
|
|
268
|
+
* The `jest` object has `isolateModules`, `isolateModulesAsync` and `resetModules` (each reads
|
|
269
|
+
* `host.registry()` when it is called, because every file has its own registry), and the mock
|
|
270
|
+
* functions `fn`, `spyOn`, `isMockFunction`, `replaceProperty`, `clearAllMocks`, `resetAllMocks`
|
|
271
|
+
* and `restoreAllMocks` (each reads `host.mocks()` and `host.mockPolicy` when it is called).
|
|
272
|
+
* Nothing else: the module-mock calls are on each module's own `jest` (`jestModuleScope`), which
|
|
273
|
+
* knows its caller.
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
export declare function jestGlobals(host: JestGlobalsHost): JestGlobals;
|
|
277
|
+
/**
|
|
278
|
+
* The Jest dialect's per-module bindings (`jestDialect.moduleScope`, a `ModuleScopeFactory`): the
|
|
279
|
+
* loader calls the function this returns for each module whose source names `jest`, and that
|
|
280
|
+
* module's wrapper gets its own `jest`, as jest-runtime's `_createJestObjectFor(from)` gives each
|
|
281
|
+
* module one. Called once per worker; the objects read `host` when they are called, so a module
|
|
282
|
+
* shared under isolation `none` acts on the file running now.
|
|
283
|
+
* @public
|
|
284
|
+
*/
|
|
285
|
+
export declare function jestModuleScope(host: JestGlobalsHost): (from: string) => Readonly<Record<string, unknown>>;
|
|
286
|
+
/** What an environment's `handleTestEvent(event, state)` is, as the mirror calls it. */
|
|
287
|
+
type HandleTestEvent = (event: never, state: never) => void | PromiseLike<void>;
|
|
288
|
+
/**
|
|
289
|
+
* What the adapter is given (JSON, so it crosses to a worker): where the class is and the parts of
|
|
290
|
+
* Jest's `projectConfig` an environment class reads.
|
|
291
|
+
* @public
|
|
292
|
+
*/
|
|
293
|
+
interface JestEnvironmentOptions {
|
|
294
|
+
readonly [key: string]: JsonValue;
|
|
295
|
+
/** The environment package's entry, absolute (the project's own copy). */
|
|
296
|
+
readonly module: string;
|
|
297
|
+
/** What Jest's `projectConfig` holds that an environment reads. */
|
|
298
|
+
readonly projectConfig: {
|
|
299
|
+
readonly [key: string]: JsonValue;
|
|
300
|
+
};
|
|
301
|
+
/** What Jest's `globalConfig` holds that an environment or its `handleTestEvent` state reads. */
|
|
302
|
+
readonly globalConfig?: {
|
|
303
|
+
readonly [key: string]: JsonValue;
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/** The surface of a Jest environment class instance the adapter uses. */
|
|
307
|
+
interface JestEnvironmentLike {
|
|
308
|
+
readonly global: object;
|
|
309
|
+
setup(): Promise<void>;
|
|
310
|
+
teardown(): Promise<void>;
|
|
311
|
+
exportConditions?(): readonly string[];
|
|
312
|
+
/** Jest's per-event hook: called with circus's event and state (T8.5). */
|
|
313
|
+
handleTestEvent?: HandleTestEvent;
|
|
314
|
+
}
|
|
315
|
+
/** A Jest environment class, as jest-runtime constructs it. @public */
|
|
316
|
+
type JestEnvironmentClass = new (config: {
|
|
317
|
+
readonly globalConfig: object;
|
|
318
|
+
readonly projectConfig: object;
|
|
319
|
+
}, context: {
|
|
320
|
+
readonly console: Console;
|
|
321
|
+
readonly docblockPragmas: Pragmas;
|
|
322
|
+
readonly testPath: string;
|
|
323
|
+
}) => JestEnvironmentLike;
|
|
324
|
+
/**
|
|
325
|
+
* Runs the Jest environment class a project names (by path, in `options`): `prepare` imports the
|
|
326
|
+
* class once per worker; `setup` builds one instance per file.
|
|
327
|
+
* @public
|
|
328
|
+
*/
|
|
329
|
+
export declare const jestEnvironment: Environment<"jest-environment", JestEnvironmentOptions>;
|
|
330
|
+
/**
|
|
331
|
+
* An `Environment` over a Jest environment class you already hold (T8.5): for code that builds an
|
|
332
|
+
* environment itself rather than naming a package. `projectConfig` is what the class reads.
|
|
333
|
+
* @public
|
|
334
|
+
*/
|
|
335
|
+
export declare function fromJestEnvironment(EnvironmentClass: JestEnvironmentClass, projectConfig?: object, globalConfig?: object): Environment<"jest-environment", {
|
|
336
|
+
readonly [key: string]: JsonValue;
|
|
337
|
+
}>;
|
|
338
|
+
/**
|
|
339
|
+
* The resolver export conditions of a Jest environment (`orchestrator.environmentConditions`),
|
|
340
|
+
* which jest-runtime reads from the class's `exportConditions()`: the option
|
|
341
|
+
* `customExportConditions` when the project gives it (`['']` for react-hook-form's, which names no
|
|
342
|
+
* condition), else the default of the package Jest ships: `['browser']` for the jsdom family,
|
|
343
|
+
* `['node', 'node-addons']` for `jest-environment-node`, `['edge', 'edge-light']` for the edge
|
|
344
|
+
* runtime. A class this doesn't know has none, as jest-runtime's `?.() ?? []`; `node` is always
|
|
345
|
+
* added (see below).
|
|
346
|
+
* @public
|
|
347
|
+
*/
|
|
348
|
+
export declare const jestEnvironmentConditions: EnvironmentConditions;
|
|
349
|
+
/**
|
|
350
|
+
* The environment a test file's docblock names (`@jest-environment`), resolved as jest-runner's
|
|
351
|
+
* `resolveTestEnvironment` does it for a project: from the project's root, `jsdom` and `node` as
|
|
352
|
+
* their `jest-environment-*` packages, a name as a path or package, then with the
|
|
353
|
+
* `jest-environment-` prefix. The options pragma is merged over the project's
|
|
354
|
+
* `testEnvironmentOptions`. Every environment runs through the adapter (D44).
|
|
355
|
+
* @public
|
|
356
|
+
*/
|
|
357
|
+
export declare const jestEnvironmentFor: EnvironmentResolver;
|
|
358
|
+
/**
|
|
359
|
+
* Jest's text for a failed `node:assert` call, as the error's replacement; any other error as it
|
|
360
|
+
* is. A diff prints in full under `expand` (`--expand`), as `state.expand` does in circus.
|
|
361
|
+
* @public
|
|
362
|
+
*/
|
|
363
|
+
export declare const shapeTestError: ShapeTestError;
|
|
364
|
+
/**
|
|
365
|
+
* `core.shuffle` for the Jest dialect: builds the shuffle of one file from the run's seed. The
|
|
366
|
+
* function it returns reorders an array in place and draws from one generator, so the suites of a
|
|
367
|
+
* file, shuffled in the order they first run, consume it in jest-circus's order.
|
|
368
|
+
* @public
|
|
369
|
+
*/
|
|
370
|
+
export declare function jestShuffle(seed: number): <T>(items: T[]) => T[];
|
|
371
|
+
/**
|
|
372
|
+
* The Jest dialect's snapshot printer: what `jestPolicy.snapshot.printer` loads. The worker builds
|
|
373
|
+
* it once.
|
|
374
|
+
* @public
|
|
375
|
+
*/
|
|
376
|
+
export declare function jestSnapshotPrinter(): SnapshotPrinter;
|
|
377
|
+
/**
|
|
378
|
+
* Builds the Jest resolver of a project's `snapshotResolver` module. Throws Jest's `TypeError`
|
|
379
|
+
* for a missing member and its `Error` for functions that don't invert each other.
|
|
380
|
+
* @public
|
|
381
|
+
*/
|
|
382
|
+
export declare const jestSnapshotResolver: SnapshotResolverFactory;
|
|
383
|
+
/**
|
|
384
|
+
* What jest-snapshot's matchers pass to `SnapshotState.match` (State.ts `SnapshotMatchOptions`).
|
|
385
|
+
* @public
|
|
386
|
+
*/
|
|
387
|
+
interface JestSnapshotMatchOptions {
|
|
388
|
+
readonly testName: string;
|
|
389
|
+
/**
|
|
390
|
+
* jest-circus's test, from the matcher's `currentTestIdentity` (jest-snapshot index.ts L294):
|
|
391
|
+
* Jest's state records the attempt's work against it, for `clear(test)` on a retry. Provino's
|
|
392
|
+
* matcher state has no `currentTestIdentity`, so jest-snapshot passes `undefined`; the view
|
|
393
|
+
* records the snapshot against the attempt the state names (`SnapshotViewSource.currentTestId`).
|
|
394
|
+
*/
|
|
395
|
+
readonly testIdentity?: object | undefined;
|
|
396
|
+
readonly received: unknown;
|
|
397
|
+
readonly key?: string | undefined;
|
|
398
|
+
readonly inlineSnapshot?: string | undefined;
|
|
399
|
+
readonly isInline: boolean;
|
|
400
|
+
/** The error made at a `.resolves`/`.rejects` call: where an inline snapshot is written. */
|
|
401
|
+
readonly error?: Error | undefined;
|
|
402
|
+
readonly testFailing?: boolean | undefined;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* The members of jest-snapshot's `SnapshotState` the view carries, each over the file's state.
|
|
406
|
+
* `_counters`, `_updateSnapshot`, `snapshotFormat` and `snapshotPath` can't be replaced.
|
|
407
|
+
* @public
|
|
408
|
+
*/
|
|
409
|
+
interface JestSnapshotStateView {
|
|
410
|
+
/** How many snapshots each test name has taken: the state's live map. */
|
|
411
|
+
readonly _counters: Map<string, number>;
|
|
412
|
+
/** `all` (`-u`), `new`, or `none` (CI). */
|
|
413
|
+
readonly _updateSnapshot: SnapshotViewSource["update"];
|
|
414
|
+
/** Snapshots written in this file. */
|
|
415
|
+
added: number;
|
|
416
|
+
/** Snapshots that matched the stored ones. */
|
|
417
|
+
matched: number;
|
|
418
|
+
/** Snapshots that failed. */
|
|
419
|
+
unmatched: number;
|
|
420
|
+
/** Stored snapshots rewritten (`-u`). */
|
|
421
|
+
updated: number;
|
|
422
|
+
/** Whether diffs show every line (`--expand`). */
|
|
423
|
+
expand: boolean;
|
|
424
|
+
/** The pretty-format options the file's snapshots are serialized with. */
|
|
425
|
+
readonly snapshotFormat: Readonly<Record<string, unknown>>;
|
|
426
|
+
/** The file's snapshot file. */
|
|
427
|
+
readonly snapshotPath: string;
|
|
428
|
+
/**
|
|
429
|
+
* Compares a value with its stored snapshot, and writes it when the update mode says to, as the
|
|
430
|
+
* running test attempt's (State.ts `SnapshotReturnOptions`).
|
|
431
|
+
*/
|
|
432
|
+
match(options: JestSnapshotMatchOptions): SnapshotViewMatchResult;
|
|
433
|
+
/**
|
|
434
|
+
* A snapshot that couldn't be taken (its property matchers failed), as the running test
|
|
435
|
+
* attempt's; returns its key.
|
|
436
|
+
*/
|
|
437
|
+
fail(testName: string, received: unknown, key?: string, testIdentity?: object): string;
|
|
438
|
+
/** Marks a test's stored snapshots as checked, so they are not reported obsolete. */
|
|
439
|
+
markSnapshotsAsCheckedForTest(testName: string): void;
|
|
440
|
+
/** How many stored snapshots no test has checked yet. */
|
|
441
|
+
getUncheckedCount(): number;
|
|
442
|
+
/** The keys of those snapshots. */
|
|
443
|
+
getUncheckedKeys(): string[];
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Builds Jest's view of a file's snapshot state (`snapshot.contextView`), once per test file.
|
|
447
|
+
* @public
|
|
448
|
+
*/
|
|
449
|
+
export declare function jestSnapshotStateView(state: SnapshotViewSource): JestSnapshotStateView;
|
|
450
|
+
export type { EachTableKind, JestEnvironmentClass, JestEnvironmentOptions, JestFakeTimersConfig, JestGlobals, JestGlobalsHost, JestMockOptions, JestModuleObject, JestObject, JestSnapshotMatchOptions, JestSnapshotStateView, JestTimerMembers };
|