@vitest/runner 1.0.0-beta.3 → 1.0.0-beta.5
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/dist/index.d.ts +3 -2
- package/dist/index.js +20 -10
- package/dist/{tasks-3ea70b32.d.ts → tasks-rsXe_qLO.d.ts} +17 -10
- package/dist/types.d.ts +3 -44
- package/dist/utils.d.ts +2 -2
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
import { VitestRunner } from './types.js';
|
2
2
|
export { CancelReason, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource } from './types.js';
|
3
|
-
import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as CustomAPI, h as SuiteHooks, O as OnTestFailedHandler, a as Test, C as Custom } from './tasks-
|
4
|
-
export { D as DoneCallback, E as ExtendedContext,
|
3
|
+
import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as CustomAPI, h as SuiteHooks, O as OnTestFailedHandler, a as Test, C as Custom } from './tasks-rsXe_qLO.js';
|
4
|
+
export { D as DoneCallback, E as ExtendedContext, r as Fixture, q as FixtureFn, s as Fixtures, t as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, w as RuntimeContext, z as SequenceHooks, A as SequenceSetupFiles, S as Suite, v as SuiteFactory, j as TaskBase, y as TaskContext, u as TaskCustomOptions, l as TaskMeta, k as TaskPopulated, m as TaskResult, n as TaskResultPack, i as TaskState, x as TestContext, o as TestFunction, p as TestOptions, U as Use } from './tasks-rsXe_qLO.js';
|
5
5
|
import { Awaitable } from '@vitest/utils';
|
6
6
|
export { processError } from '@vitest/utils/error';
|
7
|
+
import '@vitest/utils/diff';
|
7
8
|
|
8
9
|
declare function updateTask(task: Task, runner: VitestRunner): void;
|
9
10
|
declare function startTests(paths: string[], runner: VitestRunner): Promise<File[]>;
|
package/dist/index.js
CHANGED
@@ -105,12 +105,12 @@ function mergeContextFixtures(fixtures, context = {}) {
|
|
105
105
|
if (fixture.isFn) {
|
106
106
|
const usedProps = getUsedProps(fixture.value);
|
107
107
|
if (usedProps.length)
|
108
|
-
fixture.deps = context.fixtures.filter(({
|
108
|
+
fixture.deps = context.fixtures.filter(({ prop }) => prop !== fixture.prop && usedProps.includes(prop));
|
109
109
|
}
|
110
110
|
});
|
111
111
|
return context;
|
112
112
|
}
|
113
|
-
const
|
113
|
+
const fixtureValueMaps = /* @__PURE__ */ new Map();
|
114
114
|
let cleanupFnArray = new Array();
|
115
115
|
async function callFixtureCleanup() {
|
116
116
|
for (const cleanup of cleanupFnArray.reverse())
|
@@ -128,8 +128,13 @@ function withFixtures(fn, testContext) {
|
|
128
128
|
const usedProps = getUsedProps(fn);
|
129
129
|
if (!usedProps.length)
|
130
130
|
return fn(context);
|
131
|
+
if (!fixtureValueMaps.get(context))
|
132
|
+
fixtureValueMaps.set(context, /* @__PURE__ */ new Map());
|
133
|
+
const fixtureValueMap = fixtureValueMaps.get(context);
|
131
134
|
const usedFixtures = fixtures.filter(({ prop }) => usedProps.includes(prop));
|
132
135
|
const pendingFixtures = resolveDeps(usedFixtures);
|
136
|
+
if (!pendingFixtures.length)
|
137
|
+
return fn(context);
|
133
138
|
let cursor = 0;
|
134
139
|
return new Promise((resolve, reject) => {
|
135
140
|
async function use(fixtureValue) {
|
@@ -162,7 +167,7 @@ function withFixtures(fn, testContext) {
|
|
162
167
|
else
|
163
168
|
return isFn ? value(context, use) : use(value);
|
164
169
|
}
|
165
|
-
const setupFixturePromise = next();
|
170
|
+
const setupFixturePromise = next().catch(reject);
|
166
171
|
cleanupFnArray.unshift(() => setupFixturePromise);
|
167
172
|
});
|
168
173
|
};
|
@@ -291,7 +296,7 @@ function createSuiteCollector(name, factory = () => {
|
|
291
296
|
meta: options.meta ?? /* @__PURE__ */ Object.create(null)
|
292
297
|
};
|
293
298
|
const handler = options.handler;
|
294
|
-
if (options.concurrent || !sequential &&
|
299
|
+
if (options.concurrent || !options.sequential && runner.config.sequence.concurrent)
|
295
300
|
task2.concurrent = true;
|
296
301
|
if (shuffle)
|
297
302
|
task2.shuffle = true;
|
@@ -310,11 +315,13 @@ function createSuiteCollector(name, factory = () => {
|
|
310
315
|
tasks.push(task2);
|
311
316
|
return task2;
|
312
317
|
};
|
313
|
-
const test2 = createTest(function(name2, fn = noop, options) {
|
318
|
+
const test2 = createTest(function(name2, fn = noop, options = {}) {
|
314
319
|
if (typeof options === "number")
|
315
320
|
options = { timeout: options };
|
316
321
|
if (typeof suiteOptions === "object")
|
317
322
|
options = Object.assign({}, suiteOptions, options);
|
323
|
+
options.concurrent = this.concurrent || !this.sequential && (options == null ? void 0 : options.concurrent);
|
324
|
+
options.sequential = this.sequential || !this.concurrent && (options == null ? void 0 : options.sequential);
|
318
325
|
const test3 = task(
|
319
326
|
formatName(name2),
|
320
327
|
{ ...this, ...options, handler: fn }
|
@@ -347,7 +354,8 @@ function createSuiteCollector(name, factory = () => {
|
|
347
354
|
each,
|
348
355
|
shuffle,
|
349
356
|
tasks: [],
|
350
|
-
meta: /* @__PURE__ */ Object.create(null)
|
357
|
+
meta: /* @__PURE__ */ Object.create(null),
|
358
|
+
projectName: ""
|
351
359
|
};
|
352
360
|
setHooks(suite2, createSuiteHooks());
|
353
361
|
}
|
@@ -376,14 +384,16 @@ function createSuiteCollector(name, factory = () => {
|
|
376
384
|
return collector;
|
377
385
|
}
|
378
386
|
function createSuite() {
|
379
|
-
function suiteFn(name, factory, options) {
|
387
|
+
function suiteFn(name, factory, options = {}) {
|
380
388
|
const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
381
389
|
const currentSuite = getCurrentSuite();
|
382
390
|
if (typeof options === "number")
|
383
391
|
options = { timeout: options };
|
384
392
|
if (currentSuite == null ? void 0 : currentSuite.options)
|
385
393
|
options = { ...currentSuite.options, ...options };
|
386
|
-
|
394
|
+
options.concurrent = this.concurrent || !this.sequential && (options == null ? void 0 : options.concurrent);
|
395
|
+
options.sequential = this.sequential || !this.concurrent && (options == null ? void 0 : options.sequential);
|
396
|
+
return createSuiteCollector(formatName(name), factory, mode, this.concurrent, this.sequential, this.shuffle, this.each, options);
|
387
397
|
}
|
388
398
|
suiteFn.each = function(cases, ...args) {
|
389
399
|
const suite2 = this.withContext();
|
@@ -433,7 +443,7 @@ function createTaskCollector(fn, context) {
|
|
433
443
|
}, _context);
|
434
444
|
};
|
435
445
|
const _test = createChainable(
|
436
|
-
["concurrent", "skip", "only", "todo", "fails"],
|
446
|
+
["concurrent", "sequential", "skip", "only", "todo", "fails"],
|
437
447
|
taskFn
|
438
448
|
);
|
439
449
|
if (context)
|
@@ -455,11 +465,11 @@ function formatTitle(template, items, idx) {
|
|
455
465
|
if (isObject(items[0])) {
|
456
466
|
formatted = formatted.replace(
|
457
467
|
/\$([$\w_.]+)/g,
|
468
|
+
// https://github.com/chaijs/chai/pull/1490
|
458
469
|
(_, key) => {
|
459
470
|
var _a, _b;
|
460
471
|
return objDisplay(objectAttr(items[0], key), { truncate: (_b = (_a = runner == null ? void 0 : runner.config) == null ? void 0 : _a.chaiConfig) == null ? void 0 : _b.truncateThreshold });
|
461
472
|
}
|
462
|
-
// https://github.com/chaijs/chai/pull/1490
|
463
473
|
);
|
464
474
|
}
|
465
475
|
return formatted;
|
@@ -68,7 +68,7 @@ interface Suite extends TaskBase {
|
|
68
68
|
type: 'suite';
|
69
69
|
tasks: Task[];
|
70
70
|
filepath?: string;
|
71
|
-
projectName
|
71
|
+
projectName: string;
|
72
72
|
}
|
73
73
|
interface File extends Suite {
|
74
74
|
filepath: string;
|
@@ -110,7 +110,7 @@ interface TestEachFunction {
|
|
110
110
|
<T>(cases: ReadonlyArray<T>): (name: string | Function, fn: (...args: T[]) => Awaitable<void>, options?: number | TestOptions) => void;
|
111
111
|
(...args: [TemplateStringsArray, ...any]): (name: string | Function, fn: (...args: any[]) => Awaitable<void>, options?: number | TestOptions) => void;
|
112
112
|
}
|
113
|
-
type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [
|
113
|
+
type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'fails', [
|
114
114
|
name: string | Function,
|
115
115
|
fn?: TestFunction<ExtraContext>,
|
116
116
|
options?: number | TestOptions
|
@@ -137,6 +137,16 @@ interface TestOptions {
|
|
137
137
|
* @default 0
|
138
138
|
*/
|
139
139
|
repeats?: number;
|
140
|
+
/**
|
141
|
+
* Whether tests run concurrently.
|
142
|
+
* Tests inherit `concurrent` from `describe()` and nested `describe()` will inherit from parent's `concurrent`.
|
143
|
+
*/
|
144
|
+
concurrent?: boolean;
|
145
|
+
/**
|
146
|
+
* Whether tests run sequentially.
|
147
|
+
* Tests inherit `sequential` from `describe()` and nested `describe()` will inherit from parent's `sequential`.
|
148
|
+
*/
|
149
|
+
sequential?: boolean;
|
140
150
|
}
|
141
151
|
interface ExtendedAPI<ExtraContext> {
|
142
152
|
each: TestEachFunction;
|
@@ -153,14 +163,11 @@ type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & ExtendedAPI<E
|
|
153
163
|
[K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
|
154
164
|
}>;
|
155
165
|
};
|
156
|
-
type
|
157
|
-
type
|
158
|
-
|
159
|
-
} & TestContext, use: (fixture: V) => Promise<void>) => Promise<void>> = OnlyFunction extends true ? FN : (FN | V);
|
166
|
+
type Use<T> = (value: T) => Promise<void>;
|
167
|
+
type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
|
168
|
+
type Fixture<T, K extends keyof T, ExtraContext = {}> = ((...args: any) => any) extends T[K] ? (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never) : T[K] | (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never);
|
160
169
|
type Fixtures<T extends Record<string, any>, ExtraContext = {}> = {
|
161
|
-
[K in keyof T]: Fixture<T, K,
|
162
|
-
} | {
|
163
|
-
[K in keyof T]: Fixture<T, K, true, ExtraContext>;
|
170
|
+
[K in keyof T]: Fixture<T, K, ExtraContext & ExtendedContext<Test>>;
|
164
171
|
};
|
165
172
|
type InferFixturesTypes<T> = T extends TestAPI<infer C> ? C : T;
|
166
173
|
type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', [
|
@@ -234,4 +241,4 @@ type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
|
|
234
241
|
type SequenceHooks = 'stack' | 'list' | 'parallel';
|
235
242
|
type SequenceSetupFiles = 'list' | 'parallel';
|
236
243
|
|
237
|
-
export { type Custom as C, type DoneCallback as D, type ExtendedContext as E, type File as F, type HookListener as H, type InferFixturesTypes as I, type OnTestFailedHandler as O, type RunMode as R, type Suite as S, type Task as T, type Test as a, type ChainableFunction as b, createChainable as c, type SuiteAPI as d, type TestAPI as e, type SuiteCollector as f, type CustomAPI as g, type SuiteHooks as h, type TaskState as i, type TaskBase as j, type TaskPopulated as k, type TaskMeta as l, type TaskResult as m, type TaskResultPack as n, type TestFunction as o, type TestOptions as p, type
|
244
|
+
export { type SequenceSetupFiles as A, type Custom as C, type DoneCallback as D, type ExtendedContext as E, type File as F, type HookListener as H, type InferFixturesTypes as I, type OnTestFailedHandler as O, type RunMode as R, type Suite as S, type Task as T, type Use as U, type Test as a, type ChainableFunction as b, createChainable as c, type SuiteAPI as d, type TestAPI as e, type SuiteCollector as f, type CustomAPI as g, type SuiteHooks as h, type TaskState as i, type TaskBase as j, type TaskPopulated as k, type TaskMeta as l, type TaskResult as m, type TaskResultPack as n, type TestFunction as o, type TestOptions as p, type FixtureFn as q, type Fixture as r, type Fixtures as s, type HookCleanupCallback as t, type TaskCustomOptions as u, type SuiteFactory as v, type RuntimeContext as w, type TestContext as x, type TaskContext as y, type SequenceHooks as z };
|
package/dist/types.d.ts
CHANGED
@@ -1,49 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
export { g as CustomAPI, D as DoneCallback,
|
1
|
+
import { z as SequenceHooks, A as SequenceSetupFiles, F as File, k as TaskPopulated, S as Suite, n as TaskResultPack, a as Test, C as Custom, y as TaskContext, E as ExtendedContext } from './tasks-rsXe_qLO.js';
|
2
|
+
export { g as CustomAPI, D as DoneCallback, r as Fixture, q as FixtureFn, s as Fixtures, t as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, R as RunMode, w as RuntimeContext, d as SuiteAPI, f as SuiteCollector, v as SuiteFactory, h as SuiteHooks, T as Task, j as TaskBase, u as TaskCustomOptions, l as TaskMeta, m as TaskResult, i as TaskState, e as TestAPI, x as TestContext, o as TestFunction, p as TestOptions, U as Use } from './tasks-rsXe_qLO.js';
|
3
|
+
import { DiffOptions } from '@vitest/utils/diff';
|
3
4
|
import '@vitest/utils';
|
4
5
|
|
5
|
-
/**
|
6
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
7
|
-
*
|
8
|
-
* This source code is licensed under the MIT license found in the
|
9
|
-
* LICENSE file in the root directory of this source tree.
|
10
|
-
*/
|
11
|
-
|
12
|
-
|
13
|
-
declare type CompareKeys =
|
14
|
-
| ((a: string, b: string) => number)
|
15
|
-
| null
|
16
|
-
| undefined;
|
17
|
-
|
18
|
-
/**
|
19
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
20
|
-
*
|
21
|
-
* This source code is licensed under the MIT license found in the
|
22
|
-
* LICENSE file in the root directory of this source tree.
|
23
|
-
*/
|
24
|
-
|
25
|
-
type DiffOptionsColor = (arg: string) => string;
|
26
|
-
interface DiffOptions {
|
27
|
-
aAnnotation?: string;
|
28
|
-
aColor?: DiffOptionsColor;
|
29
|
-
aIndicator?: string;
|
30
|
-
bAnnotation?: string;
|
31
|
-
bColor?: DiffOptionsColor;
|
32
|
-
bIndicator?: string;
|
33
|
-
changeColor?: DiffOptionsColor;
|
34
|
-
changeLineTrailingSpaceColor?: DiffOptionsColor;
|
35
|
-
commonColor?: DiffOptionsColor;
|
36
|
-
commonIndicator?: string;
|
37
|
-
commonLineTrailingSpaceColor?: DiffOptionsColor;
|
38
|
-
contextLines?: number;
|
39
|
-
emptyFirstOrLastLinePlaceholder?: string;
|
40
|
-
expand?: boolean;
|
41
|
-
includeChangeCounts?: boolean;
|
42
|
-
omitAnnotationLines?: boolean;
|
43
|
-
patchColor?: DiffOptionsColor;
|
44
|
-
compareKeys?: CompareKeys;
|
45
|
-
}
|
46
|
-
|
47
6
|
interface VitestRunnerConfig {
|
48
7
|
root: string;
|
49
8
|
setupFiles: string[] | string;
|
package/dist/utils.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-
|
2
|
-
export { b as ChainableFunction, c as createChainable } from './tasks-
|
1
|
+
import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-rsXe_qLO.js';
|
2
|
+
export { b as ChainableFunction, c as createChainable } from './tasks-rsXe_qLO.js';
|
3
3
|
import { Arrayable } from '@vitest/utils';
|
4
4
|
|
5
5
|
/**
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/runner",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.0.0-beta.
|
4
|
+
"version": "1.0.0-beta.5",
|
5
5
|
"description": "Vitest test runner",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -18,15 +18,15 @@
|
|
18
18
|
"exports": {
|
19
19
|
".": {
|
20
20
|
"types": "./dist/index.d.ts",
|
21
|
-
"
|
21
|
+
"default": "./dist/index.js"
|
22
22
|
},
|
23
23
|
"./utils": {
|
24
24
|
"types": "./dist/utils.d.ts",
|
25
|
-
"
|
25
|
+
"default": "./dist/utils.js"
|
26
26
|
},
|
27
27
|
"./types": {
|
28
28
|
"types": "./dist/types.d.ts",
|
29
|
-
"
|
29
|
+
"default": "./dist/types.js"
|
30
30
|
},
|
31
31
|
"./*": "./*"
|
32
32
|
},
|
@@ -34,13 +34,13 @@
|
|
34
34
|
"module": "./dist/index.js",
|
35
35
|
"types": "./dist/index.d.ts",
|
36
36
|
"files": [
|
37
|
-
"
|
38
|
-
"
|
37
|
+
"*.d.ts",
|
38
|
+
"dist"
|
39
39
|
],
|
40
40
|
"dependencies": {
|
41
|
-
"p-limit": "^
|
41
|
+
"p-limit": "^5.0.0",
|
42
42
|
"pathe": "^1.1.1",
|
43
|
-
"@vitest/utils": "1.0.0-beta.
|
43
|
+
"@vitest/utils": "1.0.0-beta.5"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"build": "rimraf dist && rollup -c",
|