@storybook/addon-vitest 0.0.0-pr-32717-sha-f340a68b → 0.0.0-pr-32795-sha-f0ac445c

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.
@@ -1,37 +1,36 @@
1
- import CJS_COMPAT_NODE_URL_xvr6gehai1p from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_xvr6gehai1p from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_xvr6gehai1p from "node:module";
1
+ import CJS_COMPAT_NODE_URL_oycy7mg2pm from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_oycy7mg2pm from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_oycy7mg2pm from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_xvr6gehai1p.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_xvr6gehai1p.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_xvr6gehai1p.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_oycy7mg2pm.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_oycy7mg2pm.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_oycy7mg2pm.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-724JPUHM.js";
14
+ } from "../_node-chunks/chunk-MQUBKGKA.js";
15
15
  import {
16
- any
17
- } from "../_node-chunks/chunk-NGOGIT42.js";
16
+ any,
17
+ errorToErrorLike
18
+ } from "../_node-chunks/chunk-CKQN7IR2.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-KHNVQCL7.js";
25
- import "../_node-chunks/chunk-7ZCNTQXP.js";
25
+ } from "../_node-chunks/chunk-RIAV333R.js";
26
+ import "../_node-chunks/chunk-PI4OHO3O.js";
26
27
  import {
27
28
  dirname,
28
29
  join,
29
30
  normalize,
30
31
  path
31
- } from "../_node-chunks/chunk-TXTKPPIA.js";
32
- import {
33
- __name
34
- } from "../_node-chunks/chunk-K5BRNZW2.js";
32
+ } from "../_node-chunks/chunk-SNWBLFHL.js";
33
+ import "../_node-chunks/chunk-HCCHV65D.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 = void 0;
48
- let pendingArgs = null;
49
- const leading = edges != null && edges.includes("leading");
50
- const trailing = edges == null || edges.includes("trailing");
51
- const invoke = /* @__PURE__ */ __name(() => {
52
- if (pendingArgs !== null) {
53
- func.apply(pendingThis, pendingArgs);
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
- }, "schedule");
74
- const cancelTimer = /* @__PURE__ */ __name(() => {
75
- if (timeoutId !== null) {
76
- clearTimeout(timeoutId);
77
- timeoutId = null;
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
- }, "flush");
88
- const debounced = /* @__PURE__ */ __name(function(...args) {
89
- if (signal?.aborted) {
60
+ }, debounced = function(...args) {
61
+ if (signal?.aborted)
90
62
  return;
91
- }
92
- pendingThis = this;
93
- pendingArgs = args;
94
- const isFirstCall = timeoutId == null;
95
- schedule();
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
- const partialed = /* @__PURE__ */ __name(function(...providedArgs) {
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
- }, "partialed");
120
- if (func.prototype) {
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
- const partialedRight = /* @__PURE__ */ __name(function(...providedArgs) {
136
- const placeholderLength = partialArgs.filter((arg) => arg === placeholder).length;
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
- }, "partialedRight");
143
- if (func.prototype) {
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
- const debounced = debounce(func, throttleMs, { signal, edges });
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
- const isExtendedLengthPath = path2.startsWith("\\\\?\\");
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
- const { storyId, reports } = testCase.meta();
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
- const totalTestCount = testModules.flatMap(
135
+ let totalTestCount = testModules.flatMap(
224
136
  (t) => Array.from(t.children.allTests("passed")).concat(Array.from(t.children.allTests("failed")))
225
- ).length;
226
- const testModulesErrors = testModules.flatMap((t) => t.errors());
227
- const serializedErrors = unhandledErrors.concat(testModulesErrors).map((e) => {
228
- return {
229
- ...e,
230
- name: e.name,
231
- message: e.message,
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
- const { createVitest } = await import("vitest/node");
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
- const coverageOptions = coverage ? {
279
- enabled: true,
280
- clean: true,
281
- cleanOnRerun: true,
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: false };
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: true,
298
- passWithNoTests: false,
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
- const originalMessage = String(err.message);
202
+ let originalMessage = String(err.message);
310
203
  if (originalMessage.includes("Found multiple projects")) {
311
- const custom = [
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("\n");
315
- if (!originalMessage.startsWith(custom)) {
316
- err.message = `${custom}${originalMessage}`;
317
- }
207
+ ].join(`
208
+ `);
209
+ originalMessage.startsWith(custom) || (err.message = `${custom}${originalMessage}`);
318
210
  }
319
211
  throw err;
320
212
  }
321
- if (this.vitest) {
322
- this.vitest.onCancel(() => {
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
- const isV8 = e.message?.includes("@vitest/coverage-v8");
330
- const isIstanbul = e.message?.includes("@vitest/coverage-istanbul");
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/${coveragePackage} package to collect coverage
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
- if (server) {
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
- const indexUrl = this.testManager.store.getState().indexUrl;
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
- const index = await Promise.race([
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
- const storyIds = requestStoryIds || Object.keys(index.entries);
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
- const filteredTestSpecifications = [];
400
- const filteredStoryIds = [];
401
- const storiesByImportPath = {};
402
- for (const story of stories) {
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 (const testSpecification of testSpecifications) {
410
- const { env = {} } = testSpecification.project.config;
411
- const include = env.__VITEST_INCLUDE_TAGS__?.split(",").filter(Boolean) ?? ["test"];
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
- const { watching, config } = this.testManager.store.getState();
439
- const coverageShouldBeEnabled = config.coverage && !watching && (runPayload?.storyIds?.length ?? 0) === 0;
440
- const currentCoverage = this.vitest?.config.coverage?.enabled;
441
- if (!this.vitest) {
442
- await this.startVitest({ coverage: coverageShouldBeEnabled });
443
- } else if (currentCoverage !== coverageShouldBeEnabled) {
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
- const parentName = getTestName(selectedStory.name);
287
+ let parentName = getTestName(selectedStory.name);
465
288
  regex = new RegExp(`^${parentName}`);
466
289
  } else if (hasParentStory) {
467
- const parentStory = allStories.find((story) => story.id === selectedStory.parent);
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
- const { filteredTestSpecifications, filteredStoryIds } = this.filterTestSpecifications(
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
- const globTestSpecifications = await this.vitest?.globTestSpecifications() ?? [];
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
- const id = slash(changedFilePath);
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
- const storybookProject = this.vitest.projects.find((p) => this.isStorybookProject(p));
518
- const previewAnnotationSpecifications = this.testManager.store.getState().previewAnnotations.map((previewAnnotation) => {
519
- return {
520
- project: storybookProject ?? this.vitest.projects[0],
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
- const dependencies = await this.getTestDependencies(testSpecification);
537
- if (changedFilePath === testSpecification.moduleId || dependencies.has(changedFilePath)) {
538
- if (syntheticGlobalTestSpecifications.includes(testSpecification)) {
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
- const testSpecificationsToRun = affectsGlobalFiles ? testSpecifications : affectedTestSpecifications;
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: /* @__PURE__ */ __name(async () => {
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
- await this.vitest.cancelCurrentRun("keyboard-input");
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
- const deps = /* @__PURE__ */ new Set();
574
- const addImports = /* @__PURE__ */ __name(async (project, filepath) => {
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
- const mod = project.vite.moduleGraph.getModuleById(filepath);
580
- const transformed = mod?.ssrTransformResult || await project.vite.transformRequest(filepath, { ssr: true });
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
- const fsPath = dep.startsWith("/@fs/") ? dep.slice(process.platform === "win32" ? 5 : 4) : join(project.config.root, dep);
588
- if (!fsPath.includes("node_modules") && !deps.has(fsPath) && existsSync(fsPath)) {
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
- }, "addImports");
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
- const isConfig = normalize(file) === this.vitest?.vite?.config.configFile;
601
- if (isConfig) {
381
+ if (normalize(file) === this.vitest?.vite?.config.configFile) {
602
382
  log("Restarting Vitest due to config change");
603
- const { watching, config } = this.testManager.store.getState();
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
- const testCaseResultsToFlush = this.batchedTestCaseResults;
653
- this.batchedTestCaseResults = [];
654
- this.store.setState((s) => {
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
- if (testResult.state === "passed") {
659
- ctSuccess++;
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
- const finishedTestCount = ctSuccess + ctError;
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
- const componentTestStatuses = testCaseResultsToFlush.map(({ storyId, testResult }) => ({
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("\n") ?? "",
693
- sidebarContextMenu: false
453
+ description: testResult.errors?.map((error) => error.stack || error.message).join(`
454
+ `) ?? "",
455
+ sidebarContextMenu: !1
694
456
  }));
695
457
  this.componentTestStatusStore.set(componentTestStatuses);
696
- const a11yStatuses = testCaseResultsToFlush.flatMap(
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: false
465
+ sidebarContextMenu: !1
704
466
  }))
705
467
  ).filter((a11yStatus) => a11yStatus !== void 0);
706
- if (a11yStatuses.length > 0) {
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: /* @__PURE__ */ __name(async () => {
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
- }, "callback")
484
+ }
741
485
  });
742
486
  }
743
487
  async handleCancelEvent() {
744
488
  try {
745
489
  this.store.setState((s) => ({
746
490
  ...s,
747
- cancelling: true
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: false
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
- process.env.VITEST_STORYBOOK_CONFIG = JSON.stringify(this.store.getState().config);
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
- const { storyId, testResult, reports } = result;
799
- if (!storyId) {
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
- const testManager = new _TestManager({
568
+ let testManager = new _TestManager({
839
569
  ...options,
840
- onReady: /* @__PURE__ */ __name(() => {
841
- resolve(testManager);
842
- options.onReady?.();
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
- var getStatusStore = experimental_getStatusStore;
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: /* @__PURE__ */ __name((event) => {
582
+ send: (event) => {
857
583
  process2.send?.(event);
858
- }, "send"),
859
- setHandler: /* @__PURE__ */ __name((handler) => {
584
+ },
585
+ setHandler: (handler) => {
860
586
  process2.on("message", handler);
861
- }, "setHandler")
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: /* @__PURE__ */ __name(() => {
597
+ onReady: () => {
872
598
  process2.send?.({ type: "ready" });
873
- }, "onReady"),
599
+ },
874
600
  storybookOptions: {
875
601
  configDir: process2.env.STORYBOOK_CONFIG_DIR || ""
876
602
  }
877
603
  });
878
- var exit = /* @__PURE__ */ __name((code = 0) => {
879
- channel?.removeAllListeners();
880
- process2.exit(code);
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
- const payload = {
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
- }, "createUnhandledErrorHandler");
624
+ };
901
625
  process2.on(
902
626
  "uncaughtException",
903
627
  createUnhandledErrorHandler("Uncaught exception in the test runner process")