@noma.to/qwik-testing-library 1.3.1 → 1.4.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.
Files changed (97) hide show
  1. package/README.md +18 -5
  2. package/lib/index.qwik.cjs +0 -4
  3. package/lib/index.qwik.mjs +0 -4
  4. package/lib/lib/qwik-testing-library.qwik.cjs +18 -6
  5. package/lib/lib/qwik-testing-library.qwik.mjs +18 -6
  6. package/lib-types/lib/qwik-testing-library.d.ts +1 -2
  7. package/package.json +9 -9
  8. package/lib/lib/mock.qwik.cjs +0 -14
  9. package/lib/lib/mock.qwik.mjs +0 -14
  10. package/lib/lib/qwikloader.qwik.cjs +0 -252
  11. package/lib/lib/qwikloader.qwik.mjs +0 -252
  12. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.qwik.cjs +0 -89
  13. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.qwik.mjs +0 -89
  14. package/lib/node_modules/.pnpm/@vitest_expect@3.0.5/node_modules/@vitest/expect/dist/index.qwik.cjs +0 -2191
  15. package/lib/node_modules/.pnpm/@vitest_expect@3.0.5/node_modules/@vitest/expect/dist/index.qwik.mjs +0 -2191
  16. package/lib/node_modules/.pnpm/@vitest_pretty-format@3.0.5/node_modules/@vitest/pretty-format/dist/index.qwik.cjs +0 -1499
  17. package/lib/node_modules/.pnpm/@vitest_pretty-format@3.0.5/node_modules/@vitest/pretty-format/dist/index.qwik.mjs +0 -1499
  18. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/chunk-tasks.qwik.cjs +0 -44
  19. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/chunk-tasks.qwik.mjs +0 -44
  20. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/index.qwik.cjs +0 -757
  21. package/lib/node_modules/.pnpm/@vitest_runner@3.0.5/node_modules/@vitest/runner/dist/index.qwik.mjs +0 -757
  22. package/lib/node_modules/.pnpm/@vitest_snapshot@3.0.5/node_modules/@vitest/snapshot/dist/index.qwik.cjs +0 -2079
  23. package/lib/node_modules/.pnpm/@vitest_snapshot@3.0.5/node_modules/@vitest/snapshot/dist/index.qwik.mjs +0 -2079
  24. package/lib/node_modules/.pnpm/@vitest_spy@3.0.5/node_modules/@vitest/spy/dist/index.qwik.cjs +0 -165
  25. package/lib/node_modules/.pnpm/@vitest_spy@3.0.5/node_modules/@vitest/spy/dist/index.qwik.mjs +0 -165
  26. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.qwik.cjs +0 -162
  27. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.qwik.mjs +0 -162
  28. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/diff.qwik.cjs +0 -1755
  29. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/diff.qwik.mjs +0 -1755
  30. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/error.qwik.cjs +0 -137
  31. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/error.qwik.mjs +0 -137
  32. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/helpers.qwik.cjs +0 -150
  33. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/helpers.qwik.mjs +0 -150
  34. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/index.qwik.cjs +0 -474
  35. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/index.qwik.mjs +0 -474
  36. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/source-map.qwik.cjs +0 -216
  37. package/lib/node_modules/.pnpm/@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/source-map.qwik.mjs +0 -216
  38. package/lib/node_modules/.pnpm/chai@5.1.2/node_modules/chai/chai.qwik.cjs +0 -3937
  39. package/lib/node_modules/.pnpm/chai@5.1.2/node_modules/chai/chai.qwik.mjs +0 -3937
  40. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/arguments.qwik.cjs +0 -9
  41. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/arguments.qwik.mjs +0 -10
  42. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/array.qwik.cjs +0 -16
  43. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/array.qwik.mjs +0 -17
  44. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/bigint.qwik.cjs +0 -9
  45. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/bigint.qwik.mjs +0 -10
  46. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/class.qwik.cjs +0 -16
  47. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/class.qwik.mjs +0 -17
  48. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/date.qwik.cjs +0 -12
  49. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/date.qwik.mjs +0 -13
  50. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/error.qwik.cjs +0 -36
  51. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/error.qwik.mjs +0 -37
  52. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/function.qwik.cjs +0 -11
  53. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/function.qwik.mjs +0 -12
  54. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/helpers.qwik.cjs +0 -160
  55. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/helpers.qwik.mjs +0 -160
  56. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/html.qwik.cjs +0 -36
  57. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/html.qwik.mjs +0 -36
  58. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/index.qwik.cjs +0 -130
  59. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/index.qwik.mjs +0 -130
  60. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/map.qwik.cjs +0 -23
  61. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/map.qwik.mjs +0 -24
  62. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/number.qwik.cjs +0 -19
  63. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/number.qwik.mjs +0 -20
  64. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/object.qwik.cjs +0 -24
  65. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/object.qwik.mjs +0 -25
  66. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/promise.qwik.cjs +0 -17
  67. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/promise.qwik.mjs +0 -18
  68. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/regexp.qwik.cjs +0 -9
  69. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/regexp.qwik.mjs +0 -10
  70. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/set.qwik.cjs +0 -16
  71. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/set.qwik.mjs +0 -17
  72. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/string.qwik.cjs +0 -23
  73. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/string.qwik.mjs +0 -24
  74. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/symbol.qwik.cjs +0 -8
  75. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/symbol.qwik.mjs +0 -9
  76. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/typedarray.qwik.cjs +0 -34
  77. package/lib/node_modules/.pnpm/loupe@3.1.3/node_modules/loupe/lib/typedarray.qwik.mjs +0 -35
  78. package/lib/node_modules/.pnpm/magic-string@0.30.17/node_modules/magic-string/dist/magic-string.es.qwik.cjs +0 -979
  79. package/lib/node_modules/.pnpm/magic-string@0.30.17/node_modules/magic-string/dist/magic-string.es.qwik.mjs +0 -979
  80. package/lib/node_modules/.pnpm/pathe@2.0.2/node_modules/pathe/dist/shared/pathe.UZ-hd4nF.qwik.cjs +0 -101
  81. package/lib/node_modules/.pnpm/pathe@2.0.2/node_modules/pathe/dist/shared/pathe.UZ-hd4nF.qwik.mjs +0 -101
  82. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/browser.qwik.cjs +0 -4
  83. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/browser.qwik.mjs +0 -5
  84. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.cjs +0 -80
  85. package/lib/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.qwik.mjs +0 -80
  86. package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.cjs +0 -104
  87. package/lib/node_modules/.pnpm/tinyspy@3.0.2/node_modules/tinyspy/dist/index.qwik.mjs +0 -104
  88. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.cjs +0 -8
  89. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.qwik.mjs +0 -8
  90. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.cjs +0 -56
  91. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/date.W2xKR2qe.qwik.mjs +0 -56
  92. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/utils.C8RiOc4B.qwik.cjs +0 -66
  93. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/utils.C8RiOc4B.qwik.mjs +0 -66
  94. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.CjhMlMwf.qwik.cjs +0 -2977
  95. package/lib/node_modules/.pnpm/vitest@3.0.5_@types_node@22.13.1_@vitest_ui@3.0.5_jiti@2.4.2_jsdom@26.0.0/node_modules/vitest/dist/chunks/vi.CjhMlMwf.qwik.mjs +0 -2977
  96. package/lib-types/lib/mock.d.ts +0 -34
  97. package/lib-types/lib/qwikloader.d.ts +0 -1
@@ -1,757 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
- const index = require("../../../../../@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/index.qwik.cjs");
7
- const sourceMap = require("../../../../../@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/source-map.qwik.cjs");
8
- const chunkTasks = require("./chunk-tasks.qwik.cjs");
9
- const helpers = require("../../../../../@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/helpers.qwik.cjs");
10
- const chunk_commonjsHelpers = require("../../../../../@vitest_utils@3.0.5/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.qwik.cjs");
11
- class PendingError extends Error {
12
- constructor(message, task, note) {
13
- super(message);
14
- __publicField(this, "code", "VITEST_PENDING");
15
- __publicField(this, "taskId");
16
- this.message = message;
17
- this.note = note;
18
- this.taskId = task.id;
19
- }
20
- }
21
- const now$2 = Date.now;
22
- const collectorContext = {
23
- currentSuite: null
24
- };
25
- function collectTask(task) {
26
- var _a;
27
- (_a = collectorContext.currentSuite) == null ? void 0 : _a.tasks.push(task);
28
- }
29
- async function runWithSuite(suite2, fn) {
30
- const prev = collectorContext.currentSuite;
31
- collectorContext.currentSuite = suite2;
32
- await fn();
33
- collectorContext.currentSuite = prev;
34
- }
35
- function withTimeout(fn, timeout, isHook = false) {
36
- if (timeout <= 0 || timeout === Number.POSITIVE_INFINITY) {
37
- return fn;
38
- }
39
- const { setTimeout, clearTimeout } = index.getSafeTimers();
40
- return function runWithTimeout(...args) {
41
- const startTime = now$2();
42
- return new Promise((resolve_, reject_) => {
43
- var _a;
44
- const timer = setTimeout(() => {
45
- clearTimeout(timer);
46
- reject(new Error(makeTimeoutMsg(isHook, timeout)));
47
- }, timeout);
48
- (_a = timer.unref) == null ? void 0 : _a.call(timer);
49
- function resolve(result) {
50
- clearTimeout(timer);
51
- if (now$2() - startTime >= timeout) {
52
- reject_(new Error(makeTimeoutMsg(isHook, timeout)));
53
- return;
54
- }
55
- resolve_(result);
56
- }
57
- function reject(error) {
58
- clearTimeout(timer);
59
- reject_(error);
60
- }
61
- try {
62
- const result = fn(...args);
63
- if (typeof result === "object" && result != null && typeof result.then === "function") {
64
- result.then(resolve, reject);
65
- } else {
66
- resolve(result);
67
- }
68
- } catch (error) {
69
- reject(error);
70
- }
71
- });
72
- };
73
- }
74
- function createTestContext(test, runner2) {
75
- var _a;
76
- const context = function() {
77
- throw new Error("done() callback is deprecated, use promise instead");
78
- };
79
- context.task = test;
80
- context.skip = (note) => {
81
- test.result ?? (test.result = { state: "skip" });
82
- test.result.pending = true;
83
- throw new PendingError("test is skipped; abort execution", test, note);
84
- };
85
- context.onTestFailed = (handler, timeout) => {
86
- test.onFailed || (test.onFailed = []);
87
- test.onFailed.push(
88
- withTimeout(handler, timeout ?? runner2.config.hookTimeout, true)
89
- );
90
- };
91
- context.onTestFinished = (handler, timeout) => {
92
- test.onFinished || (test.onFinished = []);
93
- test.onFinished.push(
94
- withTimeout(handler, timeout ?? runner2.config.hookTimeout, true)
95
- );
96
- };
97
- return ((_a = runner2.extendTaskContext) == null ? void 0 : _a.call(runner2, context)) || context;
98
- }
99
- function makeTimeoutMsg(isHook, timeout) {
100
- return `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
101
- 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"}".`;
102
- }
103
- const fnMap = /* @__PURE__ */ new WeakMap();
104
- const fixtureMap = /* @__PURE__ */ new WeakMap();
105
- const hooksMap = /* @__PURE__ */ new WeakMap();
106
- function setFn(key, fn) {
107
- fnMap.set(key, fn);
108
- }
109
- function setFixture(key, fixture) {
110
- fixtureMap.set(key, fixture);
111
- }
112
- function getFixture(key) {
113
- return fixtureMap.get(key);
114
- }
115
- function setHooks(key, hooks) {
116
- hooksMap.set(key, hooks);
117
- }
118
- function getHooks(key) {
119
- return hooksMap.get(key);
120
- }
121
- function mergeContextFixtures(fixtures, context, inject) {
122
- const fixtureOptionKeys = ["auto", "injected"];
123
- const fixtureArray = Object.entries(fixtures).map(
124
- ([prop, value]) => {
125
- const fixtureItem = { value };
126
- if (Array.isArray(value) && value.length >= 2 && helpers.isObject(value[1]) && Object.keys(value[1]).some((key) => fixtureOptionKeys.includes(key))) {
127
- Object.assign(fixtureItem, value[1]);
128
- const userValue = value[0];
129
- fixtureItem.value = fixtureItem.injected ? inject(prop) ?? userValue : userValue;
130
- }
131
- fixtureItem.prop = prop;
132
- fixtureItem.isFn = typeof fixtureItem.value === "function";
133
- return fixtureItem;
134
- }
135
- );
136
- if (Array.isArray(context.fixtures)) {
137
- context.fixtures = context.fixtures.concat(fixtureArray);
138
- } else {
139
- context.fixtures = fixtureArray;
140
- }
141
- fixtureArray.forEach((fixture) => {
142
- if (fixture.isFn) {
143
- const usedProps = getUsedProps(fixture.value);
144
- if (usedProps.length) {
145
- fixture.deps = context.fixtures.filter(
146
- ({ prop }) => prop !== fixture.prop && usedProps.includes(prop)
147
- );
148
- }
149
- }
150
- });
151
- return context;
152
- }
153
- const fixtureValueMaps = /* @__PURE__ */ new Map();
154
- const cleanupFnArrayMap = /* @__PURE__ */ new Map();
155
- function withFixtures(fn, testContext) {
156
- return (hookContext) => {
157
- const context = hookContext || testContext;
158
- if (!context) {
159
- return fn({});
160
- }
161
- const fixtures = getFixture(context);
162
- if (!(fixtures == null ? void 0 : fixtures.length)) {
163
- return fn(context);
164
- }
165
- const usedProps = getUsedProps(fn);
166
- const hasAutoFixture = fixtures.some(({ auto }) => auto);
167
- if (!usedProps.length && !hasAutoFixture) {
168
- return fn(context);
169
- }
170
- if (!fixtureValueMaps.get(context)) {
171
- fixtureValueMaps.set(context, /* @__PURE__ */ new Map());
172
- }
173
- const fixtureValueMap = fixtureValueMaps.get(context);
174
- if (!cleanupFnArrayMap.has(context)) {
175
- cleanupFnArrayMap.set(context, []);
176
- }
177
- const cleanupFnArray = cleanupFnArrayMap.get(context);
178
- const usedFixtures = fixtures.filter(
179
- ({ prop, auto }) => auto || usedProps.includes(prop)
180
- );
181
- const pendingFixtures = resolveDeps(usedFixtures);
182
- if (!pendingFixtures.length) {
183
- return fn(context);
184
- }
185
- async function resolveFixtures() {
186
- for (const fixture of pendingFixtures) {
187
- if (fixtureValueMap.has(fixture)) {
188
- continue;
189
- }
190
- const resolvedValue = fixture.isFn ? await resolveFixtureFunction(fixture.value, context, cleanupFnArray) : fixture.value;
191
- context[fixture.prop] = resolvedValue;
192
- fixtureValueMap.set(fixture, resolvedValue);
193
- cleanupFnArray.unshift(() => {
194
- fixtureValueMap.delete(fixture);
195
- });
196
- }
197
- }
198
- return resolveFixtures().then(() => fn(context));
199
- };
200
- }
201
- async function resolveFixtureFunction(fixtureFn, context, cleanupFnArray) {
202
- const useFnArgPromise = helpers.createDefer();
203
- let isUseFnArgResolved = false;
204
- const fixtureReturn = fixtureFn(context, async (useFnArg) => {
205
- isUseFnArgResolved = true;
206
- useFnArgPromise.resolve(useFnArg);
207
- const useReturnPromise = helpers.createDefer();
208
- cleanupFnArray.push(async () => {
209
- useReturnPromise.resolve();
210
- await fixtureReturn;
211
- });
212
- await useReturnPromise;
213
- }).catch((e) => {
214
- if (!isUseFnArgResolved) {
215
- useFnArgPromise.reject(e);
216
- return;
217
- }
218
- throw e;
219
- });
220
- return useFnArgPromise;
221
- }
222
- function resolveDeps(fixtures, depSet = /* @__PURE__ */ new Set(), pendingFixtures = []) {
223
- fixtures.forEach((fixture) => {
224
- if (pendingFixtures.includes(fixture)) {
225
- return;
226
- }
227
- if (!fixture.isFn || !fixture.deps) {
228
- pendingFixtures.push(fixture);
229
- return;
230
- }
231
- if (depSet.has(fixture)) {
232
- throw new Error(
233
- `Circular fixture dependency detected: ${fixture.prop} <- ${[...depSet].reverse().map((d) => d.prop).join(" <- ")}`
234
- );
235
- }
236
- depSet.add(fixture);
237
- resolveDeps(fixture.deps, depSet, pendingFixtures);
238
- pendingFixtures.push(fixture);
239
- depSet.clear();
240
- });
241
- return pendingFixtures;
242
- }
243
- function getUsedProps(fn) {
244
- let fnString = fn.toString();
245
- if (/__async\(this, (?:null|arguments|\[[_0-9, ]*\]), function\*/.test(fnString)) {
246
- fnString = fnString.split("__async(this,")[1];
247
- }
248
- const match = fnString.match(/[^(]*\(([^)]*)/);
249
- if (!match) {
250
- return [];
251
- }
252
- const args = splitByComma(match[1]);
253
- if (!args.length) {
254
- return [];
255
- }
256
- let first = args[0];
257
- if ("__VITEST_FIXTURE_INDEX__" in fn) {
258
- first = args[fn.__VITEST_FIXTURE_INDEX__];
259
- if (!first) {
260
- return [];
261
- }
262
- }
263
- if (!(first.startsWith("{") && first.endsWith("}"))) {
264
- throw new Error(
265
- `The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "${first}".`
266
- );
267
- }
268
- const _first = first.slice(1, -1).replace(/\s/g, "");
269
- const props = splitByComma(_first).map((prop) => {
270
- return prop.replace(/:.*|=.*/g, "");
271
- });
272
- const last = props.at(-1);
273
- if (last && last.startsWith("...")) {
274
- throw new Error(
275
- `Rest parameters are not supported in fixtures, received "${last}".`
276
- );
277
- }
278
- return props;
279
- }
280
- function splitByComma(s) {
281
- const result = [];
282
- const stack = [];
283
- let start = 0;
284
- for (let i = 0; i < s.length; i++) {
285
- if (s[i] === "{" || s[i] === "[") {
286
- stack.push(s[i] === "{" ? "}" : "]");
287
- } else if (s[i] === stack[stack.length - 1]) {
288
- stack.pop();
289
- } else if (!stack.length && s[i] === ",") {
290
- const token = s.substring(start, i).trim();
291
- if (token) {
292
- result.push(token);
293
- }
294
- start = i + 1;
295
- }
296
- }
297
- const lastToken = s.substring(start).trim();
298
- if (lastToken) {
299
- result.push(lastToken);
300
- }
301
- return result;
302
- }
303
- const suite = createSuite();
304
- createTest(function(name, optionsOrFn, optionsOrTest) {
305
- getCurrentSuite().test.fn.call(
306
- this,
307
- formatName(name),
308
- optionsOrFn,
309
- optionsOrTest
310
- );
311
- });
312
- let runner;
313
- let defaultSuite;
314
- let currentTestFilepath;
315
- function assert(condition, message) {
316
- if (!condition) {
317
- throw new Error(`Vitest failed to find ${message}. This is a bug in Vitest. Please, open an issue with reproduction.`);
318
- }
319
- }
320
- function getTestFilepath() {
321
- return currentTestFilepath;
322
- }
323
- function getRunner() {
324
- assert(runner, "the runner");
325
- return runner;
326
- }
327
- function getCurrentSuite() {
328
- const currentSuite = collectorContext.currentSuite || defaultSuite;
329
- assert(currentSuite, "the current suite");
330
- return currentSuite;
331
- }
332
- function createSuiteHooks() {
333
- return {
334
- beforeAll: [],
335
- afterAll: [],
336
- beforeEach: [],
337
- afterEach: []
338
- };
339
- }
340
- function parseArguments(optionsOrFn, optionsOrTest) {
341
- let options = {};
342
- let fn = () => {
343
- };
344
- if (typeof optionsOrTest === "object") {
345
- if (typeof optionsOrFn === "object") {
346
- throw new TypeError(
347
- "Cannot use two objects as arguments. Please provide options and a function callback in that order."
348
- );
349
- }
350
- console.warn(
351
- "Using an object as a third argument is deprecated. Vitest 4 will throw an error if the third argument is not a timeout number. Please use the second argument for options. See more at https://vitest.dev/guide/migration"
352
- );
353
- options = optionsOrTest;
354
- } else if (typeof optionsOrTest === "number") {
355
- options = { timeout: optionsOrTest };
356
- } else if (typeof optionsOrFn === "object") {
357
- options = optionsOrFn;
358
- }
359
- if (typeof optionsOrFn === "function") {
360
- if (typeof optionsOrTest === "function") {
361
- throw new TypeError(
362
- "Cannot use two functions as arguments. Please use the second argument for options."
363
- );
364
- }
365
- fn = optionsOrFn;
366
- } else if (typeof optionsOrTest === "function") {
367
- fn = optionsOrTest;
368
- }
369
- return {
370
- options,
371
- handler: fn
372
- };
373
- }
374
- function createSuiteCollector(name, factory = () => {
375
- }, mode, each, suiteOptions) {
376
- const tasks = [];
377
- const factoryQueue = [];
378
- let suite2;
379
- initSuite();
380
- const task = function(name2 = "", options = {}) {
381
- const task2 = {
382
- id: "",
383
- name: name2,
384
- suite: void 0,
385
- each: options.each,
386
- fails: options.fails,
387
- context: void 0,
388
- type: "test",
389
- file: void 0,
390
- retry: options.retry ?? runner.config.retry,
391
- repeats: options.repeats,
392
- mode: options.only ? "only" : options.skip ? "skip" : options.todo ? "todo" : "run",
393
- meta: options.meta ?? /* @__PURE__ */ Object.create(null)
394
- };
395
- const handler = options.handler;
396
- if (options.concurrent || !options.sequential && runner.config.sequence.concurrent) {
397
- task2.concurrent = true;
398
- }
399
- task2.shuffle = suiteOptions == null ? void 0 : suiteOptions.shuffle;
400
- const context = createTestContext(task2, runner);
401
- Object.defineProperty(task2, "context", {
402
- value: context,
403
- enumerable: false
404
- });
405
- setFixture(context, options.fixtures);
406
- if (handler) {
407
- setFn(
408
- task2,
409
- withTimeout(
410
- withAwaitAsyncAssertions(withFixtures(handler, context), task2),
411
- (options == null ? void 0 : options.timeout) ?? runner.config.testTimeout
412
- )
413
- );
414
- }
415
- if (runner.config.includeTaskLocation) {
416
- const limit = Error.stackTraceLimit;
417
- Error.stackTraceLimit = 15;
418
- const error = new Error("stacktrace").stack;
419
- Error.stackTraceLimit = limit;
420
- const stack = findTestFileStackTrace(error, task2.each ?? false);
421
- if (stack) {
422
- task2.location = stack;
423
- }
424
- }
425
- tasks.push(task2);
426
- return task2;
427
- };
428
- const test2 = createTest(function(name2, optionsOrFn, optionsOrTest) {
429
- let { options, handler } = parseArguments(optionsOrFn, optionsOrTest);
430
- if (typeof suiteOptions === "object") {
431
- options = Object.assign({}, suiteOptions, options);
432
- }
433
- options.concurrent = this.concurrent || !this.sequential && (options == null ? void 0 : options.concurrent);
434
- options.sequential = this.sequential || !this.concurrent && (options == null ? void 0 : options.sequential);
435
- const test3 = task(formatName(name2), {
436
- ...this,
437
- ...options,
438
- handler
439
- });
440
- test3.type = "test";
441
- });
442
- const collector = {
443
- type: "collector",
444
- name,
445
- mode,
446
- options: suiteOptions,
447
- test: test2,
448
- tasks,
449
- collect,
450
- task,
451
- clear,
452
- on: addHook
453
- };
454
- function addHook(name2, ...fn) {
455
- getHooks(suite2)[name2].push(...fn);
456
- }
457
- function initSuite(includeLocation) {
458
- if (typeof suiteOptions === "number") {
459
- suiteOptions = { timeout: suiteOptions };
460
- }
461
- suite2 = {
462
- id: "",
463
- type: "suite",
464
- name,
465
- mode,
466
- each,
467
- file: void 0,
468
- shuffle: suiteOptions == null ? void 0 : suiteOptions.shuffle,
469
- tasks: [],
470
- meta: /* @__PURE__ */ Object.create(null),
471
- concurrent: suiteOptions == null ? void 0 : suiteOptions.concurrent
472
- };
473
- setHooks(suite2, createSuiteHooks());
474
- }
475
- function clear() {
476
- tasks.length = 0;
477
- factoryQueue.length = 0;
478
- initSuite();
479
- }
480
- async function collect(file) {
481
- if (!file) {
482
- throw new TypeError("File is required to collect tasks.");
483
- }
484
- factoryQueue.length = 0;
485
- if (factory) {
486
- await runWithSuite(collector, () => factory(test2));
487
- }
488
- const allChildren = [];
489
- for (const i of [...factoryQueue, ...tasks]) {
490
- allChildren.push(i.type === "collector" ? await i.collect(file) : i);
491
- }
492
- suite2.file = file;
493
- suite2.tasks = allChildren;
494
- allChildren.forEach((task2) => {
495
- task2.suite = suite2;
496
- task2.file = file;
497
- });
498
- return suite2;
499
- }
500
- collectTask(collector);
501
- return collector;
502
- }
503
- function withAwaitAsyncAssertions(fn, task) {
504
- return async (...args) => {
505
- const fnResult = await fn(...args);
506
- if (task.promises) {
507
- const result = await Promise.allSettled(task.promises);
508
- const errors = result.map((r) => r.status === "rejected" ? r.reason : void 0).filter(Boolean);
509
- if (errors.length) {
510
- throw errors;
511
- }
512
- }
513
- return fnResult;
514
- };
515
- }
516
- function createSuite() {
517
- function suiteFn(name, factoryOrOptions, optionsOrFactory) {
518
- var _a;
519
- const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
520
- const currentSuite = collectorContext.currentSuite || defaultSuite;
521
- let { options, handler: factory } = parseArguments(
522
- factoryOrOptions,
523
- optionsOrFactory
524
- );
525
- const isConcurrentSpecified = options.concurrent || this.concurrent || options.sequential === false;
526
- const isSequentialSpecified = options.sequential || this.sequential || options.concurrent === false;
527
- options = {
528
- ...currentSuite == null ? void 0 : currentSuite.options,
529
- ...options,
530
- shuffle: this.shuffle ?? options.shuffle ?? ((_a = currentSuite == null ? void 0 : currentSuite.options) == null ? void 0 : _a.shuffle) ?? void 0
531
- };
532
- const isConcurrent = isConcurrentSpecified || options.concurrent && !isSequentialSpecified;
533
- const isSequential = isSequentialSpecified || options.sequential && !isConcurrentSpecified;
534
- options.concurrent = isConcurrent && !isSequential;
535
- options.sequential = isSequential && !isConcurrent;
536
- return createSuiteCollector(
537
- formatName(name),
538
- factory,
539
- mode,
540
- this.each,
541
- options
542
- );
543
- }
544
- suiteFn.each = function(cases, ...args) {
545
- const suite2 = this.withContext();
546
- this.setContext("each", true);
547
- if (Array.isArray(cases) && args.length) {
548
- cases = formatTemplateString(cases, args);
549
- }
550
- return (name, optionsOrFn, fnOrOptions) => {
551
- const _name = formatName(name);
552
- const arrayOnlyCases = cases.every(Array.isArray);
553
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
554
- const fnFirst = typeof optionsOrFn === "function" && typeof fnOrOptions === "object";
555
- cases.forEach((i, idx) => {
556
- const items = Array.isArray(i) ? i : [i];
557
- if (fnFirst) {
558
- if (arrayOnlyCases) {
559
- suite2(
560
- formatTitle(_name, items, idx),
561
- () => handler(...items),
562
- options
563
- );
564
- } else {
565
- suite2(formatTitle(_name, items, idx), () => handler(i), options);
566
- }
567
- } else {
568
- if (arrayOnlyCases) {
569
- suite2(formatTitle(_name, items, idx), options, () => handler(...items));
570
- } else {
571
- suite2(formatTitle(_name, items, idx), options, () => handler(i));
572
- }
573
- }
574
- });
575
- this.setContext("each", void 0);
576
- };
577
- };
578
- suiteFn.for = function(cases, ...args) {
579
- if (Array.isArray(cases) && args.length) {
580
- cases = formatTemplateString(cases, args);
581
- }
582
- return (name, optionsOrFn, fnOrOptions) => {
583
- const name_ = formatName(name);
584
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
585
- cases.forEach((item, idx) => {
586
- suite(formatTitle(name_, helpers.toArray(item), idx), options, () => handler(item));
587
- });
588
- };
589
- };
590
- suiteFn.skipIf = (condition) => condition ? suite.skip : suite;
591
- suiteFn.runIf = (condition) => condition ? suite : suite.skip;
592
- return chunkTasks.c(
593
- ["concurrent", "sequential", "shuffle", "skip", "only", "todo"],
594
- suiteFn
595
- );
596
- }
597
- function createTaskCollector(fn, context) {
598
- const taskFn = fn;
599
- taskFn.each = function(cases, ...args) {
600
- const test2 = this.withContext();
601
- this.setContext("each", true);
602
- if (Array.isArray(cases) && args.length) {
603
- cases = formatTemplateString(cases, args);
604
- }
605
- return (name, optionsOrFn, fnOrOptions) => {
606
- const _name = formatName(name);
607
- const arrayOnlyCases = cases.every(Array.isArray);
608
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
609
- const fnFirst = typeof optionsOrFn === "function" && typeof fnOrOptions === "object";
610
- cases.forEach((i, idx) => {
611
- const items = Array.isArray(i) ? i : [i];
612
- if (fnFirst) {
613
- if (arrayOnlyCases) {
614
- test2(
615
- formatTitle(_name, items, idx),
616
- () => handler(...items),
617
- options
618
- );
619
- } else {
620
- test2(formatTitle(_name, items, idx), () => handler(i), options);
621
- }
622
- } else {
623
- if (arrayOnlyCases) {
624
- test2(formatTitle(_name, items, idx), options, () => handler(...items));
625
- } else {
626
- test2(formatTitle(_name, items, idx), options, () => handler(i));
627
- }
628
- }
629
- });
630
- this.setContext("each", void 0);
631
- };
632
- };
633
- taskFn.for = function(cases, ...args) {
634
- const test2 = this.withContext();
635
- if (Array.isArray(cases) && args.length) {
636
- cases = formatTemplateString(cases, args);
637
- }
638
- return (name, optionsOrFn, fnOrOptions) => {
639
- const _name = formatName(name);
640
- const { options, handler } = parseArguments(optionsOrFn, fnOrOptions);
641
- cases.forEach((item, idx) => {
642
- const handlerWrapper = (ctx) => handler(item, ctx);
643
- handlerWrapper.__VITEST_FIXTURE_INDEX__ = 1;
644
- handlerWrapper.toString = () => handler.toString();
645
- test2(formatTitle(_name, helpers.toArray(item), idx), options, handlerWrapper);
646
- });
647
- };
648
- };
649
- taskFn.skipIf = function(condition) {
650
- return condition ? this.skip : this;
651
- };
652
- taskFn.runIf = function(condition) {
653
- return condition ? this : this.skip;
654
- };
655
- taskFn.extend = function(fixtures) {
656
- const _context = mergeContextFixtures(
657
- fixtures,
658
- context || {},
659
- (key) => {
660
- var _a, _b;
661
- return (_b = (_a = getRunner()).injectValue) == null ? void 0 : _b.call(_a, key);
662
- }
663
- );
664
- return createTest(function fn2(name, optionsOrFn, optionsOrTest) {
665
- getCurrentSuite().test.fn.call(
666
- this,
667
- formatName(name),
668
- optionsOrFn,
669
- optionsOrTest
670
- );
671
- }, _context);
672
- };
673
- const _test = chunkTasks.c(
674
- ["concurrent", "sequential", "skip", "only", "todo", "fails"],
675
- taskFn
676
- );
677
- if (context) {
678
- _test.mergeContext(context);
679
- }
680
- return _test;
681
- }
682
- function createTest(fn, context) {
683
- return createTaskCollector(fn, context);
684
- }
685
- function formatName(name) {
686
- return typeof name === "string" ? name : name instanceof Function ? name.name || "<anonymous>" : String(name);
687
- }
688
- function formatTitle(template, items, idx) {
689
- if (template.includes("%#")) {
690
- template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/__vitest_escaped_%__/g, "%%");
691
- }
692
- const count = template.split("%").length - 1;
693
- if (template.includes("%f")) {
694
- const placeholders = template.match(/%f/g) || [];
695
- placeholders.forEach((_, i) => {
696
- if (helpers.isNegativeNaN(items[i]) || Object.is(items[i], -0)) {
697
- let occurrence = 0;
698
- template = template.replace(/%f/g, (match) => {
699
- occurrence++;
700
- return occurrence === i + 1 ? "-%f" : match;
701
- });
702
- }
703
- });
704
- }
705
- let formatted = chunk_commonjsHelpers.f(template, ...items.slice(0, count));
706
- if (helpers.isObject(items[0])) {
707
- formatted = formatted.replace(
708
- /\$([$\w.]+)/g,
709
- // https://github.com/chaijs/chai/pull/1490
710
- (_, key) => {
711
- var _a, _b;
712
- return chunk_commonjsHelpers.o(helpers.objectAttr(items[0], key), {
713
- truncate: (_b = (_a = void 0) == null ? void 0 : _a.chaiConfig) == null ? void 0 : _b.truncateThreshold
714
- });
715
- }
716
- );
717
- }
718
- return formatted;
719
- }
720
- function formatTemplateString(cases, args) {
721
- const header = cases.join("").trim().replace(/ /g, "").split("\n").map((i) => i.split("|"))[0];
722
- const res = [];
723
- for (let i = 0; i < Math.floor(args.length / header.length); i++) {
724
- const oneCase = {};
725
- for (let j = 0; j < header.length; j++) {
726
- oneCase[header[j]] = args[i * header.length + j];
727
- }
728
- res.push(oneCase);
729
- }
730
- return res;
731
- }
732
- function findTestFileStackTrace(error, each) {
733
- const lines = error.split("\n").slice(1);
734
- for (const line of lines) {
735
- const stack = sourceMap.parseSingleStack(line);
736
- if (stack && stack.file === getTestFilepath()) {
737
- return {
738
- line: stack.line,
739
- /**
740
- * test.each([1, 2])('name')
741
- * ^ leads here, but should
742
- * ^ lead here
743
- * in source maps it's the same boundary, so it just points to the start of it
744
- */
745
- column: each ? stack.column + 1 : stack.column
746
- };
747
- }
748
- }
749
- }
750
- globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
751
- globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
752
- exports.createTaskCollector = createTaskCollector;
753
- exports.getCurrentSuite = getCurrentSuite;
754
- exports.getHooks = getHooks;
755
- exports.setFn = setFn;
756
- exports.setHooks = setHooks;
757
- exports.suite = suite;