@noma.to/qwik-testing-library 1.3.0 → 1.3.2

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