@vitest/runner 1.0.1 → 1.0.3
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 +29 -36
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import limit from 'p-limit';
|
2
|
-
import { getSafeTimers, format, isObject, objDisplay, objectAttr, noop, toArray, shuffle } from '@vitest/utils';
|
2
|
+
import { getSafeTimers, createDefer, format, isObject, objDisplay, objectAttr, noop, toArray, shuffle } from '@vitest/utils';
|
3
3
|
import { processError } from '@vitest/utils/error';
|
4
4
|
export { processError } from '@vitest/utils/error';
|
5
5
|
import { createChainable, generateHash, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, partitionSuiteChildren, hasTests, hasFailed } from './utils.js';
|
@@ -135,41 +135,34 @@ function withFixtures(fn, testContext) {
|
|
135
135
|
const pendingFixtures = resolveDeps(usedFixtures);
|
136
136
|
if (!pendingFixtures.length)
|
137
137
|
return fn(context);
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
if (
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
138
|
+
async function resolveFixtures() {
|
139
|
+
for (const fixture of pendingFixtures) {
|
140
|
+
if (fixtureValueMap.has(fixture))
|
141
|
+
continue;
|
142
|
+
let resolvedValue;
|
143
|
+
if (fixture.isFn) {
|
144
|
+
const useFnArgPromise = createDefer();
|
145
|
+
const fixtureReturn = fixture.value(context, async (useFnArg) => {
|
146
|
+
useFnArgPromise.resolve(useFnArg);
|
147
|
+
const useReturnPromise = createDefer();
|
148
|
+
cleanupFnArray.push(async () => {
|
149
|
+
useReturnPromise.resolve();
|
150
|
+
await fixtureReturn;
|
151
|
+
});
|
152
|
+
await useReturnPromise;
|
153
|
+
}).catch(useFnArgPromise.reject);
|
154
|
+
resolvedValue = await useFnArgPromise;
|
151
155
|
} else {
|
152
|
-
|
153
|
-
resolve(await fn(context));
|
154
|
-
} catch (err) {
|
155
|
-
reject(err);
|
156
|
-
}
|
157
|
-
return new Promise((resolve2) => {
|
158
|
-
cleanupFnArray.push(resolve2);
|
159
|
-
});
|
156
|
+
resolvedValue = fixture.value;
|
160
157
|
}
|
158
|
+
context[fixture.prop] = resolvedValue;
|
159
|
+
fixtureValueMap.set(fixture, resolvedValue);
|
160
|
+
cleanupFnArray.unshift(() => {
|
161
|
+
fixtureValueMap.delete(fixture);
|
162
|
+
});
|
161
163
|
}
|
162
|
-
|
163
|
-
|
164
|
-
const { isFn, value } = fixture;
|
165
|
-
if (fixtureValueMap.has(fixture))
|
166
|
-
return use(fixtureValueMap.get(fixture));
|
167
|
-
else
|
168
|
-
return isFn ? value(context, use) : use(value);
|
169
|
-
}
|
170
|
-
const setupFixturePromise = next().catch(reject);
|
171
|
-
cleanupFnArray.unshift(() => setupFixturePromise);
|
172
|
-
});
|
164
|
+
}
|
165
|
+
return resolveFixtures().then(() => fn(context));
|
173
166
|
};
|
174
167
|
}
|
175
168
|
function resolveDeps(fixtures, depSet = /* @__PURE__ */ new Set(), pendingFixtures = []) {
|
@@ -181,7 +174,7 @@ function resolveDeps(fixtures, depSet = /* @__PURE__ */ new Set(), pendingFixtur
|
|
181
174
|
return;
|
182
175
|
}
|
183
176
|
if (depSet.has(fixture))
|
184
|
-
throw new Error(
|
177
|
+
throw new Error(`Circular fixture dependency detected: ${fixture.prop} <- ${[...depSet].reverse().map((d) => d.prop).join(" <- ")}`);
|
185
178
|
depSet.add(fixture);
|
186
179
|
resolveDeps(fixture.deps, depSet, pendingFixtures);
|
187
180
|
pendingFixtures.push(fixture);
|
@@ -198,14 +191,14 @@ function getUsedProps(fn) {
|
|
198
191
|
return [];
|
199
192
|
const first = args[0];
|
200
193
|
if (!(first.startsWith("{") && first.endsWith("}")))
|
201
|
-
throw new Error(
|
194
|
+
throw new Error(`The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "${first}".`);
|
202
195
|
const _first = first.slice(1, -1).replace(/\s/g, "");
|
203
196
|
const props = splitByComma(_first).map((prop) => {
|
204
197
|
return prop.replace(/\:.*|\=.*/g, "");
|
205
198
|
});
|
206
199
|
const last = props.at(-1);
|
207
200
|
if (last && last.startsWith("..."))
|
208
|
-
throw new Error(
|
201
|
+
throw new Error(`Rest parameters are not supported in fixtures, received "${last}".`);
|
209
202
|
return props;
|
210
203
|
}
|
211
204
|
function splitByComma(s) {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/runner",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.0.
|
4
|
+
"version": "1.0.3",
|
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": "^5.0.0",
|
42
42
|
"pathe": "^1.1.1",
|
43
|
-
"@vitest/utils": "1.0.
|
43
|
+
"@vitest/utils": "1.0.3"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"build": "rimraf dist && rollup -c",
|