@vitest/runner 0.34.5 → 0.34.6
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.js +50 -13
- package/package.json +2 -2
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) {
|
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.6",
|
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.6"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"build": "rimraf dist && rollup -c",
|