@vitest/runner 0.34.5 → 0.34.7
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 +2 -2
- package/dist/index.js +50 -13
- package/dist/{tasks-e594cd24.d.ts → tasks-d7d578d8.d.ts} +9 -4
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
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 SuiteHooks, O as OnTestFailedHandler, a as Test } from './tasks-
|
4
|
-
export { D as DoneCallback, o as
|
3
|
+
import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as SuiteHooks, O as OnTestFailedHandler, a as Test } from './tasks-d7d578d8.js';
|
4
|
+
export { D as DoneCallback, o as Fixture, p as Fixtures, q as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, s as RuntimeContext, u as SequenceHooks, v as SequenceSetupFiles, S as Suite, r as SuiteFactory, i as TaskBase, b as TaskCustom, j as TaskMeta, k as TaskResult, l as TaskResultPack, h as TaskState, t as TestContext, m as TestFunction, n as TestOptions } from './tasks-d7d578d8.js';
|
5
5
|
import { Awaitable } from '@vitest/utils';
|
6
6
|
|
7
7
|
declare function updateTask(task: Task, runner: VitestRunner): void;
|
package/dist/index.js
CHANGED
@@ -110,11 +110,26 @@ function mergeContextFixtures(fixtures, context = {}) {
|
|
110
110
|
});
|
111
111
|
return context;
|
112
112
|
}
|
113
|
+
const fixtureValueMap = /* @__PURE__ */ new Map();
|
114
|
+
const fixtureCleanupFnMap = /* @__PURE__ */ new Map();
|
115
|
+
async function callFixtureCleanup(id) {
|
116
|
+
const cleanupFnArray = fixtureCleanupFnMap.get(id);
|
117
|
+
if (!cleanupFnArray)
|
118
|
+
return;
|
119
|
+
for (const cleanup of cleanupFnArray.reverse())
|
120
|
+
await cleanup();
|
121
|
+
fixtureCleanupFnMap.delete(id);
|
122
|
+
}
|
113
123
|
function withFixtures(fn, testContext) {
|
114
124
|
return (hookContext) => {
|
115
125
|
const context = hookContext || testContext;
|
116
126
|
if (!context)
|
117
127
|
return fn({});
|
128
|
+
let cleanupFnArray = fixtureCleanupFnMap.get(context.task.suite.id);
|
129
|
+
if (!cleanupFnArray) {
|
130
|
+
cleanupFnArray = [];
|
131
|
+
fixtureCleanupFnMap.set(context.task.suite.id, cleanupFnArray);
|
132
|
+
}
|
118
133
|
const fixtures = getFixture(context);
|
119
134
|
if (!(fixtures == null ? void 0 : fixtures.length))
|
120
135
|
return fn(context);
|
@@ -124,19 +139,40 @@ function withFixtures(fn, testContext) {
|
|
124
139
|
const usedFixtures = fixtures.filter(({ prop }) => usedProps.includes(prop));
|
125
140
|
const pendingFixtures = resolveDeps(usedFixtures);
|
126
141
|
let cursor = 0;
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
142
|
+
return new Promise((resolve, reject) => {
|
143
|
+
async function use(fixtureValue) {
|
144
|
+
const fixture = pendingFixtures[cursor++];
|
145
|
+
context[fixture.prop] = fixtureValue;
|
146
|
+
if (!fixtureValueMap.has(fixture)) {
|
147
|
+
fixtureValueMap.set(fixture, fixtureValue);
|
148
|
+
cleanupFnArray.unshift(() => {
|
149
|
+
fixtureValueMap.delete(fixture);
|
150
|
+
});
|
151
|
+
}
|
152
|
+
if (cursor < pendingFixtures.length) {
|
153
|
+
await next();
|
154
|
+
} else {
|
155
|
+
try {
|
156
|
+
resolve(await fn(context));
|
157
|
+
} catch (err) {
|
158
|
+
reject(err);
|
159
|
+
}
|
160
|
+
return new Promise((resolve2) => {
|
161
|
+
cleanupFnArray.push(resolve2);
|
162
|
+
});
|
163
|
+
}
|
164
|
+
}
|
165
|
+
async function next() {
|
166
|
+
const fixture = pendingFixtures[cursor];
|
167
|
+
const { isFn, value } = fixture;
|
168
|
+
if (fixtureValueMap.has(fixture))
|
169
|
+
return use(fixtureValueMap.get(fixture));
|
170
|
+
else
|
171
|
+
return isFn ? value(context, use) : use(value);
|
172
|
+
}
|
173
|
+
const setupFixturePromise = next();
|
174
|
+
cleanupFnArray.unshift(() => setupFixturePromise);
|
175
|
+
});
|
140
176
|
};
|
141
177
|
}
|
142
178
|
function resolveDeps(fixtures, depSet = /* @__PURE__ */ new Set(), pendingFixtures = []) {
|
@@ -751,6 +787,7 @@ async function runSuite(suite, runner) {
|
|
751
787
|
failTask(suite.result, e, runner.config.diffOptions);
|
752
788
|
}
|
753
789
|
try {
|
790
|
+
await callFixtureCleanup(suite.id);
|
754
791
|
await callSuiteHook(suite, suite, "afterAll", runner, [suite]);
|
755
792
|
await callCleanupHooks(beforeAllCleanups);
|
756
793
|
} catch (e) {
|
@@ -133,11 +133,16 @@ type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & {
|
|
133
133
|
[K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
|
134
134
|
}>;
|
135
135
|
};
|
136
|
+
type FixtureType<T> = T extends (context: any, use: (fixture: infer F) => any) => any ? F : T;
|
137
|
+
type Fixture<T, K extends keyof T, OnlyFunction, ExtraContext = {}, V = FixtureType<T[K]>, FN = (context: {
|
138
|
+
[P in keyof T | keyof ExtraContext as P extends K ? P extends keyof ExtraContext ? P : never : P]: K extends P ? K extends keyof ExtraContext ? ExtraContext[K] : V : P extends keyof T ? T[P] : never;
|
139
|
+
} & TestContext, use: (fixture: V) => Promise<void>) => Promise<void>> = OnlyFunction extends true ? FN : (FN | V);
|
136
140
|
type Fixtures<T extends Record<string, any>, ExtraContext = {}> = {
|
137
|
-
[K in keyof T]: T
|
138
|
-
|
139
|
-
|
141
|
+
[K in keyof T]: Fixture<T, K, false, ExtraContext>;
|
142
|
+
} | {
|
143
|
+
[K in keyof T]: Fixture<T, K, true, ExtraContext>;
|
140
144
|
};
|
145
|
+
type InferFixturesTypes<T> = T extends TestAPI<infer C> ? C : T;
|
141
146
|
type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', [
|
142
147
|
name: string | Function,
|
143
148
|
factory?: SuiteFactory<ExtraContext>,
|
@@ -200,4 +205,4 @@ type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
|
|
200
205
|
type SequenceHooks = 'stack' | 'list' | 'parallel';
|
201
206
|
type SequenceSetupFiles = 'list' | 'parallel';
|
202
207
|
|
203
|
-
export { ChainableFunction as C, DoneCallback as D, File as F, HookListener as H, OnTestFailedHandler as O, RunMode as R, Suite as S, Task as T, Test as a, TaskCustom as b, createChainable as c, SuiteAPI as d, TestAPI as e, SuiteCollector as f, SuiteHooks as g, TaskState as h, TaskBase as i, TaskMeta as j, TaskResult as k, TaskResultPack as l, TestFunction as m, TestOptions as n,
|
208
|
+
export { ChainableFunction as C, DoneCallback as D, File as F, HookListener as H, InferFixturesTypes as I, OnTestFailedHandler as O, RunMode as R, Suite as S, Task as T, Test as a, TaskCustom as b, createChainable as c, SuiteAPI as d, TestAPI as e, SuiteCollector as f, SuiteHooks as g, TaskState as h, TaskBase as i, TaskMeta as j, TaskResult as k, TaskResultPack as l, TestFunction as m, TestOptions as n, Fixture as o, Fixtures as p, HookCleanupCallback as q, SuiteFactory as r, RuntimeContext as s, TestContext as t, SequenceHooks as u, SequenceSetupFiles as v };
|
package/dist/types.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
export { D as DoneCallback, o as
|
1
|
+
import { u as SequenceHooks, v as SequenceSetupFiles, F as File, a as Test, S as Suite, l as TaskResultPack, t as TestContext } from './tasks-d7d578d8.js';
|
2
|
+
export { D as DoneCallback, o as Fixture, p as Fixtures, q as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, R as RunMode, s as RuntimeContext, d as SuiteAPI, f as SuiteCollector, r as SuiteFactory, g as SuiteHooks, T as Task, i as TaskBase, b as TaskCustom, j as TaskMeta, k as TaskResult, h as TaskState, e as TestAPI, m as TestFunction, n as TestOptions } from './tasks-d7d578d8.js';
|
3
3
|
import '@vitest/utils';
|
4
4
|
|
5
5
|
/**
|
package/dist/utils.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { S as Suite, T as Task, a as Test, b as TaskCustom } from './tasks-
|
2
|
-
export { C as ChainableFunction, c as createChainable } from './tasks-
|
1
|
+
import { S as Suite, T as Task, a as Test, b as TaskCustom } from './tasks-d7d578d8.js';
|
2
|
+
export { C as ChainableFunction, c as createChainable } from './tasks-d7d578d8.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": "0.34.
|
4
|
+
"version": "0.34.7",
|
5
5
|
"description": "Vitest test runner",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -40,7 +40,7 @@
|
|
40
40
|
"dependencies": {
|
41
41
|
"p-limit": "^4.0.0",
|
42
42
|
"pathe": "^1.1.1",
|
43
|
-
"@vitest/utils": "0.34.
|
43
|
+
"@vitest/utils": "0.34.7"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"build": "rimraf dist && rollup -c",
|