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