@storybook/addon-vitest 0.0.0-pr-32717-sha-47ba2989 → 0.0.0-pr-32795-sha-81cf1f23
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/_browser-chunks/chunk-ULSHVN74.js +60 -0
- package/dist/_node-chunks/chunk-43MIUCD6.js +138 -0
- package/dist/_node-chunks/{chunk-FXNIGN3F.js → chunk-KCHXXKAS.js} +15 -24
- package/dist/_node-chunks/{chunk-C2FSHTUD.js → chunk-ML5LEYEM.js} +14 -19
- package/dist/_node-chunks/chunk-NCYNCIBX.js +1697 -0
- package/dist/_node-chunks/chunk-NSF3UF7J.js +339 -0
- package/dist/_node-chunks/chunk-PYDFQUST.js +35 -0
- package/dist/_node-chunks/chunk-XTWQR354.js +69 -0
- package/dist/_node-chunks/chunk-ZI6UZG2P.js +83 -0
- package/dist/index.js +1 -5
- package/dist/manager.js +163 -354
- package/dist/node/coverage-reporter.js +319 -864
- package/dist/node/vitest.js +190 -466
- package/dist/postinstall.js +633 -1276
- package/dist/preset.js +160 -354
- package/dist/vitest-plugin/global-setup.js +51 -105
- package/dist/vitest-plugin/index.js +1161 -2381
- package/dist/vitest-plugin/setup-file.js +6 -12
- package/dist/vitest-plugin/test-utils.js +31 -71
- package/package.json +7 -3
- package/dist/_browser-chunks/chunk-JK72E6FR.js +0 -6
- package/dist/_browser-chunks/chunk-RPDOPHZX.js +0 -77
- package/dist/_node-chunks/chunk-26QD4KIO.js +0 -247
- package/dist/_node-chunks/chunk-2JQWJGRS.js +0 -60
- package/dist/_node-chunks/chunk-45MCYOUJ.js +0 -40
- package/dist/_node-chunks/chunk-4H2GO2UY.js +0 -260
- package/dist/_node-chunks/chunk-BRIC3JT4.js +0 -92
- package/dist/_node-chunks/chunk-L2XD2AHB.js +0 -502
- package/dist/_node-chunks/chunk-MYOIMEAF.js +0 -69
package/dist/node/vitest.js
CHANGED
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_75ibbepv58q from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_75ibbepv58q from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_75ibbepv58q from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_75ibbepv58q.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_75ibbepv58q.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_75ibbepv58q.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
12
|
import {
|
|
13
13
|
log
|
|
14
|
-
} from "../_node-chunks/chunk-
|
|
14
|
+
} from "../_node-chunks/chunk-PYDFQUST.js";
|
|
15
15
|
import {
|
|
16
|
-
any
|
|
17
|
-
|
|
16
|
+
any,
|
|
17
|
+
errorToErrorLike
|
|
18
|
+
} from "../_node-chunks/chunk-XTWQR354.js";
|
|
18
19
|
import {
|
|
19
20
|
ADDON_ID,
|
|
20
21
|
COVERAGE_DIRECTORY,
|
|
21
22
|
STATUS_TYPE_ID_A11Y,
|
|
22
23
|
STATUS_TYPE_ID_COMPONENT_TEST,
|
|
23
24
|
storeOptions
|
|
24
|
-
} from "../_node-chunks/chunk-
|
|
25
|
-
import "../_node-chunks/chunk-
|
|
25
|
+
} from "../_node-chunks/chunk-ZI6UZG2P.js";
|
|
26
|
+
import "../_node-chunks/chunk-KCHXXKAS.js";
|
|
26
27
|
import {
|
|
27
28
|
dirname,
|
|
28
29
|
join,
|
|
29
30
|
normalize,
|
|
30
31
|
path
|
|
31
|
-
} from "../_node-chunks/chunk-
|
|
32
|
-
import
|
|
33
|
-
__name
|
|
34
|
-
} from "../_node-chunks/chunk-C2FSHTUD.js";
|
|
32
|
+
} from "../_node-chunks/chunk-43MIUCD6.js";
|
|
33
|
+
import "../_node-chunks/chunk-ML5LEYEM.js";
|
|
35
34
|
|
|
36
35
|
// src/node/vitest.ts
|
|
37
36
|
import process2 from "node:process";
|
|
@@ -44,85 +43,41 @@ import {
|
|
|
44
43
|
|
|
45
44
|
// ../../node_modules/es-toolkit/dist/function/debounce.mjs
|
|
46
45
|
function debounce(func, debounceMs, { signal, edges } = {}) {
|
|
47
|
-
let pendingThis =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
pendingThis = void 0;
|
|
55
|
-
pendingArgs = null;
|
|
56
|
-
}
|
|
57
|
-
}, "invoke");
|
|
58
|
-
const onTimerEnd = /* @__PURE__ */ __name(() => {
|
|
59
|
-
if (trailing) {
|
|
60
|
-
invoke();
|
|
61
|
-
}
|
|
62
|
-
cancel();
|
|
63
|
-
}, "onTimerEnd");
|
|
64
|
-
let timeoutId = null;
|
|
65
|
-
const schedule = /* @__PURE__ */ __name(() => {
|
|
66
|
-
if (timeoutId != null) {
|
|
67
|
-
clearTimeout(timeoutId);
|
|
68
|
-
}
|
|
69
|
-
timeoutId = setTimeout(() => {
|
|
70
|
-
timeoutId = null;
|
|
71
|
-
onTimerEnd();
|
|
46
|
+
let pendingThis, pendingArgs = null, leading = edges != null && edges.includes("leading"), trailing = edges == null || edges.includes("trailing"), invoke = () => {
|
|
47
|
+
pendingArgs !== null && (func.apply(pendingThis, pendingArgs), pendingThis = void 0, pendingArgs = null);
|
|
48
|
+
}, onTimerEnd = () => {
|
|
49
|
+
trailing && invoke(), cancel();
|
|
50
|
+
}, timeoutId = null, schedule = () => {
|
|
51
|
+
timeoutId != null && clearTimeout(timeoutId), timeoutId = setTimeout(() => {
|
|
52
|
+
timeoutId = null, onTimerEnd();
|
|
72
53
|
}, debounceMs);
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
}, "cancelTimer");
|
|
80
|
-
const cancel = /* @__PURE__ */ __name(() => {
|
|
81
|
-
cancelTimer();
|
|
82
|
-
pendingThis = void 0;
|
|
83
|
-
pendingArgs = null;
|
|
84
|
-
}, "cancel");
|
|
85
|
-
const flush = /* @__PURE__ */ __name(() => {
|
|
54
|
+
}, cancelTimer = () => {
|
|
55
|
+
timeoutId !== null && (clearTimeout(timeoutId), timeoutId = null);
|
|
56
|
+
}, cancel = () => {
|
|
57
|
+
cancelTimer(), pendingThis = void 0, pendingArgs = null;
|
|
58
|
+
}, flush = () => {
|
|
86
59
|
invoke();
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
if (signal?.aborted) {
|
|
60
|
+
}, debounced = function(...args) {
|
|
61
|
+
if (signal?.aborted)
|
|
90
62
|
return;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (leading && isFirstCall) {
|
|
97
|
-
invoke();
|
|
98
|
-
}
|
|
99
|
-
}, "debounced");
|
|
100
|
-
debounced.schedule = schedule;
|
|
101
|
-
debounced.cancel = cancel;
|
|
102
|
-
debounced.flush = flush;
|
|
103
|
-
signal?.addEventListener("abort", cancel, { once: true });
|
|
104
|
-
return debounced;
|
|
63
|
+
pendingThis = this, pendingArgs = args;
|
|
64
|
+
let isFirstCall = timeoutId == null;
|
|
65
|
+
schedule(), leading && isFirstCall && invoke();
|
|
66
|
+
};
|
|
67
|
+
return debounced.schedule = schedule, debounced.cancel = cancel, debounced.flush = flush, signal?.addEventListener("abort", cancel, { once: !0 }), debounced;
|
|
105
68
|
}
|
|
106
|
-
__name(debounce, "debounce");
|
|
107
69
|
|
|
108
70
|
// ../../node_modules/es-toolkit/dist/function/partial.mjs
|
|
109
71
|
function partial(func, ...partialArgs) {
|
|
110
72
|
return partialImpl(func, placeholderSymbol, ...partialArgs);
|
|
111
73
|
}
|
|
112
|
-
__name(partial, "partial");
|
|
113
74
|
function partialImpl(func, placeholder, ...partialArgs) {
|
|
114
|
-
|
|
115
|
-
let providedArgsIndex = 0;
|
|
116
|
-
const substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg);
|
|
117
|
-
const remainingArgs = providedArgs.slice(providedArgsIndex);
|
|
75
|
+
let partialed = function(...providedArgs) {
|
|
76
|
+
let providedArgsIndex = 0, substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg), remainingArgs = providedArgs.slice(providedArgsIndex);
|
|
118
77
|
return func.apply(this, substitutedArgs.concat(remainingArgs));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
partialed.prototype = Object.create(func.prototype);
|
|
122
|
-
}
|
|
123
|
-
return partialed;
|
|
78
|
+
};
|
|
79
|
+
return func.prototype && (partialed.prototype = Object.create(func.prototype)), partialed;
|
|
124
80
|
}
|
|
125
|
-
__name(partialImpl, "partialImpl");
|
|
126
81
|
var placeholderSymbol = Symbol("partial.placeholder");
|
|
127
82
|
partial.placeholder = placeholderSymbol;
|
|
128
83
|
|
|
@@ -130,22 +85,13 @@ partial.placeholder = placeholderSymbol;
|
|
|
130
85
|
function partialRight(func, ...partialArgs) {
|
|
131
86
|
return partialRightImpl(func, placeholderSymbol2, ...partialArgs);
|
|
132
87
|
}
|
|
133
|
-
__name(partialRight, "partialRight");
|
|
134
88
|
function partialRightImpl(func, placeholder, ...partialArgs) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
|
|
138
|
-
const remainingArgs = providedArgs.slice(0, rangeLength);
|
|
139
|
-
let providedArgsIndex = rangeLength;
|
|
140
|
-
const substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg);
|
|
89
|
+
let partialedRight = function(...providedArgs) {
|
|
90
|
+
let placeholderLength = partialArgs.filter((arg) => arg === placeholder).length, rangeLength = Math.max(providedArgs.length - placeholderLength, 0), remainingArgs = providedArgs.slice(0, rangeLength), providedArgsIndex = rangeLength, substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg);
|
|
141
91
|
return func.apply(this, remainingArgs.concat(substitutedArgs));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
partialedRight.prototype = Object.create(func.prototype);
|
|
145
|
-
}
|
|
146
|
-
return partialedRight;
|
|
92
|
+
};
|
|
93
|
+
return func.prototype && (partialedRight.prototype = Object.create(func.prototype)), partialedRight;
|
|
147
94
|
}
|
|
148
|
-
__name(partialRightImpl, "partialRightImpl");
|
|
149
95
|
var placeholderSymbol2 = Symbol("partialRight.placeholder");
|
|
150
96
|
partialRight.placeholder = placeholderSymbol2;
|
|
151
97
|
|
|
@@ -154,36 +100,11 @@ var DEFAULT_RETRIES = Number.POSITIVE_INFINITY;
|
|
|
154
100
|
|
|
155
101
|
// ../../node_modules/es-toolkit/dist/function/throttle.mjs
|
|
156
102
|
function throttle(func, throttleMs, { signal, edges = ["leading", "trailing"] } = {}) {
|
|
157
|
-
let pendingAt = null
|
|
158
|
-
|
|
159
|
-
const throttled = /* @__PURE__ */ __name(function(...args) {
|
|
160
|
-
if (pendingAt == null) {
|
|
161
|
-
pendingAt = Date.now();
|
|
162
|
-
} else {
|
|
163
|
-
if (Date.now() - pendingAt >= throttleMs) {
|
|
164
|
-
pendingAt = Date.now();
|
|
165
|
-
debounced.cancel();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
debounced.apply(this, args);
|
|
169
|
-
}, "throttled");
|
|
170
|
-
throttled.cancel = debounced.cancel;
|
|
171
|
-
throttled.flush = debounced.flush;
|
|
172
|
-
return throttled;
|
|
173
|
-
}
|
|
174
|
-
__name(throttle, "throttle");
|
|
175
|
-
|
|
176
|
-
// src/utils.ts
|
|
177
|
-
function errorToErrorLike(error) {
|
|
178
|
-
return {
|
|
179
|
-
message: error.message,
|
|
180
|
-
name: error.name,
|
|
181
|
-
// avoid duplicating the error message in the stack trace
|
|
182
|
-
stack: error.stack?.replace(error.message, ""),
|
|
183
|
-
cause: error.cause && error.cause instanceof Error ? errorToErrorLike(error.cause) : void 0
|
|
103
|
+
let pendingAt = null, debounced = debounce(func, throttleMs, { signal, edges }), throttled = function(...args) {
|
|
104
|
+
pendingAt == null ? pendingAt = Date.now() : Date.now() - pendingAt >= throttleMs && (pendingAt = Date.now(), debounced.cancel()), debounced.apply(this, args);
|
|
184
105
|
};
|
|
106
|
+
return throttled.cancel = debounced.cancel, throttled.flush = debounced.flush, throttled;
|
|
185
107
|
}
|
|
186
|
-
__name(errorToErrorLike, "errorToErrorLike");
|
|
187
108
|
|
|
188
109
|
// src/node/vitest-manager.ts
|
|
189
110
|
import { existsSync } from "node:fs";
|
|
@@ -191,28 +112,19 @@ import { getProjectRoot, resolvePathInStorybookCache } from "storybook/internal/
|
|
|
191
112
|
|
|
192
113
|
// ../../node_modules/slash/index.js
|
|
193
114
|
function slash(path2) {
|
|
194
|
-
|
|
195
|
-
if (isExtendedLengthPath) {
|
|
196
|
-
return path2;
|
|
197
|
-
}
|
|
198
|
-
return path2.replace(/\\/g, "/");
|
|
115
|
+
return path2.startsWith("\\\\?\\") ? path2 : path2.replace(/\\/g, "/");
|
|
199
116
|
}
|
|
200
|
-
__name(slash, "slash");
|
|
201
117
|
|
|
202
118
|
// src/node/reporter.ts
|
|
203
119
|
var StorybookReporter = class {
|
|
204
120
|
constructor(testManager) {
|
|
205
121
|
this.testManager = testManager;
|
|
206
122
|
}
|
|
207
|
-
static {
|
|
208
|
-
__name(this, "StorybookReporter");
|
|
209
|
-
}
|
|
210
123
|
onInit(ctx) {
|
|
211
124
|
this.ctx = ctx;
|
|
212
125
|
}
|
|
213
126
|
onTestCaseResult(testCase) {
|
|
214
|
-
|
|
215
|
-
const testResult = testCase.result();
|
|
127
|
+
let { storyId, reports } = testCase.meta(), testResult = testCase.result();
|
|
216
128
|
this.testManager.onTestCaseResult({
|
|
217
129
|
storyId,
|
|
218
130
|
testResult,
|
|
@@ -220,42 +132,30 @@ var StorybookReporter = class {
|
|
|
220
132
|
});
|
|
221
133
|
}
|
|
222
134
|
async onTestRunEnd(testModules, unhandledErrors) {
|
|
223
|
-
|
|
135
|
+
let totalTestCount = testModules.flatMap(
|
|
224
136
|
(t) => Array.from(t.children.allTests("passed")).concat(Array.from(t.children.allTests("failed")))
|
|
225
|
-
).length
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
stack: e.stack?.replace(e.message, ""),
|
|
233
|
-
cause: e.cause
|
|
234
|
-
};
|
|
235
|
-
});
|
|
137
|
+
).length, testModulesErrors = testModules.flatMap((t) => t.errors()), serializedErrors = unhandledErrors.concat(testModulesErrors).map((e) => ({
|
|
138
|
+
...e,
|
|
139
|
+
name: e.name,
|
|
140
|
+
message: e.message,
|
|
141
|
+
stack: e.stack?.replace(e.message, ""),
|
|
142
|
+
cause: e.cause
|
|
143
|
+
}));
|
|
236
144
|
this.testManager.onTestRunEnd({
|
|
237
145
|
totalTestCount,
|
|
238
146
|
unhandledErrors: serializedErrors
|
|
239
|
-
});
|
|
240
|
-
this.clearVitestState();
|
|
147
|
+
}), this.clearVitestState();
|
|
241
148
|
}
|
|
242
149
|
// TODO: Clearing the whole internal state of Vitest might be too aggressive
|
|
243
150
|
async clearVitestState() {
|
|
244
|
-
this.ctx.state.filesMap.clear();
|
|
245
|
-
this.ctx.state.pathsSet.clear();
|
|
246
|
-
this.ctx.state.idMap.clear();
|
|
247
|
-
this.ctx.state.errorsSet.clear();
|
|
248
|
-
this.ctx.state.processTimeoutCauses?.clear();
|
|
151
|
+
this.ctx.state.filesMap.clear(), this.ctx.state.pathsSet.clear(), this.ctx.state.idMap.clear(), this.ctx.state.errorsSet.clear(), this.ctx.state.processTimeoutCauses?.clear();
|
|
249
152
|
}
|
|
250
153
|
};
|
|
251
154
|
|
|
252
155
|
// src/node/vitest-manager.ts
|
|
253
|
-
var VITEST_CONFIG_FILE_EXTENSIONS = ["mts", "mjs", "cts", "cjs", "ts", "tsx", "js", "jsx"];
|
|
254
|
-
var VITEST_WORKSPACE_FILE_EXTENSION = ["ts", "js", "json"];
|
|
156
|
+
var VITEST_CONFIG_FILE_EXTENSIONS = ["mts", "mjs", "cts", "cjs", "ts", "tsx", "js", "jsx"], VITEST_WORKSPACE_FILE_EXTENSION = ["ts", "js", "json"];
|
|
255
157
|
process.env.VITEST_STORYBOOK = "true";
|
|
256
|
-
var DOUBLE_SPACES = " "
|
|
257
|
-
var getTestName = /* @__PURE__ */ __name((name) => `${name}${DOUBLE_SPACES}`, "getTestName");
|
|
258
|
-
var VitestManager = class {
|
|
158
|
+
var DOUBLE_SPACES = " ", getTestName = (name) => `${name}${DOUBLE_SPACES}`, VitestManager = class {
|
|
259
159
|
constructor(testManager) {
|
|
260
160
|
this.testManager = testManager;
|
|
261
161
|
this.vitest = null;
|
|
@@ -263,39 +163,32 @@ var VitestManager = class {
|
|
|
263
163
|
this.vitestRestartPromise = null;
|
|
264
164
|
this.runningPromise = null;
|
|
265
165
|
}
|
|
266
|
-
static {
|
|
267
|
-
__name(this, "VitestManager");
|
|
268
|
-
}
|
|
269
166
|
async startVitest({ coverage }) {
|
|
270
|
-
|
|
271
|
-
const storybookCoverageReporter = [
|
|
167
|
+
let { createVitest } = await import("vitest/node"), storybookCoverageReporter = [
|
|
272
168
|
"@storybook/addon-vitest/internal/coverage-reporter",
|
|
273
169
|
{
|
|
274
170
|
testManager: this.testManager,
|
|
275
171
|
coverageOptions: this.vitest?.config?.coverage
|
|
276
172
|
}
|
|
277
|
-
]
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
reportOnFailure: true,
|
|
173
|
+
], coverageOptions = coverage ? {
|
|
174
|
+
enabled: !0,
|
|
175
|
+
clean: !0,
|
|
176
|
+
cleanOnRerun: !0,
|
|
177
|
+
reportOnFailure: !0,
|
|
283
178
|
reporter: [["html", {}], storybookCoverageReporter],
|
|
284
179
|
reportsDirectory: resolvePathInStorybookCache(COVERAGE_DIRECTORY)
|
|
285
|
-
} : { enabled:
|
|
286
|
-
const vitestWorkspaceConfig = any(
|
|
180
|
+
} : { enabled: !1 }, vitestWorkspaceConfig = any(
|
|
287
181
|
[
|
|
288
182
|
...VITEST_WORKSPACE_FILE_EXTENSION.map((ext) => `vitest.workspace.${ext}`),
|
|
289
183
|
...VITEST_CONFIG_FILE_EXTENSIONS.map((ext) => `vitest.config.${ext}`)
|
|
290
184
|
],
|
|
291
185
|
{ last: getProjectRoot() }
|
|
292
|
-
);
|
|
293
|
-
const projectName = "storybook:" + process.env.STORYBOOK_CONFIG_DIR;
|
|
186
|
+
), projectName = "storybook:" + process.env.STORYBOOK_CONFIG_DIR;
|
|
294
187
|
try {
|
|
295
188
|
this.vitest = await createVitest("test", {
|
|
296
189
|
root: vitestWorkspaceConfig ? dirname(vitestWorkspaceConfig) : process.cwd(),
|
|
297
|
-
watch:
|
|
298
|
-
passWithNoTests:
|
|
190
|
+
watch: !0,
|
|
191
|
+
passWithNoTests: !1,
|
|
299
192
|
project: [projectName],
|
|
300
193
|
// TODO:
|
|
301
194
|
// Do we want to enable Vite's default reporter?
|
|
@@ -306,176 +199,104 @@ var VitestManager = class {
|
|
|
306
199
|
coverage: coverageOptions
|
|
307
200
|
});
|
|
308
201
|
} catch (err) {
|
|
309
|
-
|
|
202
|
+
let originalMessage = String(err.message);
|
|
310
203
|
if (originalMessage.includes("Found multiple projects")) {
|
|
311
|
-
|
|
204
|
+
let custom = [
|
|
312
205
|
"Storybook was unable to start the test run because you have multiple Vitest projects (or browsers) in headed mode.",
|
|
313
206
|
"Please set `headless: true` in your Storybook vitest config.\n\n"
|
|
314
|
-
].join(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
207
|
+
].join(`
|
|
208
|
+
`);
|
|
209
|
+
originalMessage.startsWith(custom) || (err.message = `${custom}${originalMessage}`);
|
|
318
210
|
}
|
|
319
211
|
throw err;
|
|
320
212
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
});
|
|
324
|
-
}
|
|
213
|
+
this.vitest && this.vitest.onCancel(() => {
|
|
214
|
+
});
|
|
325
215
|
try {
|
|
326
216
|
await this.vitest.init();
|
|
327
217
|
} catch (e) {
|
|
328
|
-
let message = "Failed to initialize Vitest";
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (e.message?.includes("Failed to load url") && (isIstanbul || isV8) || // Vitest will sometimes not throw the correct missing-package-detection error, so we have to check for this as well
|
|
332
|
-
e instanceof TypeError && e?.message === "Cannot read properties of undefined (reading 'name')") {
|
|
333
|
-
const coveragePackage = isIstanbul ? "coverage-istanbul" : "coverage-v8";
|
|
334
|
-
message += `
|
|
218
|
+
let message = "Failed to initialize Vitest", isV8 = e.message?.includes("@vitest/coverage-v8"), isIstanbul = e.message?.includes("@vitest/coverage-istanbul");
|
|
219
|
+
(e.message?.includes("Failed to load url") && (isIstanbul || isV8) || // Vitest will sometimes not throw the correct missing-package-detection error, so we have to check for this as well
|
|
220
|
+
e instanceof TypeError && e?.message === "Cannot read properties of undefined (reading 'name')") && (message += `
|
|
335
221
|
|
|
336
|
-
Please install the @vitest/${
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
this.testManager.reportFatalError(message, e);
|
|
222
|
+
Please install the @vitest/${isIstanbul ? "coverage-istanbul" : "coverage-v8"} package to collect coverage
|
|
223
|
+
`), this.testManager.reportFatalError(message, e);
|
|
340
224
|
return;
|
|
341
225
|
}
|
|
342
226
|
await this.setupWatchers();
|
|
343
227
|
}
|
|
344
228
|
async restartVitest({ coverage }) {
|
|
345
|
-
await this.vitestRestartPromise
|
|
346
|
-
this.vitestRestartPromise = new Promise(async (resolve, reject) => {
|
|
229
|
+
return await this.vitestRestartPromise, this.vitestRestartPromise = new Promise(async (resolve, reject) => {
|
|
347
230
|
try {
|
|
348
|
-
await this.runningPromise;
|
|
349
|
-
await this.vitest?.close();
|
|
350
|
-
await this.startVitest({ coverage });
|
|
351
|
-
resolve();
|
|
231
|
+
await this.runningPromise, await this.vitest?.close(), await this.startVitest({ coverage }), resolve();
|
|
352
232
|
} catch (e) {
|
|
353
233
|
reject(e);
|
|
354
234
|
} finally {
|
|
355
235
|
this.vitestRestartPromise = null;
|
|
356
236
|
}
|
|
357
|
-
});
|
|
358
|
-
return this.vitestRestartPromise;
|
|
237
|
+
}), this.vitestRestartPromise;
|
|
359
238
|
}
|
|
360
239
|
resetGlobalTestNamePattern() {
|
|
361
240
|
this.vitest?.setGlobalTestNamePattern("");
|
|
362
241
|
}
|
|
363
242
|
updateLastChanged(filepath) {
|
|
364
243
|
this.vitest.projects.forEach(({ browser, vite, server }) => {
|
|
365
|
-
|
|
366
|
-
const serverMods = server.moduleGraph.getModulesByFile(filepath);
|
|
367
|
-
serverMods?.forEach((mod) => server.moduleGraph.invalidateModule(mod));
|
|
368
|
-
}
|
|
369
|
-
if (vite) {
|
|
370
|
-
const serverMods = vite.moduleGraph.getModulesByFile(filepath);
|
|
371
|
-
serverMods?.forEach((mod) => vite.moduleGraph.invalidateModule(mod));
|
|
372
|
-
}
|
|
373
|
-
if (browser) {
|
|
374
|
-
const browserMods = browser.vite.moduleGraph.getModulesByFile(filepath);
|
|
375
|
-
browserMods?.forEach((mod) => browser.vite.moduleGraph.invalidateModule(mod));
|
|
376
|
-
}
|
|
244
|
+
server && server.moduleGraph.getModulesByFile(filepath)?.forEach((mod) => server.moduleGraph.invalidateModule(mod)), vite && vite.moduleGraph.getModulesByFile(filepath)?.forEach((mod) => vite.moduleGraph.invalidateModule(mod)), browser && browser.vite.moduleGraph.getModulesByFile(filepath)?.forEach((mod) => browser.vite.moduleGraph.invalidateModule(mod));
|
|
377
245
|
});
|
|
378
246
|
}
|
|
379
247
|
async fetchStories(requestStoryIds) {
|
|
380
|
-
|
|
381
|
-
if (!indexUrl)
|
|
248
|
+
let indexUrl = this.testManager.store.getState().indexUrl;
|
|
249
|
+
if (!indexUrl)
|
|
382
250
|
throw new Error(
|
|
383
251
|
"Tried to fetch stories to test, but the index URL was not set in the store yet."
|
|
384
252
|
);
|
|
385
|
-
}
|
|
386
253
|
try {
|
|
387
|
-
|
|
254
|
+
let index = await Promise.race([
|
|
388
255
|
fetch(indexUrl).then((res) => res.json()),
|
|
389
256
|
new Promise((_, reject) => setTimeout(reject, 3e3, new Error("Request took too long")))
|
|
390
257
|
]);
|
|
391
|
-
|
|
392
|
-
return storyIds.map((id) => index.entries[id]).filter((story) => story.type === "story");
|
|
258
|
+
return (requestStoryIds || Object.keys(index.entries)).map((id) => index.entries[id]).filter((story) => story.type === "story");
|
|
393
259
|
} catch (e) {
|
|
394
|
-
log("Failed to fetch story index: " + e.message);
|
|
395
|
-
return [];
|
|
260
|
+
return log("Failed to fetch story index: " + e.message), [];
|
|
396
261
|
}
|
|
397
262
|
}
|
|
398
263
|
filterTestSpecifications(testSpecifications, stories) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const absoluteImportPath = path.join(process.cwd(), story.importPath);
|
|
404
|
-
if (!storiesByImportPath[absoluteImportPath]) {
|
|
405
|
-
storiesByImportPath[absoluteImportPath] = [];
|
|
406
|
-
}
|
|
407
|
-
storiesByImportPath[absoluteImportPath].push(story);
|
|
264
|
+
let filteredTestSpecifications = [], filteredStoryIds = [], storiesByImportPath = {};
|
|
265
|
+
for (let story of stories) {
|
|
266
|
+
let absoluteImportPath = path.join(process.cwd(), story.importPath);
|
|
267
|
+
storiesByImportPath[absoluteImportPath] || (storiesByImportPath[absoluteImportPath] = []), storiesByImportPath[absoluteImportPath].push(story);
|
|
408
268
|
}
|
|
409
|
-
for (
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
const exclude = env.__VITEST_EXCLUDE_TAGS__?.split(",").filter(Boolean) ?? [];
|
|
413
|
-
const skip = env.__VITEST_SKIP_TAGS__?.split(",").filter(Boolean) ?? [];
|
|
414
|
-
const storiesInTestSpecification = storiesByImportPath[testSpecification.moduleId] ?? [];
|
|
415
|
-
const filteredStories = storiesInTestSpecification.filter((story) => {
|
|
416
|
-
if (include.length && !include.some((tag) => story.tags?.includes(tag))) {
|
|
417
|
-
return false;
|
|
418
|
-
}
|
|
419
|
-
if (exclude.some((tag) => story.tags?.includes(tag))) {
|
|
420
|
-
return false;
|
|
421
|
-
}
|
|
422
|
-
return true;
|
|
423
|
-
});
|
|
424
|
-
if (!filteredStories.length) {
|
|
425
|
-
continue;
|
|
426
|
-
}
|
|
427
|
-
if (!this.testManager.store.getState().watching) {
|
|
428
|
-
this.updateLastChanged(testSpecification.moduleId);
|
|
429
|
-
}
|
|
430
|
-
filteredTestSpecifications.push(testSpecification);
|
|
431
|
-
filteredStoryIds.push(
|
|
269
|
+
for (let testSpecification of testSpecifications) {
|
|
270
|
+
let { env = {} } = testSpecification.project.config, include = env.__VITEST_INCLUDE_TAGS__?.split(",").filter(Boolean) ?? ["test"], exclude = env.__VITEST_EXCLUDE_TAGS__?.split(",").filter(Boolean) ?? [], skip = env.__VITEST_SKIP_TAGS__?.split(",").filter(Boolean) ?? [], filteredStories = (storiesByImportPath[testSpecification.moduleId] ?? []).filter((story) => !(include.length && !include.some((tag) => story.tags?.includes(tag)) || exclude.some((tag) => story.tags?.includes(tag))));
|
|
271
|
+
filteredStories.length && (this.testManager.store.getState().watching || this.updateLastChanged(testSpecification.moduleId), filteredTestSpecifications.push(testSpecification), filteredStoryIds.push(
|
|
432
272
|
...filteredStories.filter((story) => !skip.some((tag) => story.tags?.includes(tag))).map((story) => story.id)
|
|
433
|
-
);
|
|
273
|
+
));
|
|
434
274
|
}
|
|
435
275
|
return { filteredTestSpecifications, filteredStoryIds };
|
|
436
276
|
}
|
|
437
277
|
async runTests(runPayload) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
if (
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
await this.restartVitest({ coverage: coverageShouldBeEnabled });
|
|
445
|
-
} else {
|
|
446
|
-
await this.vitestRestartPromise;
|
|
447
|
-
}
|
|
448
|
-
this.resetGlobalTestNamePattern();
|
|
449
|
-
await this.cancelCurrentRun();
|
|
450
|
-
const testSpecifications = await this.getStorybookTestSpecifications();
|
|
451
|
-
const allStories = await this.fetchStories();
|
|
452
|
-
const filteredStories = runPayload.storyIds ? allStories.filter((story) => runPayload.storyIds?.includes(story.id)) : allStories;
|
|
453
|
-
const isSingleStoryRun = runPayload.storyIds?.length === 1;
|
|
454
|
-
if (isSingleStoryRun) {
|
|
455
|
-
const selectedStory = filteredStories.find((story) => story.id === runPayload.storyIds?.[0]);
|
|
456
|
-
if (!selectedStory) {
|
|
278
|
+
let { watching, config } = this.testManager.store.getState(), coverageShouldBeEnabled = config.coverage && !watching && (runPayload?.storyIds?.length ?? 0) === 0, currentCoverage = this.vitest?.config.coverage?.enabled;
|
|
279
|
+
this.vitest ? currentCoverage !== coverageShouldBeEnabled ? await this.restartVitest({ coverage: coverageShouldBeEnabled }) : await this.vitestRestartPromise : await this.startVitest({ coverage: coverageShouldBeEnabled }), this.resetGlobalTestNamePattern(), await this.cancelCurrentRun();
|
|
280
|
+
let testSpecifications = await this.getStorybookTestSpecifications(), allStories = await this.fetchStories(), filteredStories = runPayload.storyIds ? allStories.filter((story) => runPayload.storyIds?.includes(story.id)) : allStories;
|
|
281
|
+
if (runPayload.storyIds?.length === 1) {
|
|
282
|
+
let selectedStory = filteredStories.find((story) => story.id === runPayload.storyIds?.[0]);
|
|
283
|
+
if (!selectedStory)
|
|
457
284
|
throw new Error(`Story ${runPayload.storyIds?.[0]} not found`);
|
|
458
|
-
|
|
459
|
-
const storyName = selectedStory.name;
|
|
460
|
-
let regex;
|
|
461
|
-
const isParentStory = allStories.some((story) => selectedStory.id === story.parent);
|
|
462
|
-
const hasParentStory = allStories.some((story) => selectedStory.parent === story.id);
|
|
285
|
+
let storyName = selectedStory.name, regex, isParentStory = allStories.some((story) => selectedStory.id === story.parent), hasParentStory = allStories.some((story) => selectedStory.parent === story.id);
|
|
463
286
|
if (isParentStory) {
|
|
464
|
-
|
|
287
|
+
let parentName = getTestName(selectedStory.name);
|
|
465
288
|
regex = new RegExp(`^${parentName}`);
|
|
466
289
|
} else if (hasParentStory) {
|
|
467
|
-
|
|
468
|
-
if (!parentStory)
|
|
290
|
+
let parentStory = allStories.find((story) => story.id === selectedStory.parent);
|
|
291
|
+
if (!parentStory)
|
|
469
292
|
throw new Error(`Parent story not found for story ${selectedStory.id}`);
|
|
470
|
-
|
|
471
|
-
const parentName = getTestName(parentStory.name);
|
|
293
|
+
let parentName = getTestName(parentStory.name);
|
|
472
294
|
regex = new RegExp(`^${parentName} ${storyName}$`);
|
|
473
|
-
} else
|
|
295
|
+
} else
|
|
474
296
|
regex = new RegExp(`^${storyName}$`);
|
|
475
|
-
}
|
|
476
297
|
this.vitest.setGlobalTestNamePattern(regex);
|
|
477
298
|
}
|
|
478
|
-
|
|
299
|
+
let { filteredTestSpecifications, filteredStoryIds } = this.filterTestSpecifications(
|
|
479
300
|
testSpecifications,
|
|
480
301
|
filteredStories
|
|
481
302
|
);
|
|
@@ -485,138 +306,92 @@ Please install the @vitest/${coveragePackage} package to collect coverage
|
|
|
485
306
|
...s.currentRun,
|
|
486
307
|
totalTestCount: filteredStoryIds.length
|
|
487
308
|
}
|
|
488
|
-
}));
|
|
489
|
-
await this.vitest.runTestSpecifications(filteredTestSpecifications, true);
|
|
490
|
-
this.resetGlobalTestNamePattern();
|
|
309
|
+
})), await this.vitest.runTestSpecifications(filteredTestSpecifications, !0), this.resetGlobalTestNamePattern();
|
|
491
310
|
}
|
|
492
311
|
async cancelCurrentRun() {
|
|
493
|
-
await this.vitest?.cancelCurrentRun("keyboard-input");
|
|
494
|
-
await this.runningPromise;
|
|
312
|
+
await this.vitest?.cancelCurrentRun("keyboard-input"), await this.runningPromise;
|
|
495
313
|
}
|
|
496
314
|
async getStorybookTestSpecifications() {
|
|
497
|
-
|
|
498
|
-
return globTestSpecifications.filter(
|
|
315
|
+
return (await this.vitest?.globTestSpecifications() ?? []).filter(
|
|
499
316
|
(workspaceSpec) => this.isStorybookProject(workspaceSpec.project)
|
|
500
317
|
) ?? [];
|
|
501
318
|
}
|
|
502
319
|
async runAffectedTestsAfterChange(changedFilePath, event) {
|
|
503
|
-
|
|
504
|
-
this.vitest?.logger.clearHighlightCache(id)
|
|
505
|
-
this.updateLastChanged(id);
|
|
506
|
-
if (event === "add") {
|
|
507
|
-
const project = this.vitest?.projects.find(this.isStorybookProject.bind(this));
|
|
508
|
-
project?.matchesTestGlob(id);
|
|
509
|
-
}
|
|
510
|
-
if (!this.testManager.store.getState().watching) {
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
if (!this.vitest) {
|
|
320
|
+
let id = slash(changedFilePath);
|
|
321
|
+
if (this.vitest?.logger.clearHighlightCache(id), this.updateLastChanged(id), event === "add" && this.vitest?.projects.find(this.isStorybookProject.bind(this))?.matchesTestGlob(id), !this.testManager.store.getState().watching || !this.vitest)
|
|
514
322
|
return;
|
|
515
|
-
}
|
|
516
323
|
this.resetGlobalTestNamePattern();
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
moduleId: typeof previewAnnotation === "string" ? previewAnnotation : previewAnnotation.absolute
|
|
522
|
-
};
|
|
523
|
-
});
|
|
524
|
-
const setupFilesSpecifications = this.vitest.projects.flatMap(
|
|
324
|
+
let storybookProject = this.vitest.projects.find((p) => this.isStorybookProject(p)), previewAnnotationSpecifications = this.testManager.store.getState().previewAnnotations.map((previewAnnotation) => ({
|
|
325
|
+
project: storybookProject ?? this.vitest.projects[0],
|
|
326
|
+
moduleId: typeof previewAnnotation == "string" ? previewAnnotation : previewAnnotation.absolute
|
|
327
|
+
})), setupFilesSpecifications = this.vitest.projects.flatMap(
|
|
525
328
|
(project) => project.config.setupFiles.map((setupFile) => ({
|
|
526
329
|
project,
|
|
527
330
|
moduleId: setupFile
|
|
528
331
|
}))
|
|
529
|
-
)
|
|
530
|
-
const syntheticGlobalTestSpecifications = previewAnnotationSpecifications.concat(setupFilesSpecifications);
|
|
531
|
-
const testSpecifications = await this.getStorybookTestSpecifications();
|
|
532
|
-
const allStories = await this.fetchStories();
|
|
533
|
-
let affectsGlobalFiles = false;
|
|
534
|
-
const affectedTestSpecifications = (await Promise.all(
|
|
332
|
+
), syntheticGlobalTestSpecifications = previewAnnotationSpecifications.concat(setupFilesSpecifications), testSpecifications = await this.getStorybookTestSpecifications(), allStories = await this.fetchStories(), affectsGlobalFiles = !1, affectedTestSpecifications = (await Promise.all(
|
|
535
333
|
syntheticGlobalTestSpecifications.concat(testSpecifications).map(async (testSpecification) => {
|
|
536
|
-
|
|
537
|
-
if (changedFilePath === testSpecification.moduleId || dependencies.has(changedFilePath))
|
|
538
|
-
|
|
539
|
-
affectsGlobalFiles = true;
|
|
540
|
-
}
|
|
541
|
-
return testSpecification;
|
|
542
|
-
}
|
|
334
|
+
let dependencies = await this.getTestDependencies(testSpecification);
|
|
335
|
+
if (changedFilePath === testSpecification.moduleId || dependencies.has(changedFilePath))
|
|
336
|
+
return syntheticGlobalTestSpecifications.includes(testSpecification) && (affectsGlobalFiles = !0), testSpecification;
|
|
543
337
|
})
|
|
544
|
-
)).filter(Boolean);
|
|
545
|
-
|
|
546
|
-
if (!testSpecificationsToRun.length) {
|
|
338
|
+
)).filter(Boolean), testSpecificationsToRun = affectsGlobalFiles ? testSpecifications : affectedTestSpecifications;
|
|
339
|
+
if (!testSpecificationsToRun.length)
|
|
547
340
|
return;
|
|
548
|
-
}
|
|
549
|
-
const { filteredTestSpecifications, filteredStoryIds } = this.filterTestSpecifications(
|
|
341
|
+
let { filteredTestSpecifications, filteredStoryIds } = this.filterTestSpecifications(
|
|
550
342
|
testSpecificationsToRun,
|
|
551
343
|
allStories
|
|
552
344
|
);
|
|
553
345
|
await this.testManager.runTestsWithState({
|
|
554
346
|
storyIds: filteredStoryIds,
|
|
555
347
|
triggeredBy: "watch",
|
|
556
|
-
callback:
|
|
348
|
+
callback: async () => {
|
|
557
349
|
this.testManager.store.setState((s) => ({
|
|
558
350
|
...s,
|
|
559
351
|
currentRun: {
|
|
560
352
|
...s.currentRun,
|
|
561
353
|
totalTestCount: filteredStoryIds.length
|
|
562
354
|
}
|
|
563
|
-
}));
|
|
564
|
-
|
|
565
|
-
await this.runningPromise;
|
|
566
|
-
await this.vitest.runTestSpecifications(filteredTestSpecifications, false);
|
|
567
|
-
}, "callback")
|
|
355
|
+
})), await this.vitest.cancelCurrentRun("keyboard-input"), await this.runningPromise, await this.vitest.runTestSpecifications(filteredTestSpecifications, !1);
|
|
356
|
+
}
|
|
568
357
|
});
|
|
569
358
|
}
|
|
570
359
|
// This is an adaptation of Vitest's own implementation
|
|
571
360
|
// see https://github.com/vitest-dev/vitest/blob/14409088166152c920ce7fa4ad4c0ba57149b869/packages/vitest/src/node/specifications.ts#L171-L198
|
|
572
361
|
async getTestDependencies(spec) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if (deps.has(filepath)) {
|
|
362
|
+
let deps = /* @__PURE__ */ new Set(), addImports = async (project, filepath) => {
|
|
363
|
+
if (deps.has(filepath))
|
|
576
364
|
return;
|
|
577
|
-
}
|
|
578
365
|
deps.add(filepath);
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
if (!transformed) {
|
|
366
|
+
let transformed = project.vite.moduleGraph.getModuleById(filepath)?.ssrTransformResult || await project.vite.transformRequest(filepath, { ssr: !0 });
|
|
367
|
+
if (!transformed)
|
|
582
368
|
return;
|
|
583
|
-
|
|
584
|
-
const dependencies = [...transformed.deps ?? [], ...transformed.dynamicDeps ?? []];
|
|
369
|
+
let dependencies = [...transformed.deps ?? [], ...transformed.dynamicDeps ?? []];
|
|
585
370
|
await Promise.all(
|
|
586
371
|
dependencies.map(async (dep) => {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
await addImports(project, fsPath);
|
|
590
|
-
}
|
|
372
|
+
let fsPath = dep.startsWith("/@fs/") ? dep.slice(process.platform === "win32" ? 5 : 4) : join(project.config.root, dep);
|
|
373
|
+
!fsPath.includes("node_modules") && !deps.has(fsPath) && existsSync(fsPath) && await addImports(project, fsPath);
|
|
591
374
|
})
|
|
592
375
|
);
|
|
593
|
-
}
|
|
594
|
-
await addImports(spec.project, spec.moduleId);
|
|
595
|
-
deps.delete(spec.moduleId);
|
|
596
|
-
return deps;
|
|
376
|
+
};
|
|
377
|
+
return await addImports(spec.project, spec.moduleId), deps.delete(spec.moduleId), deps;
|
|
597
378
|
}
|
|
598
379
|
async registerVitestConfigListener() {
|
|
599
380
|
this.vitest.vite.watcher.on("change", async (file) => {
|
|
600
|
-
|
|
601
|
-
if (isConfig) {
|
|
381
|
+
if (normalize(file) === this.vitest?.vite?.config.configFile) {
|
|
602
382
|
log("Restarting Vitest due to config change");
|
|
603
|
-
|
|
383
|
+
let { watching, config } = this.testManager.store.getState();
|
|
604
384
|
await this.restartVitest({ coverage: config.coverage && !watching });
|
|
605
385
|
}
|
|
606
386
|
});
|
|
607
387
|
}
|
|
608
388
|
async setupWatchers() {
|
|
609
|
-
this.resetGlobalTestNamePattern()
|
|
610
|
-
this.vitest.vite.watcher.removeAllListeners("change");
|
|
611
|
-
this.vitest.vite.watcher.removeAllListeners("add");
|
|
612
|
-
this.vitest.vite.watcher.on(
|
|
389
|
+
this.resetGlobalTestNamePattern(), this.vitest.vite.watcher.removeAllListeners("change"), this.vitest.vite.watcher.removeAllListeners("add"), this.vitest.vite.watcher.on(
|
|
613
390
|
"change",
|
|
614
391
|
(file) => this.runAffectedTestsAfterChange(file, "change")
|
|
615
|
-
)
|
|
616
|
-
this.vitest.vite.watcher.on("add", (file) => {
|
|
392
|
+
), this.vitest.vite.watcher.on("add", (file) => {
|
|
617
393
|
this.runAffectedTestsAfterChange(file, "add");
|
|
618
|
-
});
|
|
619
|
-
this.registerVitestConfigListener();
|
|
394
|
+
}), this.registerVitestConfigListener();
|
|
620
395
|
}
|
|
621
396
|
isStorybookProject(project) {
|
|
622
397
|
return !!project.config.env?.__STORYBOOK_URL__;
|
|
@@ -630,8 +405,7 @@ var testStateToStatusValueMap = {
|
|
|
630
405
|
warning: "status-value:warning",
|
|
631
406
|
failed: "status-value:error",
|
|
632
407
|
skipped: "status-value:unknown"
|
|
633
|
-
}
|
|
634
|
-
var TestManager = class _TestManager {
|
|
408
|
+
}, TestManager = class _TestManager {
|
|
635
409
|
constructor(options) {
|
|
636
410
|
this.batchedTestCaseResults = [];
|
|
637
411
|
/**
|
|
@@ -649,28 +423,15 @@ var TestManager = class _TestManager {
|
|
|
649
423
|
* eventually causing the manager and dev server to lose connection.
|
|
650
424
|
*/
|
|
651
425
|
this.throttledFlushTestCaseResults = throttle(() => {
|
|
652
|
-
|
|
653
|
-
this.batchedTestCaseResults = []
|
|
654
|
-
|
|
655
|
-
let { success: ctSuccess, error: ctError } = s.currentRun.componentTestCount;
|
|
656
|
-
let { success: a11ySuccess, warning: a11yWarning, error: a11yError } = s.currentRun.a11yCount;
|
|
426
|
+
let testCaseResultsToFlush = this.batchedTestCaseResults;
|
|
427
|
+
this.batchedTestCaseResults = [], this.store.setState((s) => {
|
|
428
|
+
let { success: ctSuccess, error: ctError } = s.currentRun.componentTestCount, { success: a11ySuccess, warning: a11yWarning, error: a11yError } = s.currentRun.a11yCount;
|
|
657
429
|
testCaseResultsToFlush.forEach(({ testResult, reports }) => {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
} else if (testResult.state === "failed") {
|
|
661
|
-
ctError++;
|
|
662
|
-
}
|
|
663
|
-
reports?.filter((r) => r.type === "a11y").forEach((report) => {
|
|
664
|
-
if (report.status === "passed") {
|
|
665
|
-
a11ySuccess++;
|
|
666
|
-
} else if (report.status === "warning") {
|
|
667
|
-
a11yWarning++;
|
|
668
|
-
} else if (report.status === "failed") {
|
|
669
|
-
a11yError++;
|
|
670
|
-
}
|
|
430
|
+
testResult.state === "passed" ? ctSuccess++ : testResult.state === "failed" && ctError++, reports?.filter((r) => r.type === "a11y").forEach((report) => {
|
|
431
|
+
report.status === "passed" ? a11ySuccess++ : report.status === "warning" ? a11yWarning++ : report.status === "failed" && a11yError++;
|
|
671
432
|
});
|
|
672
433
|
});
|
|
673
|
-
|
|
434
|
+
let finishedTestCount = ctSuccess + ctError;
|
|
674
435
|
return {
|
|
675
436
|
...s,
|
|
676
437
|
currentRun: {
|
|
@@ -684,75 +445,57 @@ var TestManager = class _TestManager {
|
|
|
684
445
|
}
|
|
685
446
|
};
|
|
686
447
|
});
|
|
687
|
-
|
|
448
|
+
let componentTestStatuses = testCaseResultsToFlush.map(({ storyId, testResult }) => ({
|
|
688
449
|
storyId,
|
|
689
450
|
typeId: STATUS_TYPE_ID_COMPONENT_TEST,
|
|
690
451
|
value: testStateToStatusValueMap[testResult.state],
|
|
691
452
|
title: "Component tests",
|
|
692
|
-
description: testResult.errors?.map((error) => error.stack || error.message).join(
|
|
693
|
-
|
|
453
|
+
description: testResult.errors?.map((error) => error.stack || error.message).join(`
|
|
454
|
+
`) ?? "",
|
|
455
|
+
sidebarContextMenu: !1
|
|
694
456
|
}));
|
|
695
457
|
this.componentTestStatusStore.set(componentTestStatuses);
|
|
696
|
-
|
|
458
|
+
let a11yStatuses = testCaseResultsToFlush.flatMap(
|
|
697
459
|
({ storyId, reports }) => reports?.filter((r) => r.type === "a11y").map((a11yReport) => ({
|
|
698
460
|
storyId,
|
|
699
461
|
typeId: STATUS_TYPE_ID_A11Y,
|
|
700
462
|
value: testStateToStatusValueMap[a11yReport.status],
|
|
701
463
|
title: "Accessibility tests",
|
|
702
464
|
description: "",
|
|
703
|
-
sidebarContextMenu:
|
|
465
|
+
sidebarContextMenu: !1
|
|
704
466
|
}))
|
|
705
467
|
).filter((a11yStatus) => a11yStatus !== void 0);
|
|
706
|
-
|
|
707
|
-
this.a11yStatusStore.set(a11yStatuses);
|
|
708
|
-
}
|
|
468
|
+
a11yStatuses.length > 0 && this.a11yStatusStore.set(a11yStatuses);
|
|
709
469
|
}, 500);
|
|
710
|
-
this.store = options.store
|
|
711
|
-
this.componentTestStatusStore = options.componentTestStatusStore;
|
|
712
|
-
this.a11yStatusStore = options.a11yStatusStore;
|
|
713
|
-
this.testProviderStore = options.testProviderStore;
|
|
714
|
-
this.onReady = options.onReady;
|
|
715
|
-
this.storybookOptions = options.storybookOptions;
|
|
716
|
-
this.vitestManager = new VitestManager(this);
|
|
717
|
-
this.store.subscribe("TRIGGER_RUN", this.handleTriggerRunEvent.bind(this));
|
|
718
|
-
this.store.subscribe("CANCEL_RUN", this.handleCancelEvent.bind(this));
|
|
719
|
-
this.store.untilReady().then(() => {
|
|
720
|
-
return this.vitestManager.startVitest({ coverage: this.store.getState().config.coverage });
|
|
721
|
-
}).then(() => this.onReady?.()).catch((e) => {
|
|
470
|
+
this.store = options.store, this.componentTestStatusStore = options.componentTestStatusStore, this.a11yStatusStore = options.a11yStatusStore, this.testProviderStore = options.testProviderStore, this.onReady = options.onReady, this.storybookOptions = options.storybookOptions, this.vitestManager = new VitestManager(this), this.store.subscribe("TRIGGER_RUN", this.handleTriggerRunEvent.bind(this)), this.store.subscribe("CANCEL_RUN", this.handleCancelEvent.bind(this)), this.store.untilReady().then(() => this.vitestManager.startVitest({ coverage: this.store.getState().config.coverage })).then(() => this.onReady?.()).catch((e) => {
|
|
722
471
|
this.reportFatalError("Failed to start Vitest", e);
|
|
723
472
|
});
|
|
724
473
|
}
|
|
725
|
-
static {
|
|
726
|
-
__name(this, "TestManager");
|
|
727
|
-
}
|
|
728
474
|
async handleTriggerRunEvent(event) {
|
|
729
475
|
await this.runTestsWithState({
|
|
730
476
|
storyIds: event.payload.storyIds,
|
|
731
477
|
triggeredBy: event.payload.triggeredBy,
|
|
732
|
-
callback:
|
|
478
|
+
callback: async () => {
|
|
733
479
|
try {
|
|
734
|
-
await this.vitestManager.vitestRestartPromise;
|
|
735
|
-
await this.vitestManager.runTests(event.payload);
|
|
480
|
+
await this.vitestManager.vitestRestartPromise, await this.vitestManager.runTests(event.payload);
|
|
736
481
|
} catch (err) {
|
|
737
|
-
this.reportFatalError("Failed to run tests", err);
|
|
738
|
-
throw err;
|
|
482
|
+
throw this.reportFatalError("Failed to run tests", err), err;
|
|
739
483
|
}
|
|
740
|
-
}
|
|
484
|
+
}
|
|
741
485
|
});
|
|
742
486
|
}
|
|
743
487
|
async handleCancelEvent() {
|
|
744
488
|
try {
|
|
745
489
|
this.store.setState((s) => ({
|
|
746
490
|
...s,
|
|
747
|
-
cancelling:
|
|
748
|
-
}));
|
|
749
|
-
await this.vitestManager.cancelCurrentRun();
|
|
491
|
+
cancelling: !0
|
|
492
|
+
})), await this.vitestManager.cancelCurrentRun();
|
|
750
493
|
} catch (err) {
|
|
751
494
|
this.reportFatalError("Failed to cancel tests", err);
|
|
752
495
|
} finally {
|
|
753
496
|
this.store.setState((s) => ({
|
|
754
497
|
...s,
|
|
755
|
-
cancelling:
|
|
498
|
+
cancelling: !1
|
|
756
499
|
}));
|
|
757
500
|
}
|
|
758
501
|
}
|
|
@@ -761,9 +504,7 @@ var TestManager = class _TestManager {
|
|
|
761
504
|
triggeredBy,
|
|
762
505
|
callback
|
|
763
506
|
}) {
|
|
764
|
-
this.componentTestStatusStore.unset(storyIds)
|
|
765
|
-
this.a11yStatusStore.unset(storyIds);
|
|
766
|
-
this.store.setState((s) => ({
|
|
507
|
+
this.componentTestStatusStore.unset(storyIds), this.a11yStatusStore.unset(storyIds), this.store.setState((s) => ({
|
|
767
508
|
...s,
|
|
768
509
|
currentRun: {
|
|
769
510
|
...storeOptions.initialState.currentRun,
|
|
@@ -772,17 +513,12 @@ var TestManager = class _TestManager {
|
|
|
772
513
|
storyIds,
|
|
773
514
|
config: s.config
|
|
774
515
|
}
|
|
775
|
-
}))
|
|
776
|
-
|
|
777
|
-
await this.testProviderStore.runWithState(async () => {
|
|
778
|
-
await callback();
|
|
779
|
-
this.store.send({
|
|
516
|
+
})), process.env.VITEST_STORYBOOK_CONFIG = JSON.stringify(this.store.getState().config), await this.testProviderStore.runWithState(async () => {
|
|
517
|
+
if (await callback(), this.store.send({
|
|
780
518
|
type: "TEST_RUN_COMPLETED",
|
|
781
519
|
payload: this.store.getState().currentRun
|
|
782
|
-
})
|
|
783
|
-
if (this.store.getState().currentRun.unhandledErrors.length > 0) {
|
|
520
|
+
}), this.store.getState().currentRun.unhandledErrors.length > 0)
|
|
784
521
|
throw new Error("Tests completed but there are unhandled errors");
|
|
785
|
-
}
|
|
786
522
|
});
|
|
787
523
|
}
|
|
788
524
|
onTestModuleCollected(collectedTestCount) {
|
|
@@ -795,16 +531,11 @@ var TestManager = class _TestManager {
|
|
|
795
531
|
}));
|
|
796
532
|
}
|
|
797
533
|
onTestCaseResult(result) {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
return;
|
|
801
|
-
}
|
|
802
|
-
this.batchedTestCaseResults.push({ storyId, testResult, reports });
|
|
803
|
-
this.throttledFlushTestCaseResults();
|
|
534
|
+
let { storyId, testResult, reports } = result;
|
|
535
|
+
storyId && (this.batchedTestCaseResults.push({ storyId, testResult, reports }), this.throttledFlushTestCaseResults());
|
|
804
536
|
}
|
|
805
537
|
onTestRunEnd(endResult) {
|
|
806
|
-
this.throttledFlushTestCaseResults.flush()
|
|
807
|
-
this.store.setState((s) => ({
|
|
538
|
+
this.throttledFlushTestCaseResults.flush(), this.store.setState((s) => ({
|
|
808
539
|
...s,
|
|
809
540
|
currentRun: {
|
|
810
541
|
...s.currentRun,
|
|
@@ -824,8 +555,7 @@ var TestManager = class _TestManager {
|
|
|
824
555
|
}));
|
|
825
556
|
}
|
|
826
557
|
async reportFatalError(message, error) {
|
|
827
|
-
await this.store.untilReady()
|
|
828
|
-
this.store.send({
|
|
558
|
+
await this.store.untilReady(), this.store.send({
|
|
829
559
|
type: "FATAL_ERROR",
|
|
830
560
|
payload: {
|
|
831
561
|
message,
|
|
@@ -835,30 +565,26 @@ var TestManager = class _TestManager {
|
|
|
835
565
|
}
|
|
836
566
|
static async start(options) {
|
|
837
567
|
return new Promise((resolve) => {
|
|
838
|
-
|
|
568
|
+
let testManager = new _TestManager({
|
|
839
569
|
...options,
|
|
840
|
-
onReady:
|
|
841
|
-
resolve(testManager);
|
|
842
|
-
|
|
843
|
-
}, "onReady")
|
|
570
|
+
onReady: () => {
|
|
571
|
+
resolve(testManager), options.onReady?.();
|
|
572
|
+
}
|
|
844
573
|
});
|
|
845
574
|
});
|
|
846
575
|
}
|
|
847
576
|
};
|
|
848
577
|
|
|
849
578
|
// src/node/vitest.ts
|
|
850
|
-
var UniversalStore = experimental_UniversalStore
|
|
851
|
-
|
|
852
|
-
var getTestProviderStore = experimental_getTestProviderStore;
|
|
853
|
-
var channel = new Channel({
|
|
854
|
-
async: true,
|
|
579
|
+
var UniversalStore = experimental_UniversalStore, getStatusStore = experimental_getStatusStore, getTestProviderStore = experimental_getTestProviderStore, channel = new Channel({
|
|
580
|
+
async: !0,
|
|
855
581
|
transport: {
|
|
856
|
-
send:
|
|
582
|
+
send: (event) => {
|
|
857
583
|
process2.send?.(event);
|
|
858
|
-
},
|
|
859
|
-
setHandler:
|
|
584
|
+
},
|
|
585
|
+
setHandler: (handler) => {
|
|
860
586
|
process2.on("message", handler);
|
|
861
|
-
}
|
|
587
|
+
}
|
|
862
588
|
}
|
|
863
589
|
});
|
|
864
590
|
UniversalStore.__prepare(channel, UniversalStore.Environment.SERVER);
|
|
@@ -868,20 +594,18 @@ new TestManager({
|
|
|
868
594
|
componentTestStatusStore: getStatusStore(STATUS_TYPE_ID_COMPONENT_TEST),
|
|
869
595
|
a11yStatusStore: getStatusStore(STATUS_TYPE_ID_A11Y),
|
|
870
596
|
testProviderStore: getTestProviderStore(ADDON_ID),
|
|
871
|
-
onReady:
|
|
597
|
+
onReady: () => {
|
|
872
598
|
process2.send?.({ type: "ready" });
|
|
873
|
-
},
|
|
599
|
+
},
|
|
874
600
|
storybookOptions: {
|
|
875
601
|
configDir: process2.env.STORYBOOK_CONFIG_DIR || ""
|
|
876
602
|
}
|
|
877
603
|
});
|
|
878
|
-
var exit =
|
|
879
|
-
channel?.removeAllListeners();
|
|
880
|
-
|
|
881
|
-
}, "exit");
|
|
882
|
-
var createUnhandledErrorHandler = /* @__PURE__ */ __name((message) => async (error) => {
|
|
604
|
+
var exit = (code = 0) => {
|
|
605
|
+
channel?.removeAllListeners(), process2.exit(code);
|
|
606
|
+
}, createUnhandledErrorHandler = (message) => async (error) => {
|
|
883
607
|
try {
|
|
884
|
-
|
|
608
|
+
let payload = {
|
|
885
609
|
message,
|
|
886
610
|
error: {
|
|
887
611
|
message: error.message,
|
|
@@ -897,7 +621,7 @@ var createUnhandledErrorHandler = /* @__PURE__ */ __name((message) => async (err
|
|
|
897
621
|
} finally {
|
|
898
622
|
exit(1);
|
|
899
623
|
}
|
|
900
|
-
}
|
|
624
|
+
};
|
|
901
625
|
process2.on(
|
|
902
626
|
"uncaughtException",
|
|
903
627
|
createUnhandledErrorHandler("Uncaught exception in the test runner process")
|