@depup/vitest__runner 4.1.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/dist/chunk-tasks.js +608 -0
- package/dist/index.d.ts +179 -0
- package/dist/index.js +2805 -0
- package/dist/tasks.d-D2GKpdwQ.d.ts +1505 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +53 -0
- package/dist/utils.js +5 -0
- package/package.json +67 -0
- package/types.d.ts +1 -0
- package/utils.d.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-Present VoidZero Inc. and Vitest contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @depup/vitest__runner
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [@vitest/runner](https://www.npmjs.com/package/@vitest/runner)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/vitest__runner
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [@vitest/runner](https://www.npmjs.com/package/@vitest/runner) @ 4.1.0 |
|
|
17
|
+
| Processed | 2026-03-17 |
|
|
18
|
+
| Smoke test | passed |
|
|
19
|
+
| Deps updated | 0 |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/@vitest/runner
|
|
24
|
+
|
|
25
|
+
License inherited from the original package.
|
package/changes.json
ADDED
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
import { processError } from '@vitest/utils/error';
|
|
2
|
+
import { parseSingleStack } from '@vitest/utils/source-map';
|
|
3
|
+
import { relative } from 'pathe';
|
|
4
|
+
import { toArray } from '@vitest/utils/helpers';
|
|
5
|
+
|
|
6
|
+
const kChainableContext = Symbol("kChainableContext");
|
|
7
|
+
function getChainableContext(chainable) {
|
|
8
|
+
return chainable?.[kChainableContext];
|
|
9
|
+
}
|
|
10
|
+
function createChainable(keys, fn, context) {
|
|
11
|
+
function create(context) {
|
|
12
|
+
const chain = function(...args) {
|
|
13
|
+
return fn.apply(context, args);
|
|
14
|
+
};
|
|
15
|
+
Object.assign(chain, fn);
|
|
16
|
+
Object.defineProperty(chain, kChainableContext, {
|
|
17
|
+
value: {
|
|
18
|
+
withContext: () => chain.bind(context),
|
|
19
|
+
getFixtures: () => context.fixtures,
|
|
20
|
+
setContext: (key, value) => {
|
|
21
|
+
context[key] = value;
|
|
22
|
+
},
|
|
23
|
+
mergeContext: (ctx) => {
|
|
24
|
+
Object.assign(context, ctx);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
enumerable: false
|
|
28
|
+
});
|
|
29
|
+
for (const key of keys) {
|
|
30
|
+
Object.defineProperty(chain, key, { get() {
|
|
31
|
+
return create({
|
|
32
|
+
...context,
|
|
33
|
+
[key]: true
|
|
34
|
+
});
|
|
35
|
+
} });
|
|
36
|
+
}
|
|
37
|
+
return chain;
|
|
38
|
+
}
|
|
39
|
+
const chain = create(context ?? {});
|
|
40
|
+
Object.defineProperty(chain, "fn", {
|
|
41
|
+
value: fn,
|
|
42
|
+
enumerable: false
|
|
43
|
+
});
|
|
44
|
+
return chain;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* If any tasks been marked as `only`, mark all other tasks as `skip`.
|
|
49
|
+
*/
|
|
50
|
+
function interpretTaskModes(file, namePattern, testLocations, testIds, testTagsFilter, onlyMode, parentIsOnly, allowOnly) {
|
|
51
|
+
const matchedLocations = [];
|
|
52
|
+
const traverseSuite = (suite, parentIsOnly, parentMatchedWithLocation) => {
|
|
53
|
+
const suiteIsOnly = parentIsOnly || suite.mode === "only";
|
|
54
|
+
// Check if any tasks in this suite have `.only` - if so, only those should run
|
|
55
|
+
const hasSomeTasksOnly = onlyMode && suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
|
|
56
|
+
suite.tasks.forEach((t) => {
|
|
57
|
+
// Check if either the parent suite or the task itself are marked as included
|
|
58
|
+
// If there are tasks with `.only` in this suite, only include those (not all tasks from describe.only)
|
|
59
|
+
const includeTask = hasSomeTasksOnly ? t.mode === "only" || t.type === "suite" && someTasksAreOnly(t) : suiteIsOnly || t.mode === "only";
|
|
60
|
+
if (onlyMode) {
|
|
61
|
+
if (t.type === "suite" && (includeTask || someTasksAreOnly(t))) {
|
|
62
|
+
// Don't skip this suite
|
|
63
|
+
if (t.mode === "only") {
|
|
64
|
+
checkAllowOnly(t, allowOnly);
|
|
65
|
+
t.mode = "run";
|
|
66
|
+
}
|
|
67
|
+
} else if (t.mode === "run" && !includeTask) {
|
|
68
|
+
t.mode = "skip";
|
|
69
|
+
} else if (t.mode === "only") {
|
|
70
|
+
checkAllowOnly(t, allowOnly);
|
|
71
|
+
t.mode = "run";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
let hasLocationMatch = parentMatchedWithLocation;
|
|
75
|
+
// Match test location against provided locations, only run if present
|
|
76
|
+
// in `testLocations`. Note: if `includeTaskLocation` is not enabled,
|
|
77
|
+
// all test will be skipped.
|
|
78
|
+
if (testLocations !== undefined && testLocations.length !== 0) {
|
|
79
|
+
if (t.location && testLocations?.includes(t.location.line)) {
|
|
80
|
+
t.mode = "run";
|
|
81
|
+
matchedLocations.push(t.location.line);
|
|
82
|
+
hasLocationMatch = true;
|
|
83
|
+
} else if (parentMatchedWithLocation) {
|
|
84
|
+
t.mode = "run";
|
|
85
|
+
} else if (t.type === "test") {
|
|
86
|
+
t.mode = "skip";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (t.type === "test") {
|
|
90
|
+
if (namePattern && !getTaskFullName(t).match(namePattern)) {
|
|
91
|
+
t.mode = "skip";
|
|
92
|
+
}
|
|
93
|
+
if (testIds && !testIds.includes(t.id)) {
|
|
94
|
+
t.mode = "skip";
|
|
95
|
+
}
|
|
96
|
+
if (testTagsFilter && !testTagsFilter(t.tags || [])) {
|
|
97
|
+
t.mode = "skip";
|
|
98
|
+
}
|
|
99
|
+
} else if (t.type === "suite") {
|
|
100
|
+
if (t.mode === "skip") {
|
|
101
|
+
skipAllTasks(t);
|
|
102
|
+
} else if (t.mode === "todo") {
|
|
103
|
+
todoAllTasks(t);
|
|
104
|
+
} else {
|
|
105
|
+
traverseSuite(t, includeTask, hasLocationMatch);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
// if all subtasks are skipped, mark as skip
|
|
110
|
+
if (suite.mode === "run" || suite.mode === "queued") {
|
|
111
|
+
if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run" && i.mode !== "queued")) {
|
|
112
|
+
suite.mode = "skip";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
traverseSuite(file, parentIsOnly, false);
|
|
117
|
+
const nonMatching = testLocations?.filter((loc) => !matchedLocations.includes(loc));
|
|
118
|
+
if (nonMatching && nonMatching.length !== 0) {
|
|
119
|
+
const message = nonMatching.length === 1 ? `line ${nonMatching[0]}` : `lines ${nonMatching.join(", ")}`;
|
|
120
|
+
if (file.result === undefined) {
|
|
121
|
+
file.result = {
|
|
122
|
+
state: "fail",
|
|
123
|
+
errors: []
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (file.result.errors === undefined) {
|
|
127
|
+
file.result.errors = [];
|
|
128
|
+
}
|
|
129
|
+
file.result.errors.push(processError(new Error(`No test found in ${file.name} in ${message}`)));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function getTaskFullName(task) {
|
|
133
|
+
return `${task.suite ? `${getTaskFullName(task.suite)} ` : ""}${task.name}`;
|
|
134
|
+
}
|
|
135
|
+
function someTasksAreOnly(suite) {
|
|
136
|
+
return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
|
|
137
|
+
}
|
|
138
|
+
function skipAllTasks(suite) {
|
|
139
|
+
suite.tasks.forEach((t) => {
|
|
140
|
+
if (t.mode === "run" || t.mode === "queued") {
|
|
141
|
+
t.mode = "skip";
|
|
142
|
+
if (t.type === "suite") {
|
|
143
|
+
skipAllTasks(t);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function todoAllTasks(suite) {
|
|
149
|
+
suite.tasks.forEach((t) => {
|
|
150
|
+
if (t.mode === "run" || t.mode === "queued") {
|
|
151
|
+
t.mode = "todo";
|
|
152
|
+
if (t.type === "suite") {
|
|
153
|
+
todoAllTasks(t);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function checkAllowOnly(task, allowOnly) {
|
|
159
|
+
if (allowOnly) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const error = processError(new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error"));
|
|
163
|
+
task.result = {
|
|
164
|
+
state: "fail",
|
|
165
|
+
errors: [error]
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
169
|
+
function generateHash(str) {
|
|
170
|
+
let hash = 0;
|
|
171
|
+
if (str.length === 0) {
|
|
172
|
+
return `${hash}`;
|
|
173
|
+
}
|
|
174
|
+
for (let i = 0; i < str.length; i++) {
|
|
175
|
+
const char = str.charCodeAt(i);
|
|
176
|
+
hash = (hash << 5) - hash + char;
|
|
177
|
+
hash = hash & hash;
|
|
178
|
+
}
|
|
179
|
+
return `${hash}`;
|
|
180
|
+
}
|
|
181
|
+
function calculateSuiteHash(parent) {
|
|
182
|
+
parent.tasks.forEach((t, idx) => {
|
|
183
|
+
t.id = `${parent.id}_${idx}`;
|
|
184
|
+
if (t.type === "suite") {
|
|
185
|
+
calculateSuiteHash(t);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function createFileTask(filepath, root, projectName, pool, viteEnvironment) {
|
|
190
|
+
const path = relative(root, filepath);
|
|
191
|
+
const file = {
|
|
192
|
+
id: generateFileHash(path, projectName),
|
|
193
|
+
name: path,
|
|
194
|
+
fullName: path,
|
|
195
|
+
type: "suite",
|
|
196
|
+
mode: "queued",
|
|
197
|
+
filepath,
|
|
198
|
+
tasks: [],
|
|
199
|
+
meta: Object.create(null),
|
|
200
|
+
projectName,
|
|
201
|
+
file: undefined,
|
|
202
|
+
pool,
|
|
203
|
+
viteEnvironment
|
|
204
|
+
};
|
|
205
|
+
file.file = file;
|
|
206
|
+
return file;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Generate a unique ID for a file based on its path and project name
|
|
210
|
+
* @param file File relative to the root of the project to keep ID the same between different machines
|
|
211
|
+
* @param projectName The name of the test project
|
|
212
|
+
*/
|
|
213
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
214
|
+
function generateFileHash(file, projectName) {
|
|
215
|
+
return /* @__PURE__ */ generateHash(`${file}${projectName || ""}`);
|
|
216
|
+
}
|
|
217
|
+
function findTestFileStackTrace(testFilePath, error) {
|
|
218
|
+
// first line is the error message
|
|
219
|
+
const lines = error.split("\n").slice(1);
|
|
220
|
+
for (const line of lines) {
|
|
221
|
+
const stack = parseSingleStack(line);
|
|
222
|
+
if (stack && stack.file === testFilePath) {
|
|
223
|
+
return stack;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Return a function for running multiple async operations with limited concurrency.
|
|
230
|
+
*/
|
|
231
|
+
function limitConcurrency(concurrency = Infinity) {
|
|
232
|
+
// The number of currently active + pending tasks.
|
|
233
|
+
let count = 0;
|
|
234
|
+
// The head and tail of the pending task queue, built using a singly linked list.
|
|
235
|
+
// Both head and tail are initially undefined, signifying an empty queue.
|
|
236
|
+
// They both become undefined again whenever there are no pending tasks.
|
|
237
|
+
let head;
|
|
238
|
+
let tail;
|
|
239
|
+
// A bookkeeping function executed whenever a task has been run to completion.
|
|
240
|
+
const finish = () => {
|
|
241
|
+
count--;
|
|
242
|
+
// Check if there are further pending tasks in the queue.
|
|
243
|
+
if (head) {
|
|
244
|
+
// Allow the next pending task to run and pop it from the queue.
|
|
245
|
+
head[0]();
|
|
246
|
+
head = head[1];
|
|
247
|
+
// The head may now be undefined if there are no further pending tasks.
|
|
248
|
+
// In that case, set tail to undefined as well.
|
|
249
|
+
tail = head && tail;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
const acquire = () => {
|
|
253
|
+
let released = false;
|
|
254
|
+
const release = () => {
|
|
255
|
+
if (!released) {
|
|
256
|
+
released = true;
|
|
257
|
+
finish();
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
if (count++ < concurrency) {
|
|
261
|
+
return release;
|
|
262
|
+
}
|
|
263
|
+
return new Promise((resolve) => {
|
|
264
|
+
if (tail) {
|
|
265
|
+
// There are pending tasks, so append to the queue.
|
|
266
|
+
tail = tail[1] = [() => resolve(release)];
|
|
267
|
+
} else {
|
|
268
|
+
// No other pending tasks, initialize the queue with a new tail and head.
|
|
269
|
+
head = tail = [() => resolve(release)];
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
const limiterFn = (func, ...args) => {
|
|
274
|
+
function run(release) {
|
|
275
|
+
try {
|
|
276
|
+
const result = func(...args);
|
|
277
|
+
if (result instanceof Promise) {
|
|
278
|
+
return result.finally(release);
|
|
279
|
+
}
|
|
280
|
+
release();
|
|
281
|
+
return Promise.resolve(result);
|
|
282
|
+
} catch (error) {
|
|
283
|
+
release();
|
|
284
|
+
return Promise.reject(error);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const release = acquire();
|
|
288
|
+
return release instanceof Promise ? release.then(run) : run(release);
|
|
289
|
+
};
|
|
290
|
+
return Object.assign(limiterFn, { acquire });
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Partition in tasks groups by consecutive concurrent
|
|
295
|
+
*/
|
|
296
|
+
function partitionSuiteChildren(suite) {
|
|
297
|
+
let tasksGroup = [];
|
|
298
|
+
const tasksGroups = [];
|
|
299
|
+
for (const c of suite.tasks) {
|
|
300
|
+
if (tasksGroup.length === 0 || c.concurrent === tasksGroup[0].concurrent) {
|
|
301
|
+
tasksGroup.push(c);
|
|
302
|
+
} else {
|
|
303
|
+
tasksGroups.push(tasksGroup);
|
|
304
|
+
tasksGroup = [c];
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (tasksGroup.length > 0) {
|
|
308
|
+
tasksGroups.push(tasksGroup);
|
|
309
|
+
}
|
|
310
|
+
return tasksGroups;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function validateTags(config, tags) {
|
|
314
|
+
if (!config.strictTags) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const availableTags = new Set(config.tags.map((tag) => tag.name));
|
|
318
|
+
for (const tag of tags) {
|
|
319
|
+
if (!availableTags.has(tag)) {
|
|
320
|
+
throw createNoTagsError(config.tags, tag);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function createNoTagsError(availableTags, tag, prefix = "tag") {
|
|
325
|
+
if (!availableTags.length) {
|
|
326
|
+
throw new Error(`The Vitest config does't define any "tags", cannot apply "${tag}" ${prefix} for this test. See: https://vitest.dev/guide/test-tags`);
|
|
327
|
+
}
|
|
328
|
+
throw new Error(`The ${prefix} "${tag}" is not defined in the configuration. Available tags are:\n${availableTags.map((t) => `- ${t.name}${t.description ? `: ${t.description}` : ""}`).join("\n")}`);
|
|
329
|
+
}
|
|
330
|
+
function createTagsFilter(tagsExpr, availableTags) {
|
|
331
|
+
const matchers = tagsExpr.map((expr) => parseTagsExpression(expr, availableTags));
|
|
332
|
+
return (testTags) => {
|
|
333
|
+
return matchers.every((matcher) => matcher(testTags));
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function parseTagsExpression(expr, availableTags) {
|
|
337
|
+
const tokens = tokenize(expr);
|
|
338
|
+
const stream = new TokenStream(tokens, expr);
|
|
339
|
+
const ast = parseOrExpression(stream, availableTags);
|
|
340
|
+
if (stream.peek().type !== "EOF") {
|
|
341
|
+
throw new Error(`Invalid tags expression: unexpected "${formatToken(stream.peek())}" in "${expr}"`);
|
|
342
|
+
}
|
|
343
|
+
return (tags) => evaluateNode(ast, tags);
|
|
344
|
+
}
|
|
345
|
+
function formatToken(token) {
|
|
346
|
+
switch (token.type) {
|
|
347
|
+
case "TAG": return token.value;
|
|
348
|
+
default: return formatTokenType(token.type);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function tokenize(expr) {
|
|
352
|
+
const tokens = [];
|
|
353
|
+
let i = 0;
|
|
354
|
+
while (i < expr.length) {
|
|
355
|
+
if (expr[i] === " " || expr[i] === " ") {
|
|
356
|
+
i++;
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
if (expr[i] === "(") {
|
|
360
|
+
tokens.push({ type: "LPAREN" });
|
|
361
|
+
i++;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (expr[i] === ")") {
|
|
365
|
+
tokens.push({ type: "RPAREN" });
|
|
366
|
+
i++;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (expr[i] === "!") {
|
|
370
|
+
tokens.push({ type: "NOT" });
|
|
371
|
+
i++;
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
if (expr.slice(i, i + 2) === "&&") {
|
|
375
|
+
tokens.push({ type: "AND" });
|
|
376
|
+
i += 2;
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (expr.slice(i, i + 2) === "||") {
|
|
380
|
+
tokens.push({ type: "OR" });
|
|
381
|
+
i += 2;
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (/^and(?:\s|\)|$)/i.test(expr.slice(i))) {
|
|
385
|
+
tokens.push({ type: "AND" });
|
|
386
|
+
i += 3;
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (/^or(?:\s|\)|$)/i.test(expr.slice(i))) {
|
|
390
|
+
tokens.push({ type: "OR" });
|
|
391
|
+
i += 2;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (/^not\s/i.test(expr.slice(i))) {
|
|
395
|
+
tokens.push({ type: "NOT" });
|
|
396
|
+
i += 3;
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
let tag = "";
|
|
400
|
+
while (i < expr.length && expr[i] !== " " && expr[i] !== " " && expr[i] !== "(" && expr[i] !== ")" && expr[i] !== "!" && expr[i] !== "&" && expr[i] !== "|") {
|
|
401
|
+
const remaining = expr.slice(i);
|
|
402
|
+
// Only treat and/or/not as operators if we're at the start of a tag (after whitespace)
|
|
403
|
+
// This allows tags like "demand", "editor", "cannot" to work correctly
|
|
404
|
+
if (tag === "" && (/^and(?:\s|\)|$)/i.test(remaining) || /^or(?:\s|\)|$)/i.test(remaining) || /^not\s/i.test(remaining))) {
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
tag += expr[i];
|
|
408
|
+
i++;
|
|
409
|
+
}
|
|
410
|
+
if (tag) {
|
|
411
|
+
tokens.push({
|
|
412
|
+
type: "TAG",
|
|
413
|
+
value: tag
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
tokens.push({ type: "EOF" });
|
|
418
|
+
return tokens;
|
|
419
|
+
}
|
|
420
|
+
class TokenStream {
|
|
421
|
+
pos = 0;
|
|
422
|
+
constructor(tokens, expr) {
|
|
423
|
+
this.tokens = tokens;
|
|
424
|
+
this.expr = expr;
|
|
425
|
+
}
|
|
426
|
+
peek() {
|
|
427
|
+
return this.tokens[this.pos];
|
|
428
|
+
}
|
|
429
|
+
next() {
|
|
430
|
+
return this.tokens[this.pos++];
|
|
431
|
+
}
|
|
432
|
+
expect(type) {
|
|
433
|
+
const token = this.next();
|
|
434
|
+
if (token.type !== type) {
|
|
435
|
+
if (type === "RPAREN" && token.type === "EOF") {
|
|
436
|
+
throw new Error(`Invalid tags expression: missing closing ")" in "${this.expr}"`);
|
|
437
|
+
}
|
|
438
|
+
throw new Error(`Invalid tags expression: expected "${formatTokenType(type)}" but got "${formatToken(token)}" in "${this.expr}"`);
|
|
439
|
+
}
|
|
440
|
+
return token;
|
|
441
|
+
}
|
|
442
|
+
unexpectedToken() {
|
|
443
|
+
const token = this.peek();
|
|
444
|
+
if (token.type === "EOF") {
|
|
445
|
+
throw new Error(`Invalid tags expression: unexpected end of expression in "${this.expr}"`);
|
|
446
|
+
}
|
|
447
|
+
throw new Error(`Invalid tags expression: unexpected "${formatToken(token)}" in "${this.expr}"`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
function formatTokenType(type) {
|
|
451
|
+
switch (type) {
|
|
452
|
+
case "TAG": return "tag";
|
|
453
|
+
case "AND": return "and";
|
|
454
|
+
case "OR": return "or";
|
|
455
|
+
case "NOT": return "not";
|
|
456
|
+
case "LPAREN": return "(";
|
|
457
|
+
case "RPAREN": return ")";
|
|
458
|
+
case "EOF": return "end of expression";
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function parseOrExpression(stream, availableTags) {
|
|
462
|
+
let left = parseAndExpression(stream, availableTags);
|
|
463
|
+
while (stream.peek().type === "OR") {
|
|
464
|
+
stream.next();
|
|
465
|
+
const right = parseAndExpression(stream, availableTags);
|
|
466
|
+
left = {
|
|
467
|
+
type: "or",
|
|
468
|
+
left,
|
|
469
|
+
right
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
return left;
|
|
473
|
+
}
|
|
474
|
+
function parseAndExpression(stream, availableTags) {
|
|
475
|
+
let left = parseUnaryExpression(stream, availableTags);
|
|
476
|
+
while (stream.peek().type === "AND") {
|
|
477
|
+
stream.next();
|
|
478
|
+
const right = parseUnaryExpression(stream, availableTags);
|
|
479
|
+
left = {
|
|
480
|
+
type: "and",
|
|
481
|
+
left,
|
|
482
|
+
right
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
return left;
|
|
486
|
+
}
|
|
487
|
+
function parseUnaryExpression(stream, availableTags) {
|
|
488
|
+
if (stream.peek().type === "NOT") {
|
|
489
|
+
stream.next();
|
|
490
|
+
const operand = parseUnaryExpression(stream, availableTags);
|
|
491
|
+
return {
|
|
492
|
+
type: "not",
|
|
493
|
+
operand
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
return parsePrimaryExpression(stream, availableTags);
|
|
497
|
+
}
|
|
498
|
+
function parsePrimaryExpression(stream, availableTags) {
|
|
499
|
+
const token = stream.peek();
|
|
500
|
+
if (token.type === "LPAREN") {
|
|
501
|
+
stream.next();
|
|
502
|
+
const expr = parseOrExpression(stream, availableTags);
|
|
503
|
+
stream.expect("RPAREN");
|
|
504
|
+
return expr;
|
|
505
|
+
}
|
|
506
|
+
if (token.type === "TAG") {
|
|
507
|
+
stream.next();
|
|
508
|
+
const tagValue = token.value;
|
|
509
|
+
const pattern = resolveTagPattern(tagValue, availableTags);
|
|
510
|
+
return {
|
|
511
|
+
type: "tag",
|
|
512
|
+
value: tagValue,
|
|
513
|
+
pattern
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
stream.unexpectedToken();
|
|
517
|
+
}
|
|
518
|
+
function createWildcardRegex(pattern) {
|
|
519
|
+
return new RegExp(`^${pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`);
|
|
520
|
+
}
|
|
521
|
+
function resolveTagPattern(tagPattern, availableTags) {
|
|
522
|
+
if (tagPattern.includes("*")) {
|
|
523
|
+
const regex = createWildcardRegex(tagPattern);
|
|
524
|
+
const hasMatch = availableTags.some((tag) => regex.test(tag.name));
|
|
525
|
+
if (!hasMatch) {
|
|
526
|
+
throw createNoTagsError(availableTags, tagPattern, "tag pattern");
|
|
527
|
+
}
|
|
528
|
+
return regex;
|
|
529
|
+
}
|
|
530
|
+
if (!availableTags.length || !availableTags.some((tag) => tag.name === tagPattern)) {
|
|
531
|
+
throw createNoTagsError(availableTags, tagPattern, "tag pattern");
|
|
532
|
+
}
|
|
533
|
+
return null;
|
|
534
|
+
}
|
|
535
|
+
function evaluateNode(node, tags) {
|
|
536
|
+
switch (node.type) {
|
|
537
|
+
case "tag":
|
|
538
|
+
if (node.pattern) {
|
|
539
|
+
return tags.some((tag) => node.pattern.test(tag));
|
|
540
|
+
}
|
|
541
|
+
return tags.includes(node.value);
|
|
542
|
+
case "not": return !evaluateNode(node.operand, tags);
|
|
543
|
+
case "and": return evaluateNode(node.left, tags) && evaluateNode(node.right, tags);
|
|
544
|
+
case "or": return evaluateNode(node.left, tags) || evaluateNode(node.right, tags);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function isTestCase(s) {
|
|
549
|
+
return s.type === "test";
|
|
550
|
+
}
|
|
551
|
+
function getTests(suite) {
|
|
552
|
+
const tests = [];
|
|
553
|
+
const arraySuites = toArray(suite);
|
|
554
|
+
for (const s of arraySuites) {
|
|
555
|
+
if (isTestCase(s)) {
|
|
556
|
+
tests.push(s);
|
|
557
|
+
} else {
|
|
558
|
+
for (const task of s.tasks) {
|
|
559
|
+
if (isTestCase(task)) {
|
|
560
|
+
tests.push(task);
|
|
561
|
+
} else {
|
|
562
|
+
const taskTests = getTests(task);
|
|
563
|
+
for (const test of taskTests) {
|
|
564
|
+
tests.push(test);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return tests;
|
|
571
|
+
}
|
|
572
|
+
function getTasks(tasks = []) {
|
|
573
|
+
return toArray(tasks).flatMap((s) => isTestCase(s) ? [s] : [s, ...getTasks(s.tasks)]);
|
|
574
|
+
}
|
|
575
|
+
function getSuites(suite) {
|
|
576
|
+
return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []);
|
|
577
|
+
}
|
|
578
|
+
function hasTests(suite) {
|
|
579
|
+
return toArray(suite).some((s) => s.tasks.some((c) => isTestCase(c) || hasTests(c)));
|
|
580
|
+
}
|
|
581
|
+
function hasFailed(suite) {
|
|
582
|
+
return toArray(suite).some((s) => s.result?.state === "fail" || s.type === "suite" && hasFailed(s.tasks));
|
|
583
|
+
}
|
|
584
|
+
function getNames(task) {
|
|
585
|
+
const names = [task.name];
|
|
586
|
+
let current = task;
|
|
587
|
+
while (current?.suite) {
|
|
588
|
+
current = current.suite;
|
|
589
|
+
if (current?.name) {
|
|
590
|
+
names.unshift(current.name);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (current !== task.file) {
|
|
594
|
+
names.unshift(task.file.name);
|
|
595
|
+
}
|
|
596
|
+
return names;
|
|
597
|
+
}
|
|
598
|
+
function getFullName(task, separator = " > ") {
|
|
599
|
+
return getNames(task).join(separator);
|
|
600
|
+
}
|
|
601
|
+
function getTestName(task, separator = " > ") {
|
|
602
|
+
return getNames(task).slice(1).join(separator);
|
|
603
|
+
}
|
|
604
|
+
function createTaskName(names, separator = " > ") {
|
|
605
|
+
return names.filter((name) => name !== undefined).join(separator);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
export { createChainable as a, createFileTask as b, calculateSuiteHash as c, createTagsFilter as d, createTaskName as e, findTestFileStackTrace as f, generateFileHash as g, generateHash as h, getFullName as i, getNames as j, getSuites as k, getTasks as l, getTestName as m, getTests as n, hasFailed as o, hasTests as p, interpretTaskModes as q, isTestCase as r, limitConcurrency as s, partitionSuiteChildren as t, someTasksAreOnly as u, validateTags as v, getChainableContext as w, createNoTagsError as x };
|