@noma.to/qwik-mock 1.0.2 → 1.1.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.
Files changed (53) hide show
  1. package/lib/lib/qwik-mock.cjs +24 -6
  2. package/lib/lib/qwik-mock.mjs +24 -6
  3. package/lib-types/index.d.ts +2 -1
  4. package/lib-types/lib/qwik-mock.d.ts +21 -19
  5. package/package.json +7 -6
  6. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.cjs +0 -83
  7. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +0 -83
  8. package/lib/node_modules/.pnpm/@vitest_expect@4.0.18/node_modules/@vitest/expect/dist/index.cjs +0 -1785
  9. package/lib/node_modules/.pnpm/@vitest_expect@4.0.18/node_modules/@vitest/expect/dist/index.mjs +0 -1785
  10. package/lib/node_modules/.pnpm/@vitest_pretty-format@4.0.18/node_modules/@vitest/pretty-format/dist/index.cjs +0 -964
  11. package/lib/node_modules/.pnpm/@vitest_pretty-format@4.0.18/node_modules/@vitest/pretty-format/dist/index.mjs +0 -964
  12. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/chunk-tasks.cjs +0 -60
  13. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/chunk-tasks.mjs +0 -60
  14. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/index.cjs +0 -1102
  15. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/index.mjs +0 -1102
  16. package/lib/node_modules/.pnpm/@vitest_snapshot@4.0.18/node_modules/@vitest/snapshot/dist/index.cjs +0 -1289
  17. package/lib/node_modules/.pnpm/@vitest_snapshot@4.0.18/node_modules/@vitest/snapshot/dist/index.mjs +0 -1289
  18. package/lib/node_modules/.pnpm/@vitest_spy@4.0.18/node_modules/@vitest/spy/dist/index.cjs +0 -422
  19. package/lib/node_modules/.pnpm/@vitest_spy@4.0.18/node_modules/@vitest/spy/dist/index.mjs +0 -422
  20. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.cjs +0 -6
  21. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.mjs +0 -6
  22. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.cjs +0 -98
  23. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.mjs +0 -98
  24. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/diff.cjs +0 -1626
  25. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/diff.mjs +0 -1626
  26. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/display.cjs +0 -690
  27. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/display.mjs +0 -690
  28. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/error.cjs +0 -39
  29. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/error.mjs +0 -39
  30. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/helpers.cjs +0 -151
  31. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/helpers.mjs +0 -151
  32. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/serialize.cjs +0 -114
  33. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/serialize.mjs +0 -114
  34. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/source-map.cjs +0 -125
  35. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/source-map.mjs +0 -125
  36. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/timers.cjs +0 -22
  37. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/timers.mjs +0 -22
  38. package/lib/node_modules/.pnpm/chai@6.2.2/node_modules/chai/index.cjs +0 -4056
  39. package/lib/node_modules/.pnpm/chai@6.2.2/node_modules/chai/index.mjs +0 -4056
  40. package/lib/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.cjs +0 -994
  41. package/lib/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs +0 -994
  42. package/lib/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.cjs +0 -101
  43. package/lib/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -101
  44. package/lib/node_modules/.pnpm/tinyrainbow@3.0.3/node_modules/tinyrainbow/dist/index.cjs +0 -84
  45. package/lib/node_modules/.pnpm/tinyrainbow@3.0.3/node_modules/tinyrainbow/dist/index.mjs +0 -84
  46. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.cjs +0 -4
  47. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.mjs +0 -4
  48. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.cjs +0 -51
  49. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.mjs +0 -51
  50. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/utils.DvEY5TfP.cjs +0 -45
  51. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/utils.DvEY5TfP.mjs +0 -45
  52. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/vi.2VT5v0um.cjs +0 -2609
  53. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/vi.2VT5v0um.mjs +0 -2609
@@ -1,1102 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { isNegativeNaN, isObject, toArray, objectAttr, assertTypes, createDefer } from "../../../../../@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/helpers.mjs";
5
- import { getSafeTimers } from "../../../../../@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/timers.mjs";
6
- import { format, formatRegExp, objDisplay } from "../../../../../@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/display.mjs";
7
- import { c as createChainable, e as createTaskName, f as findTestFileStackTrace } from "./chunk-tasks.mjs";
8
- class PendingError extends Error {
9
- constructor(message, task, note) {
10
- super(message);
11
- __publicField(this, "code", "VITEST_PENDING");
12
- __publicField(this, "taskId");
13
- this.message = message;
14
- this.note = note;
15
- this.taskId = task.id;
16
- }
17
- }
18
- const fnMap = /* @__PURE__ */ new WeakMap();
19
- const testFixtureMap = /* @__PURE__ */ new WeakMap();
20
- const hooksMap = /* @__PURE__ */ new WeakMap();
21
- function setFn(key, fn) {
22
- fnMap.set(key, fn);
23
- }
24
- function setTestFixture(key, fixture) {
25
- testFixtureMap.set(key, fixture);
26
- }
27
- function getTestFixture(key) {
28
- return testFixtureMap.get(key);
29
- }
30
- function setHooks(key, hooks) {
31
- hooksMap.set(key, hooks);
32
- }
33
- function getHooks(key) {
34
- return hooksMap.get(key);
35
- }
36
- function mergeScopedFixtures(testFixtures, scopedFixtures) {
37
- const scopedFixturesMap = scopedFixtures.reduce((map, fixture) => {
38
- map[fixture.prop] = fixture;
39
- return map;
40
- }, {});
41
- const newFixtures = {};
42
- testFixtures.forEach((fixture) => {
43
- const useFixture = scopedFixturesMap[fixture.prop] || { ...fixture };
44
- newFixtures[useFixture.prop] = useFixture;
45
- });
46
- for (const fixtureKep in newFixtures) {
47
- var _fixture$deps;
48
- const fixture = newFixtures[fixtureKep];
49
- fixture.deps = (_fixture$deps = fixture.deps) === null || _fixture$deps === void 0 ? void 0 : _fixture$deps.map((dep) => newFixtures[dep.prop]);
50
- }
51
- return Object.values(newFixtures);
52
- }
53
- function mergeContextFixtures(fixtures, context, runner2) {
54
- const fixtureOptionKeys = [
55
- "auto",
56
- "injected",
57
- "scope"
58
- ];
59
- const fixtureArray = Object.entries(fixtures).map(([prop, value]) => {
60
- const fixtureItem = { value };
61
- if (Array.isArray(value) && value.length >= 2 && isObject(value[1]) && Object.keys(value[1]).some((key) => fixtureOptionKeys.includes(key))) {
62
- var _runner$injectValue;
63
- Object.assign(fixtureItem, value[1]);
64
- const userValue = value[0];
65
- fixtureItem.value = fixtureItem.injected ? ((_runner$injectValue = runner2.injectValue) === null || _runner$injectValue === void 0 ? void 0 : _runner$injectValue.call(runner2, prop)) ?? userValue : userValue;
66
- }
67
- fixtureItem.scope = fixtureItem.scope || "test";
68
- if (fixtureItem.scope === "worker" && !runner2.getWorkerContext) {
69
- fixtureItem.scope = "file";
70
- }
71
- fixtureItem.prop = prop;
72
- fixtureItem.isFn = typeof fixtureItem.value === "function";
73
- return fixtureItem;
74
- });
75
- if (Array.isArray(context.fixtures)) {
76
- context.fixtures = context.fixtures.concat(fixtureArray);
77
- } else {
78
- context.fixtures = fixtureArray;
79
- }
80
- fixtureArray.forEach((fixture) => {
81
- if (fixture.isFn) {
82
- const usedProps = getUsedProps(fixture.value);
83
- if (usedProps.length) {
84
- fixture.deps = context.fixtures.filter(({ prop }) => prop !== fixture.prop && usedProps.includes(prop));
85
- }
86
- if (fixture.scope !== "test") {
87
- var _fixture$deps2;
88
- (_fixture$deps2 = fixture.deps) === null || _fixture$deps2 === void 0 ? void 0 : _fixture$deps2.forEach((dep) => {
89
- if (!dep.isFn) {
90
- return;
91
- }
92
- if (fixture.scope === "worker" && dep.scope === "worker") {
93
- return;
94
- }
95
- if (fixture.scope === "file" && dep.scope !== "test") {
96
- return;
97
- }
98
- throw new SyntaxError(`cannot use the ${dep.scope} fixture "${dep.prop}" inside the ${fixture.scope} fixture "${fixture.prop}"`);
99
- });
100
- }
101
- }
102
- });
103
- return context;
104
- }
105
- const fixtureValueMaps = /* @__PURE__ */ new Map();
106
- const cleanupFnArrayMap = /* @__PURE__ */ new Map();
107
- function withFixtures(runner2, fn, testContext) {
108
- return (hookContext) => {
109
- const context = hookContext || testContext;
110
- if (!context) {
111
- return fn({});
112
- }
113
- const fixtures = getTestFixture(context);
114
- if (!(fixtures === null || fixtures === void 0 ? void 0 : fixtures.length)) {
115
- return fn(context);
116
- }
117
- const usedProps = getUsedProps(fn);
118
- const hasAutoFixture = fixtures.some(({ auto }) => auto);
119
- if (!usedProps.length && !hasAutoFixture) {
120
- return fn(context);
121
- }
122
- if (!fixtureValueMaps.get(context)) {
123
- fixtureValueMaps.set(context, /* @__PURE__ */ new Map());
124
- }
125
- const fixtureValueMap = fixtureValueMaps.get(context);
126
- if (!cleanupFnArrayMap.has(context)) {
127
- cleanupFnArrayMap.set(context, []);
128
- }
129
- const cleanupFnArray = cleanupFnArrayMap.get(context);
130
- const usedFixtures = fixtures.filter(({ prop, auto }) => auto || usedProps.includes(prop));
131
- const pendingFixtures = resolveDeps(usedFixtures);
132
- if (!pendingFixtures.length) {
133
- return fn(context);
134
- }
135
- async function resolveFixtures() {
136
- for (const fixture of pendingFixtures) {
137
- if (fixtureValueMap.has(fixture)) {
138
- continue;
139
- }
140
- const resolvedValue = await resolveFixtureValue(runner2, fixture, context, cleanupFnArray);
141
- context[fixture.prop] = resolvedValue;
142
- fixtureValueMap.set(fixture, resolvedValue);
143
- if (fixture.scope === "test") {
144
- cleanupFnArray.unshift(() => {
145
- fixtureValueMap.delete(fixture);
146
- });
147
- }
148
- }
149
- }
150
- return resolveFixtures().then(() => fn(context));
151
- };
152
- }
153
- const globalFixturePromise = /* @__PURE__ */ new WeakMap();
154
- function resolveFixtureValue(runner2, fixture, context, cleanupFnArray) {
155
- var _runner$getWorkerCont;
156
- const fileContext = getFileContext(context.task.file);
157
- const workerContext = (_runner$getWorkerCont = runner2.getWorkerContext) === null || _runner$getWorkerCont === void 0 ? void 0 : _runner$getWorkerCont.call(runner2);
158
- if (!fixture.isFn) {
159
- var _fixture$prop;
160
- fileContext[_fixture$prop = fixture.prop] ?? (fileContext[_fixture$prop] = fixture.value);
161
- if (workerContext) {
162
- var _fixture$prop2;
163
- workerContext[_fixture$prop2 = fixture.prop] ?? (workerContext[_fixture$prop2] = fixture.value);
164
- }
165
- return fixture.value;
166
- }
167
- if (fixture.scope === "test") {
168
- return resolveFixtureFunction(fixture.value, context, cleanupFnArray);
169
- }
170
- if (globalFixturePromise.has(fixture)) {
171
- return globalFixturePromise.get(fixture);
172
- }
173
- let fixtureContext;
174
- if (fixture.scope === "worker") {
175
- if (!workerContext) {
176
- throw new TypeError("[@vitest/runner] The worker context is not available in the current test runner. Please, provide the `getWorkerContext` method when initiating the runner.");
177
- }
178
- fixtureContext = workerContext;
179
- } else {
180
- fixtureContext = fileContext;
181
- }
182
- if (fixture.prop in fixtureContext) {
183
- return fixtureContext[fixture.prop];
184
- }
185
- if (!cleanupFnArrayMap.has(fixtureContext)) {
186
- cleanupFnArrayMap.set(fixtureContext, []);
187
- }
188
- const cleanupFnFileArray = cleanupFnArrayMap.get(fixtureContext);
189
- const promise = resolveFixtureFunction(fixture.value, fixtureContext, cleanupFnFileArray).then((value) => {
190
- fixtureContext[fixture.prop] = value;
191
- globalFixturePromise.delete(fixture);
192
- return value;
193
- });
194
- globalFixturePromise.set(fixture, promise);
195
- return promise;
196
- }
197
- async function resolveFixtureFunction(fixtureFn, context, cleanupFnArray) {
198
- const useFnArgPromise = createDefer();
199
- let isUseFnArgResolved = false;
200
- const fixtureReturn = fixtureFn(context, async (useFnArg) => {
201
- isUseFnArgResolved = true;
202
- useFnArgPromise.resolve(useFnArg);
203
- const useReturnPromise = createDefer();
204
- cleanupFnArray.push(async () => {
205
- useReturnPromise.resolve();
206
- await fixtureReturn;
207
- });
208
- await useReturnPromise;
209
- }).catch((e) => {
210
- if (!isUseFnArgResolved) {
211
- useFnArgPromise.reject(e);
212
- return;
213
- }
214
- throw e;
215
- });
216
- return useFnArgPromise;
217
- }
218
- function resolveDeps(fixtures, depSet = /* @__PURE__ */ new Set(), pendingFixtures = []) {
219
- fixtures.forEach((fixture) => {
220
- if (pendingFixtures.includes(fixture)) {
221
- return;
222
- }
223
- if (!fixture.isFn || !fixture.deps) {
224
- pendingFixtures.push(fixture);
225
- return;
226
- }
227
- if (depSet.has(fixture)) {
228
- throw new Error(`Circular fixture dependency detected: ${fixture.prop} <- ${[...depSet].reverse().map((d) => d.prop).join(" <- ")}`);
229
- }
230
- depSet.add(fixture);
231
- resolveDeps(fixture.deps, depSet, pendingFixtures);
232
- pendingFixtures.push(fixture);
233
- depSet.clear();
234
- });
235
- return pendingFixtures;
236
- }
237
- function getUsedProps(fn) {
238
- let fnString = filterOutComments(fn.toString());
239
- if (/__async\((?:this|null), (?:null|arguments|\[[_0-9, ]*\]), function\*/.test(fnString)) {
240
- fnString = fnString.split(/__async\((?:this|null),/)[1];
241
- }
242
- const match = fnString.match(/[^(]*\(([^)]*)/);
243
- if (!match) {
244
- return [];
245
- }
246
- const args = splitByComma(match[1]);
247
- if (!args.length) {
248
- return [];
249
- }
250
- let first = args[0];
251
- if ("__VITEST_FIXTURE_INDEX__" in fn) {
252
- first = args[fn.__VITEST_FIXTURE_INDEX__];
253
- if (!first) {
254
- return [];
255
- }
256
- }
257
- if (!(first[0] === "{" && first.endsWith("}"))) {
258
- throw new Error(`The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "${first}".`);
259
- }
260
- const _first = first.slice(1, -1).replace(/\s/g, "");
261
- const props = splitByComma(_first).map((prop) => {
262
- return prop.replace(/:.*|=.*/g, "");
263
- });
264
- const last = props.at(-1);
265
- if (last && last.startsWith("...")) {
266
- throw new Error(`Rest parameters are not supported in fixtures, received "${last}".`);
267
- }
268
- return props;
269
- }
270
- function filterOutComments(s) {
271
- const result = [];
272
- let commentState = "none";
273
- for (let i = 0; i < s.length; ++i) {
274
- if (commentState === "singleline") {
275
- if (s[i] === "\n") {
276
- commentState = "none";
277
- }
278
- } else if (commentState === "multiline") {
279
- if (s[i - 1] === "*" && s[i] === "/") {
280
- commentState = "none";
281
- }
282
- } else if (commentState === "none") {
283
- if (s[i] === "/" && s[i + 1] === "/") {
284
- commentState = "singleline";
285
- } else if (s[i] === "/" && s[i + 1] === "*") {
286
- commentState = "multiline";
287
- i += 2;
288
- } else {
289
- result.push(s[i]);
290
- }
291
- }
292
- }
293
- return result.join("");
294
- }
295
- function splitByComma(s) {
296
- const result = [];
297
- const stack = [];
298
- let start = 0;
299
- for (let i = 0; i < s.length; i++) {
300
- if (s[i] === "{" || s[i] === "[") {
301
- stack.push(s[i] === "{" ? "}" : "]");
302
- } else if (s[i] === stack.at(-1)) {
303
- stack.pop();
304
- } else if (!stack.length && s[i] === ",") {
305
- const token = s.substring(start, i).trim();
306
- if (token) {
307
- result.push(token);
308
- }
309
- start = i + 1;
310
- }
311
- }
312
- const lastToken = s.substring(start).trim();
313
- if (lastToken) {
314
- result.push(lastToken);
315
- }
316
- return result;
317
- }
318
- function getDefaultHookTimeout() {
319
- return getRunner().config.hookTimeout;
320
- }
321
- const CLEANUP_TIMEOUT_KEY = /* @__PURE__ */ Symbol.for("VITEST_CLEANUP_TIMEOUT");
322
- const CLEANUP_STACK_TRACE_KEY = /* @__PURE__ */ Symbol.for("VITEST_CLEANUP_STACK_TRACE");
323
- function beforeAll(fn, timeout = getDefaultHookTimeout()) {
324
- assertTypes(fn, '"beforeAll" callback', ["function"]);
325
- const stackTraceError = new Error("STACK_TRACE_ERROR");
326
- return getCurrentSuite().on("beforeAll", Object.assign(withTimeout(fn, timeout, true, stackTraceError), {
327
- [CLEANUP_TIMEOUT_KEY]: timeout,
328
- [CLEANUP_STACK_TRACE_KEY]: stackTraceError
329
- }));
330
- }
331
- function afterAll(fn, timeout) {
332
- assertTypes(fn, '"afterAll" callback', ["function"]);
333
- return getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout(), true, new Error("STACK_TRACE_ERROR")));
334
- }
335
- function beforeEach(fn, timeout = getDefaultHookTimeout()) {
336
- assertTypes(fn, '"beforeEach" callback', ["function"]);
337
- const stackTraceError = new Error("STACK_TRACE_ERROR");
338
- const runner2 = getRunner();
339
- return getCurrentSuite().on("beforeEach", Object.assign(withTimeout(withFixtures(runner2, fn), timeout ?? getDefaultHookTimeout(), true, stackTraceError, abortIfTimeout), {
340
- [CLEANUP_TIMEOUT_KEY]: timeout,
341
- [CLEANUP_STACK_TRACE_KEY]: stackTraceError
342
- }));
343
- }
344
- function afterEach(fn, timeout) {
345
- assertTypes(fn, '"afterEach" callback', ["function"]);
346
- const runner2 = getRunner();
347
- return getCurrentSuite().on("afterEach", withTimeout(withFixtures(runner2, fn), timeout ?? getDefaultHookTimeout(), true, new Error("STACK_TRACE_ERROR"), abortIfTimeout));
348
- }
349
- const suite = createSuite();
350
- createTest(function(name, optionsOrFn, optionsOrTest) {
351
- getCurrentSuite().test.fn.call(this, formatName(name), optionsOrFn, optionsOrTest);
352
- });
353
- let runner;
354
- let defaultSuite;
355
- let currentTestFilepath;
356
- function assert(condition, message) {
357
- if (!condition) {
358
- throw new Error(`Vitest failed to find ${message}. One of the following is possible:
359
- - "vitest" is imported directly without running "vitest" command
360
- - "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)
361
- - "vitest" is imported inside Vite / Vitest config file
362
- - Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues
363
- `);
364
- }
365
- }
366
- function getRunner() {
367
- assert(runner, "the runner");
368
- return runner;
369
- }
370
- function getCurrentSuite() {
371
- const currentSuite = collectorContext.currentSuite || defaultSuite;
372
- assert(currentSuite, "the current suite");
373
- return currentSuite;
374
- }
375
- function createSuiteHooks() {
376
- return {
377
- beforeAll: [],
378
- afterAll: [],
379
- beforeEach: [],
380
- afterEach: []
381
- };
382
- }
383
- function parseArguments(optionsOrFn, timeoutOrTest) {
384
- if (timeoutOrTest != null && typeof timeoutOrTest === "object") {
385
- throw new TypeError(`Signature "test(name, fn, { ... })" was deprecated in Vitest 3 and removed in Vitest 4. Please, provide options as a second argument instead.`);
386
- }
387
- let options = {};
388
- let fn;
389
- if (typeof timeoutOrTest === "number") {
390
- options = { timeout: timeoutOrTest };
391
- } else if (typeof optionsOrFn === "object") {
392
- options = optionsOrFn;
393
- }
394
- if (typeof optionsOrFn === "function") {
395
- if (typeof timeoutOrTest === "function") {
396
- throw new TypeError("Cannot use two functions as arguments. Please use the second argument for options.");
397
- }
398
- fn = optionsOrFn;
399
- } else if (typeof timeoutOrTest === "function") {
400
- fn = timeoutOrTest;
401
- }
402
- return {
403
- options,
404
- handler: fn
405
- };
406
- }
407
- function createSuiteCollector(name, factory = () => {
408
- }, mode, each, suiteOptions, parentCollectorFixtures) {
409
- const tasks = [];
410
- let suite2;
411
- initSuite();
412
- const task = function(name2 = "", options = {}) {
413
- var _collectorContext$cur, _collectorContext$cur2, _collectorContext$cur3;
414
- const timeout = (options === null || options === void 0 ? void 0 : options.timeout) ?? runner.config.testTimeout;
415
- const currentSuite = (_collectorContext$cur = collectorContext.currentSuite) === null || _collectorContext$cur === void 0 ? void 0 : _collectorContext$cur.suite;
416
- const task2 = {
417
- id: "",
418
- name: name2,
419
- fullName: createTaskName([(currentSuite === null || currentSuite === void 0 ? void 0 : currentSuite.fullName) ?? ((_collectorContext$cur2 = collectorContext.currentSuite) === null || _collectorContext$cur2 === void 0 || (_collectorContext$cur2 = _collectorContext$cur2.file) === null || _collectorContext$cur2 === void 0 ? void 0 : _collectorContext$cur2.fullName), name2]),
420
- fullTestName: createTaskName([currentSuite === null || currentSuite === void 0 ? void 0 : currentSuite.fullTestName, name2]),
421
- suite: currentSuite,
422
- each: options.each,
423
- fails: options.fails,
424
- context: void 0,
425
- type: "test",
426
- file: (currentSuite === null || currentSuite === void 0 ? void 0 : currentSuite.file) ?? ((_collectorContext$cur3 = collectorContext.currentSuite) === null || _collectorContext$cur3 === void 0 ? void 0 : _collectorContext$cur3.file),
427
- timeout,
428
- retry: options.retry ?? runner.config.retry,
429
- repeats: options.repeats,
430
- mode: options.only ? "only" : options.skip ? "skip" : options.todo ? "todo" : "run",
431
- meta: options.meta ?? /* @__PURE__ */ Object.create(null),
432
- annotations: [],
433
- artifacts: []
434
- };
435
- const handler = options.handler;
436
- if (task2.mode === "run" && !handler) {
437
- task2.mode = "todo";
438
- }
439
- if (options.concurrent || !options.sequential && runner.config.sequence.concurrent) {
440
- task2.concurrent = true;
441
- }
442
- task2.shuffle = suiteOptions === null || suiteOptions === void 0 ? void 0 : suiteOptions.shuffle;
443
- const context = createTestContext(task2, runner);
444
- Object.defineProperty(task2, "context", {
445
- value: context,
446
- enumerable: false
447
- });
448
- setTestFixture(context, options.fixtures);
449
- const limit = Error.stackTraceLimit;
450
- Error.stackTraceLimit = 15;
451
- const stackTraceError = new Error("STACK_TRACE_ERROR");
452
- Error.stackTraceLimit = limit;
453
- if (handler) {
454
- setFn(task2, withTimeout(withAwaitAsyncAssertions(withFixtures(runner, handler, context), task2), timeout, false, stackTraceError, (_, error) => abortIfTimeout([context], error)));
455
- }
456
- if (runner.config.includeTaskLocation) {
457
- const error = stackTraceError.stack;
458
- const stack = findTestFileStackTrace(currentTestFilepath, error);
459
- if (stack) {
460
- task2.location = {
461
- line: stack.line,
462
- column: stack.column
463
- };
464
- }
465
- }
466
- tasks.push(task2);
467
- return task2;
468
- };
469
- const test = createTest(function(name2, optionsOrFn, timeoutOrTest) {
470
- let { options, handler } = parseArguments(optionsOrFn, timeoutOrTest);
471
- if (typeof suiteOptions === "object") {
472
- options = Object.assign({}, suiteOptions, options);
473
- }
474
- options.concurrent = this.concurrent || !this.sequential && (options === null || options === void 0 ? void 0 : options.concurrent);
475
- options.sequential = this.sequential || !this.concurrent && (options === null || options === void 0 ? void 0 : options.sequential);
476
- const test2 = task(formatName(name2), {
477
- ...this,
478
- ...options,
479
- handler
480
- });
481
- test2.type = "test";
482
- });
483
- let collectorFixtures = parentCollectorFixtures;
484
- const collector = {
485
- type: "collector",
486
- name,
487
- mode,
488
- suite: suite2,
489
- options: suiteOptions,
490
- test,
491
- tasks,
492
- collect,
493
- task,
494
- clear,
495
- on: addHook,
496
- fixtures() {
497
- return collectorFixtures;
498
- },
499
- scoped(fixtures) {
500
- const parsed = mergeContextFixtures(fixtures, { fixtures: collectorFixtures }, runner);
501
- if (parsed.fixtures) {
502
- collectorFixtures = parsed.fixtures;
503
- }
504
- }
505
- };
506
- function addHook(name2, ...fn) {
507
- getHooks(suite2)[name2].push(...fn);
508
- }
509
- function initSuite(includeLocation) {
510
- var _collectorContext$cur4, _collectorContext$cur5, _collectorContext$cur6;
511
- if (typeof suiteOptions === "number") {
512
- suiteOptions = { timeout: suiteOptions };
513
- }
514
- const currentSuite = (_collectorContext$cur4 = collectorContext.currentSuite) === null || _collectorContext$cur4 === void 0 ? void 0 : _collectorContext$cur4.suite;
515
- suite2 = {
516
- id: "",
517
- type: "suite",
518
- name,
519
- fullName: createTaskName([(currentSuite === null || currentSuite === void 0 ? void 0 : currentSuite.fullName) ?? ((_collectorContext$cur5 = collectorContext.currentSuite) === null || _collectorContext$cur5 === void 0 || (_collectorContext$cur5 = _collectorContext$cur5.file) === null || _collectorContext$cur5 === void 0 ? void 0 : _collectorContext$cur5.fullName), name]),
520
- fullTestName: createTaskName([currentSuite === null || currentSuite === void 0 ? void 0 : currentSuite.fullTestName, name]),
521
- suite: currentSuite,
522
- mode,
523
- each,
524
- file: (currentSuite === null || currentSuite === void 0 ? void 0 : currentSuite.file) ?? ((_collectorContext$cur6 = collectorContext.currentSuite) === null || _collectorContext$cur6 === void 0 ? void 0 : _collectorContext$cur6.file),
525
- shuffle: suiteOptions === null || suiteOptions === void 0 ? void 0 : suiteOptions.shuffle,
526
- tasks: [],
527
- meta: /* @__PURE__ */ Object.create(null),
528
- concurrent: suiteOptions === null || suiteOptions === void 0 ? void 0 : suiteOptions.concurrent
529
- };
530
- setHooks(suite2, createSuiteHooks());
531
- }
532
- function clear() {
533
- tasks.length = 0;
534
- initSuite();
535
- }
536
- async function collect(file) {
537
- if (!file) {
538
- throw new TypeError("File is required to collect tasks.");
539
- }
540
- if (factory) {
541
- await runWithSuite(collector, () => factory(test));
542
- }
543
- const allChildren = [];
544
- for (const i of tasks) {
545
- allChildren.push(i.type === "collector" ? await i.collect(file) : i);
546
- }
547
- suite2.tasks = allChildren;
548
- return suite2;
549
- }
550
- collectTask(collector);
551
- return collector;
552
- }
553
- function withAwaitAsyncAssertions(fn, task) {
554
- return (async (...args) => {
555
- const fnResult = await fn(...args);
556
- if (task.promises) {
557
- const result = await Promise.allSettled(task.promises);
558
- const errors = result.map((r) => r.status === "rejected" ? r.reason : void 0).filter(Boolean);
559
- if (errors.length) {
560
- throw errors;
561
- }
562
- }
563
- return fnResult;
564
- });
565
- }
566
- function createSuite() {
567
- function suiteFn(name, factoryOrOptions, optionsOrFactory) {
568
- var _currentSuite$options;
569
- let mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
570
- const currentSuite = collectorContext.currentSuite || defaultSuite;
571
- let { options, handler: factory } = parseArguments(factoryOrOptions, optionsOrFactory);
572
- if (mode === "run" && !factory) {
573
- mode = "todo";
574
- }
575
- const isConcurrentSpecified = options.concurrent || this.concurrent || options.sequential === false;
576
- const isSequentialSpecified = options.sequential || this.sequential || options.concurrent === false;
577
- options = {
578
- ...currentSuite === null || currentSuite === void 0 ? void 0 : currentSuite.options,
579
- ...options,
580
- shuffle: this.shuffle ?? options.shuffle ?? (currentSuite === null || currentSuite === void 0 || (_currentSuite$options = currentSuite.options) === null || _currentSuite$options === void 0 ? void 0 : _currentSuite$options.shuffle) ?? void 0
581
- };
582
- const isConcurrent = isConcurrentSpecified || options.concurrent && !isSequentialSpecified;
583
- const isSequential = isSequentialSpecified || options.sequential && !isConcurrentSpecified;
584
- options.concurrent = isConcurrent && !isSequential;
585
- options.sequential = isSequential && !isConcurrent;
586
- return createSuiteCollector(formatName(name), factory, mode, this.each, options, currentSuite === null || currentSuite === void 0 ? void 0 : currentSuite.fixtures());
587
- }
588
- suiteFn.each = function(cases, ...args) {
589
- const suite2 = this.withContext();
590
- this.setContext("each", true);
591
- if (Array.isArray(cases) && args.length) {
592
- cases = formatTemplateString(cases, args);
593
- }
594
- return (name, optionsOrFn, fnOrOptions) => {
595
- const _name = formatName(name);
596
- const arrayOnlyCases = cases.every(Array.isArray);
597
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
598
- const fnFirst = typeof optionsOrFn === "function";
599
- cases.forEach((i, idx) => {
600
- const items = Array.isArray(i) ? i : [i];
601
- if (fnFirst) {
602
- if (arrayOnlyCases) {
603
- suite2(formatTitle(_name, items, idx), handler ? () => handler(...items) : void 0, options.timeout);
604
- } else {
605
- suite2(formatTitle(_name, items, idx), handler ? () => handler(i) : void 0, options.timeout);
606
- }
607
- } else {
608
- if (arrayOnlyCases) {
609
- suite2(formatTitle(_name, items, idx), options, handler ? () => handler(...items) : void 0);
610
- } else {
611
- suite2(formatTitle(_name, items, idx), options, handler ? () => handler(i) : void 0);
612
- }
613
- }
614
- });
615
- this.setContext("each", void 0);
616
- };
617
- };
618
- suiteFn.for = function(cases, ...args) {
619
- if (Array.isArray(cases) && args.length) {
620
- cases = formatTemplateString(cases, args);
621
- }
622
- return (name, optionsOrFn, fnOrOptions) => {
623
- const name_ = formatName(name);
624
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
625
- cases.forEach((item, idx) => {
626
- suite(formatTitle(name_, toArray(item), idx), options, handler ? () => handler(item) : void 0);
627
- });
628
- };
629
- };
630
- suiteFn.skipIf = (condition) => condition ? suite.skip : suite;
631
- suiteFn.runIf = (condition) => condition ? suite : suite.skip;
632
- return createChainable([
633
- "concurrent",
634
- "sequential",
635
- "shuffle",
636
- "skip",
637
- "only",
638
- "todo"
639
- ], suiteFn);
640
- }
641
- function createTaskCollector(fn, context) {
642
- const taskFn = fn;
643
- taskFn.each = function(cases, ...args) {
644
- const test = this.withContext();
645
- this.setContext("each", true);
646
- if (Array.isArray(cases) && args.length) {
647
- cases = formatTemplateString(cases, args);
648
- }
649
- return (name, optionsOrFn, fnOrOptions) => {
650
- const _name = formatName(name);
651
- const arrayOnlyCases = cases.every(Array.isArray);
652
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
653
- const fnFirst = typeof optionsOrFn === "function";
654
- cases.forEach((i, idx) => {
655
- const items = Array.isArray(i) ? i : [i];
656
- if (fnFirst) {
657
- if (arrayOnlyCases) {
658
- test(formatTitle(_name, items, idx), handler ? () => handler(...items) : void 0, options.timeout);
659
- } else {
660
- test(formatTitle(_name, items, idx), handler ? () => handler(i) : void 0, options.timeout);
661
- }
662
- } else {
663
- if (arrayOnlyCases) {
664
- test(formatTitle(_name, items, idx), options, handler ? () => handler(...items) : void 0);
665
- } else {
666
- test(formatTitle(_name, items, idx), options, handler ? () => handler(i) : void 0);
667
- }
668
- }
669
- });
670
- this.setContext("each", void 0);
671
- };
672
- };
673
- taskFn.for = function(cases, ...args) {
674
- const test = this.withContext();
675
- if (Array.isArray(cases) && args.length) {
676
- cases = formatTemplateString(cases, args);
677
- }
678
- return (name, optionsOrFn, fnOrOptions) => {
679
- const _name = formatName(name);
680
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
681
- cases.forEach((item, idx) => {
682
- const handlerWrapper = handler ? (ctx) => handler(item, ctx) : void 0;
683
- if (handlerWrapper) {
684
- handlerWrapper.__VITEST_FIXTURE_INDEX__ = 1;
685
- handlerWrapper.toString = () => handler.toString();
686
- }
687
- test(formatTitle(_name, toArray(item), idx), options, handlerWrapper);
688
- });
689
- };
690
- };
691
- taskFn.skipIf = function(condition) {
692
- return condition ? this.skip : this;
693
- };
694
- taskFn.runIf = function(condition) {
695
- return condition ? this : this.skip;
696
- };
697
- taskFn.scoped = function(fixtures) {
698
- const collector = getCurrentSuite();
699
- collector.scoped(fixtures);
700
- };
701
- taskFn.extend = function(fixtures) {
702
- const _context = mergeContextFixtures(fixtures, context || {}, runner);
703
- const originalWrapper = fn;
704
- return createTest(function(name, optionsOrFn, optionsOrTest) {
705
- const collector = getCurrentSuite();
706
- const scopedFixtures = collector.fixtures();
707
- const context2 = { ...this };
708
- if (scopedFixtures) {
709
- context2.fixtures = mergeScopedFixtures(context2.fixtures || [], scopedFixtures);
710
- }
711
- originalWrapper.call(context2, formatName(name), optionsOrFn, optionsOrTest);
712
- }, _context);
713
- };
714
- taskFn.beforeEach = beforeEach;
715
- taskFn.afterEach = afterEach;
716
- taskFn.beforeAll = beforeAll;
717
- taskFn.afterAll = afterAll;
718
- const _test = createChainable([
719
- "concurrent",
720
- "sequential",
721
- "skip",
722
- "only",
723
- "todo",
724
- "fails"
725
- ], taskFn);
726
- if (context) {
727
- _test.mergeContext(context);
728
- }
729
- return _test;
730
- }
731
- function createTest(fn, context) {
732
- return createTaskCollector(fn, context);
733
- }
734
- function formatName(name) {
735
- return typeof name === "string" ? name : typeof name === "function" ? name.name || "<anonymous>" : String(name);
736
- }
737
- function formatTitle(template, items, idx) {
738
- if (template.includes("%#") || template.includes("%$")) {
739
- template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/%\$/g, `${idx + 1}`).replace(/__vitest_escaped_%__/g, "%%");
740
- }
741
- const count = template.split("%").length - 1;
742
- if (template.includes("%f")) {
743
- const placeholders = template.match(/%f/g) || [];
744
- placeholders.forEach((_, i2) => {
745
- if (isNegativeNaN(items[i2]) || Object.is(items[i2], -0)) {
746
- let occurrence = 0;
747
- template = template.replace(/%f/g, (match) => {
748
- occurrence++;
749
- return occurrence === i2 + 1 ? "-%f" : match;
750
- });
751
- }
752
- });
753
- }
754
- const isObjectItem = isObject(items[0]);
755
- function formatAttribute(s) {
756
- return s.replace(/\$([$\w.]+)/g, (_, key) => {
757
- const isArrayKey = /^\d+$/.test(key);
758
- if (!isObjectItem && !isArrayKey) {
759
- return `$${key}`;
760
- }
761
- const arrayElement = isArrayKey ? objectAttr(items, key) : void 0;
762
- const value = isObjectItem ? objectAttr(items[0], key, arrayElement) : arrayElement;
763
- return objDisplay(value, { truncate: void 0 });
764
- });
765
- }
766
- let output = "";
767
- let i = 0;
768
- handleRegexMatch(
769
- template,
770
- formatRegExp,
771
- // format "%"
772
- (match) => {
773
- if (i < count) {
774
- output += format(match[0], items[i++]);
775
- } else {
776
- output += match[0];
777
- }
778
- },
779
- // format "$"
780
- (nonMatch) => {
781
- output += formatAttribute(nonMatch);
782
- }
783
- );
784
- return output;
785
- }
786
- function handleRegexMatch(input, regex, onMatch, onNonMatch) {
787
- let lastIndex = 0;
788
- for (const m of input.matchAll(regex)) {
789
- if (lastIndex < m.index) {
790
- onNonMatch(input.slice(lastIndex, m.index));
791
- }
792
- onMatch(m);
793
- lastIndex = m.index + m[0].length;
794
- }
795
- if (lastIndex < input.length) {
796
- onNonMatch(input.slice(lastIndex));
797
- }
798
- }
799
- function formatTemplateString(cases, args) {
800
- const header = cases.join("").trim().replace(/ /g, "").split("\n").map((i) => i.split("|"))[0];
801
- const res = [];
802
- for (let i = 0; i < Math.floor(args.length / header.length); i++) {
803
- const oneCase = {};
804
- for (let j = 0; j < header.length; j++) {
805
- oneCase[header[j]] = args[i * header.length + j];
806
- }
807
- res.push(oneCase);
808
- }
809
- return res;
810
- }
811
- const now$2 = Date.now;
812
- const collectorContext = {
813
- currentSuite: null
814
- };
815
- function collectTask(task) {
816
- var _collectorContext$cur;
817
- (_collectorContext$cur = collectorContext.currentSuite) === null || _collectorContext$cur === void 0 ? void 0 : _collectorContext$cur.tasks.push(task);
818
- }
819
- async function runWithSuite(suite2, fn) {
820
- const prev = collectorContext.currentSuite;
821
- collectorContext.currentSuite = suite2;
822
- await fn();
823
- collectorContext.currentSuite = prev;
824
- }
825
- function withTimeout(fn, timeout, isHook = false, stackTraceError, onTimeout) {
826
- if (timeout <= 0 || timeout === Number.POSITIVE_INFINITY) {
827
- return fn;
828
- }
829
- const { setTimeout, clearTimeout } = getSafeTimers();
830
- return (function runWithTimeout(...args) {
831
- const startTime = now$2();
832
- const runner2 = getRunner();
833
- runner2._currentTaskStartTime = startTime;
834
- runner2._currentTaskTimeout = timeout;
835
- return new Promise((resolve_, reject_) => {
836
- var _timer$unref;
837
- const timer = setTimeout(() => {
838
- clearTimeout(timer);
839
- rejectTimeoutError();
840
- }, timeout);
841
- (_timer$unref = timer.unref) === null || _timer$unref === void 0 ? void 0 : _timer$unref.call(timer);
842
- function rejectTimeoutError() {
843
- const error = makeTimeoutError(isHook, timeout, stackTraceError);
844
- onTimeout === null || onTimeout === void 0 ? void 0 : onTimeout(args, error);
845
- reject_(error);
846
- }
847
- function resolve(result) {
848
- runner2._currentTaskStartTime = void 0;
849
- runner2._currentTaskTimeout = void 0;
850
- clearTimeout(timer);
851
- if (now$2() - startTime >= timeout) {
852
- rejectTimeoutError();
853
- return;
854
- }
855
- resolve_(result);
856
- }
857
- function reject(error) {
858
- runner2._currentTaskStartTime = void 0;
859
- runner2._currentTaskTimeout = void 0;
860
- clearTimeout(timer);
861
- reject_(error);
862
- }
863
- try {
864
- const result = fn(...args);
865
- if (typeof result === "object" && result != null && typeof result.then === "function") {
866
- result.then(resolve, reject);
867
- } else {
868
- resolve(result);
869
- }
870
- } catch (error) {
871
- reject(error);
872
- }
873
- });
874
- });
875
- }
876
- const abortControllers = /* @__PURE__ */ new WeakMap();
877
- function abortIfTimeout([context], error) {
878
- if (context) {
879
- abortContextSignal(context, error);
880
- }
881
- }
882
- function abortContextSignal(context, error) {
883
- const abortController = abortControllers.get(context);
884
- abortController === null || abortController === void 0 ? void 0 : abortController.abort(error);
885
- }
886
- function createTestContext(test, runner2) {
887
- var _runner$extendTaskCon;
888
- const context = function() {
889
- throw new Error("done() callback is deprecated, use promise instead");
890
- };
891
- let abortController = abortControllers.get(context);
892
- if (!abortController) {
893
- abortController = new AbortController();
894
- abortControllers.set(context, abortController);
895
- }
896
- context.signal = abortController.signal;
897
- context.task = test;
898
- context.skip = (condition, note) => {
899
- if (condition === false) {
900
- return void 0;
901
- }
902
- test.result ?? (test.result = { state: "skip" });
903
- test.result.pending = true;
904
- throw new PendingError("test is skipped; abort execution", test, typeof condition === "string" ? condition : note);
905
- };
906
- context.annotate = ((message, type, attachment) => {
907
- if (test.result && test.result.state !== "run") {
908
- throw new Error(`Cannot annotate tests outside of the test run. The test "${test.name}" finished running with the "${test.result.state}" state already.`);
909
- }
910
- const annotation = {
911
- message,
912
- type: typeof type === "object" || type === void 0 ? "notice" : type
913
- };
914
- const annotationAttachment = typeof type === "object" ? type : attachment;
915
- if (annotationAttachment) {
916
- annotation.attachment = annotationAttachment;
917
- manageArtifactAttachment(annotation.attachment);
918
- }
919
- return recordAsyncOperation(test, recordArtifact(test, {
920
- type: "internal:annotation",
921
- annotation
922
- }).then(async ({ annotation: annotation2 }) => {
923
- if (!runner2.onTestAnnotate) {
924
- throw new Error(`Test runner doesn't support test annotations.`);
925
- }
926
- await finishSendTasksUpdate(runner2);
927
- const resolvedAnnotation = await runner2.onTestAnnotate(test, annotation2);
928
- test.annotations.push(resolvedAnnotation);
929
- return resolvedAnnotation;
930
- }));
931
- });
932
- context.onTestFailed = (handler, timeout) => {
933
- test.onFailed || (test.onFailed = []);
934
- test.onFailed.push(withTimeout(handler, timeout ?? runner2.config.hookTimeout, true, new Error("STACK_TRACE_ERROR"), (_, error) => abortController.abort(error)));
935
- };
936
- context.onTestFinished = (handler, timeout) => {
937
- test.onFinished || (test.onFinished = []);
938
- test.onFinished.push(withTimeout(handler, timeout ?? runner2.config.hookTimeout, true, new Error("STACK_TRACE_ERROR"), (_, error) => abortController.abort(error)));
939
- };
940
- return ((_runner$extendTaskCon = runner2.extendTaskContext) === null || _runner$extendTaskCon === void 0 ? void 0 : _runner$extendTaskCon.call(runner2, context)) || context;
941
- }
942
- function makeTimeoutError(isHook, timeout, stackTraceError) {
943
- const message = `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
944
- If this is a long-running ${isHook ? "hook" : "test"}, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
945
- const error = new Error(message);
946
- if (stackTraceError === null || stackTraceError === void 0 ? void 0 : stackTraceError.stack) {
947
- error.stack = stackTraceError.stack.replace(error.message, stackTraceError.message);
948
- }
949
- return error;
950
- }
951
- const fileContexts = /* @__PURE__ */ new WeakMap();
952
- function getFileContext(file) {
953
- const context = fileContexts.get(file);
954
- if (!context) {
955
- throw new Error(`Cannot find file context for ${file.name}`);
956
- }
957
- return context;
958
- }
959
- globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
960
- globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
961
- getSafeTimers();
962
- const packs = /* @__PURE__ */ new Map();
963
- const eventsPacks = [];
964
- const pendingTasksUpdates = [];
965
- function sendTasksUpdate(runner2) {
966
- if (packs.size) {
967
- var _runner$onTaskUpdate;
968
- const taskPacks = Array.from(packs).map(([id, task]) => {
969
- return [
970
- id,
971
- task[0],
972
- task[1]
973
- ];
974
- });
975
- const p = (_runner$onTaskUpdate = runner2.onTaskUpdate) === null || _runner$onTaskUpdate === void 0 ? void 0 : _runner$onTaskUpdate.call(runner2, taskPacks, eventsPacks);
976
- if (p) {
977
- pendingTasksUpdates.push(p);
978
- p.then(() => pendingTasksUpdates.splice(pendingTasksUpdates.indexOf(p), 1), () => {
979
- });
980
- }
981
- eventsPacks.length = 0;
982
- packs.clear();
983
- }
984
- }
985
- async function finishSendTasksUpdate(runner2) {
986
- sendTasksUpdate(runner2);
987
- await Promise.all(pendingTasksUpdates);
988
- }
989
- async function recordArtifact(task, artifact) {
990
- const runner2 = getRunner();
991
- if (task.result && task.result.state !== "run") {
992
- throw new Error(`Cannot record a test artifact outside of the test run. The test "${task.name}" finished running with the "${task.result.state}" state already.`);
993
- }
994
- const stack = findTestFileStackTrace(task.file.filepath, new Error("STACK_TRACE").stack);
995
- if (stack) {
996
- artifact.location = {
997
- file: stack.file,
998
- line: stack.line,
999
- column: stack.column
1000
- };
1001
- if (artifact.type === "internal:annotation") {
1002
- artifact.annotation.location = artifact.location;
1003
- }
1004
- }
1005
- if (Array.isArray(artifact.attachments)) {
1006
- for (const attachment of artifact.attachments) {
1007
- manageArtifactAttachment(attachment);
1008
- }
1009
- }
1010
- if (artifact.type === "internal:annotation") {
1011
- return artifact;
1012
- }
1013
- if (!runner2.onTestArtifactRecord) {
1014
- throw new Error(`Test runner doesn't support test artifacts.`);
1015
- }
1016
- await finishSendTasksUpdate(runner2);
1017
- const resolvedArtifact = await runner2.onTestArtifactRecord(task, artifact);
1018
- task.artifacts.push(resolvedArtifact);
1019
- return resolvedArtifact;
1020
- }
1021
- const table = [];
1022
- for (let i = 65; i < 91; i++) {
1023
- table.push(String.fromCharCode(i));
1024
- }
1025
- for (let i = 97; i < 123; i++) {
1026
- table.push(String.fromCharCode(i));
1027
- }
1028
- for (let i = 0; i < 10; i++) {
1029
- table.push(i.toString(10));
1030
- }
1031
- table.push("+", "/");
1032
- function encodeUint8Array(bytes) {
1033
- let base64 = "";
1034
- const len = bytes.byteLength;
1035
- for (let i = 0; i < len; i += 3) {
1036
- if (len === i + 1) {
1037
- const a = (bytes[i] & 252) >> 2;
1038
- const b = (bytes[i] & 3) << 4;
1039
- base64 += table[a];
1040
- base64 += table[b];
1041
- base64 += "==";
1042
- } else if (len === i + 2) {
1043
- const a = (bytes[i] & 252) >> 2;
1044
- const b = (bytes[i] & 3) << 4 | (bytes[i + 1] & 240) >> 4;
1045
- const c = (bytes[i + 1] & 15) << 2;
1046
- base64 += table[a];
1047
- base64 += table[b];
1048
- base64 += table[c];
1049
- base64 += "=";
1050
- } else {
1051
- const a = (bytes[i] & 252) >> 2;
1052
- const b = (bytes[i] & 3) << 4 | (bytes[i + 1] & 240) >> 4;
1053
- const c = (bytes[i + 1] & 15) << 2 | (bytes[i + 2] & 192) >> 6;
1054
- const d = bytes[i + 2] & 63;
1055
- base64 += table[a];
1056
- base64 += table[b];
1057
- base64 += table[c];
1058
- base64 += table[d];
1059
- }
1060
- }
1061
- return base64;
1062
- }
1063
- function recordAsyncOperation(test, promise) {
1064
- promise = promise.finally(() => {
1065
- if (!test.promises) {
1066
- return;
1067
- }
1068
- const index = test.promises.indexOf(promise);
1069
- if (index !== -1) {
1070
- test.promises.splice(index, 1);
1071
- }
1072
- });
1073
- if (!test.promises) {
1074
- test.promises = [];
1075
- }
1076
- test.promises.push(promise);
1077
- return promise;
1078
- }
1079
- function manageArtifactAttachment(attachment) {
1080
- if (attachment.body == null && !attachment.path) {
1081
- throw new TypeError(`Test attachment requires "body" or "path" to be set. Both are missing.`);
1082
- }
1083
- if (attachment.body && attachment.path) {
1084
- throw new TypeError(`Test attachment requires only one of "body" or "path" to be set. Both are specified.`);
1085
- }
1086
- if (attachment.body instanceof Uint8Array) {
1087
- attachment.body = encodeUint8Array(attachment.body);
1088
- }
1089
- }
1090
- export {
1091
- afterAll,
1092
- afterEach,
1093
- beforeAll,
1094
- beforeEach,
1095
- createTaskCollector,
1096
- getCurrentSuite,
1097
- getHooks,
1098
- recordArtifact,
1099
- setFn,
1100
- setHooks,
1101
- suite
1102
- };