@storybook/addon-vitest 11.0.0-beta.0 → 11.0.0-beta.2

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,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_q65v6j674l from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_q65v6j674l from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_q65v6j674l from "node:module";
1
+ import CJS_COMPAT_NODE_URL_ycvuvp62uk from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_ycvuvp62uk from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_ycvuvp62uk from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_q65v6j674l.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_q65v6j674l.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_q65v6j674l.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_ycvuvp62uk.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_ycvuvp62uk.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_ycvuvp62uk.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -13,19 +13,19 @@ import {
13
13
  errorToErrorLike,
14
14
  globalThis_,
15
15
  log
16
- } from "../_node-chunks/chunk-ATRY5NRC.js";
16
+ } from "../_node-chunks/chunk-DX5XAAV3.js";
17
17
  import {
18
18
  any,
19
19
  up
20
- } from "../_node-chunks/chunk-3BHG7ERW.js";
21
- import "../_node-chunks/chunk-RNV4WF5A.js";
20
+ } from "../_node-chunks/chunk-KU7SQ3KB.js";
21
+ import "../_node-chunks/chunk-SXATVQ73.js";
22
22
  import {
23
23
  dirname,
24
24
  join,
25
25
  normalize,
26
26
  path,
27
27
  resolve
28
- } from "../_node-chunks/chunk-YGNVYBQM.js";
28
+ } from "../_node-chunks/chunk-H6P4MQ2A.js";
29
29
  import {
30
30
  ADDON_ID2 as ADDON_ID,
31
31
  COVERAGE_DIRECTORY,
@@ -34,8 +34,8 @@ import {
34
34
  STORYBOOK_TEST_PROVIDE_KEY,
35
35
  STORY_INDEX_CHANNEL_EVENT_NAME,
36
36
  storeOptions
37
- } from "../_node-chunks/chunk-U6IN5TYZ.js";
38
- import "../_node-chunks/chunk-4GNOAC4E.js";
37
+ } from "../_node-chunks/chunk-M4HPIOHU.js";
38
+ import "../_node-chunks/chunk-BIBVDNHH.js";
39
39
 
40
40
  // src/node/vitest.ts
41
41
  import process2 from "node:process";
@@ -126,6 +126,7 @@ function throttle(func, throttleMs, { signal, edges = ["leading", "trailing"] }
126
126
  import { existsSync, readFileSync } from "node:fs";
127
127
  import { getProjectRoot, resolvePathInStorybookCache } from "storybook/internal/common";
128
128
  import { Tag } from "storybook/internal/core-server";
129
+ import { logger } from "storybook/internal/node-logger";
129
130
 
130
131
  // ../../../node_modules/es-toolkit/dist/string/words.mjs
131
132
  var CASE_SPLIT_PATTERN = new RegExp("\\p{Lu}?\\p{Ll}+|[0-9]+|\\p{Lu}+(?!\\p{Ll})|\\p{Emoji_Presentation}|\\p{Extended_Pictographic}|\\p{L}+", "gu");
@@ -180,7 +181,7 @@ var StorybookReporter = class {
180
181
  // src/node/vitest-manager.ts
181
182
  var VITEST_CONFIG_FILE_EXTENSIONS = ["mts", "mjs", "cts", "cjs", "ts", "tsx", "js", "jsx"];
182
183
  process.env.VITEST_STORYBOOK = "true";
183
- var DOUBLE_SPACES = " ", getTestName = (name) => `${name}${DOUBLE_SPACES}`, VitestManager = class {
184
+ var DOUBLE_SPACES = " ", toModuleId = (importPath) => path.join(process.cwd(), importPath), getTestName = (name) => `${name}${DOUBLE_SPACES}`, VitestManager = class {
184
185
  constructor(testManager2) {
185
186
  this.testManager = testManager2;
186
187
  this.vitest = null;
@@ -349,7 +350,7 @@ Please install the @vitest/${isIstanbul ? "coverage-istanbul" : "coverage-v8"} p
349
350
  filterTestSpecifications(testSpecifications, stories) {
350
351
  let filteredTestSpecifications = [], filteredStoryIds = [], storiesByImportPath = {};
351
352
  for (let story of stories) {
352
- let absoluteImportPath = path.join(process.cwd(), story.importPath);
353
+ let absoluteImportPath = toModuleId(story.importPath);
353
354
  storiesByImportPath[absoluteImportPath] || (storiesByImportPath[absoluteImportPath] = []), storiesByImportPath[absoluteImportPath].push(story);
354
355
  }
355
356
  for (let testSpecification of testSpecifications) {
@@ -369,7 +370,7 @@ Please install the @vitest/${isIstanbul ? "coverage-istanbul" : "coverage-v8"} p
369
370
  async runTests(runPayload) {
370
371
  let { watching } = this.testManager.store.getState(), coverageShouldBeEnabled = !!this.getCurrentRunConfig().coverage && !watching && (runPayload?.storyIds?.length ?? 0) === 0;
371
372
  this.vitest ? await this.setCoverage(coverageShouldBeEnabled) : await this.startVitest({ coverage: coverageShouldBeEnabled }), this.provideRunConfig(), this.resetGlobalTestNamePattern(), await this.cancelCurrentRun();
372
- let testSpecifications = await this.getStorybookTestSpecifications(), allStories = this.getStories(), filteredStories = runPayload.storyIds ? allStories.filter((story) => runPayload.storyIds?.includes(story.id)) : allStories;
373
+ let allStories = this.getStories(), testSpecifications = await this.getStorybookTestSpecifications(), filteredStories = runPayload.storyIds ? allStories.filter((story) => runPayload.storyIds?.includes(story.id)) : allStories;
373
374
  if (runPayload.storyIds?.length) {
374
375
  let regex = this.buildTestNamePatternForStories(filteredStories, allStories);
375
376
  regex && this.vitest.setGlobalTestNamePattern(regex);
@@ -389,6 +390,28 @@ Please install the @vitest/${isIstanbul ? "coverage-istanbul" : "coverage-v8"} p
389
390
  async cancelCurrentRun() {
390
391
  await this.vitest?.cancelCurrentRun("keyboard-input"), await this.runningPromise;
391
392
  }
393
+ /**
394
+ * Makes sure every Storybook project knows about the given test files.
395
+ *
396
+ * Vitest caches its list of test files after the first glob and only adds new files when its
397
+ * Vite watcher reports them. Story files created outside the Vite root after startup never reach
398
+ * that watcher, even though Storybook has already indexed them, so they'd be silently dropped
399
+ * from every run. `matchesTestGlob` both checks a file against a project's include/exclude globs
400
+ * and adds it to that project's cached list (it returns early for files the project already
401
+ * has), so this mirrors what Vitest itself does on file creation.
402
+ */
403
+ registerTestFiles(moduleIds) {
404
+ if (!this.vitest)
405
+ return;
406
+ let storybookProjects = this.vitest.projects.filter((p) => this.isStorybookProject(p));
407
+ for (let moduleId of moduleIds)
408
+ for (let project of storybookProjects)
409
+ try {
410
+ project.matchesTestGlob(moduleId);
411
+ } catch (e) {
412
+ logger.debug(`Could not check ${moduleId} against the Vitest test globs: ${e}`);
413
+ }
414
+ }
392
415
  async getStorybookTestSpecifications() {
393
416
  return (await this.vitest?.globTestSpecifications() ?? []).filter(
394
417
  (workspaceSpec) => this.isStorybookProject(workspaceSpec.project)
@@ -396,7 +419,7 @@ Please install the @vitest/${isIstanbul ? "coverage-istanbul" : "coverage-v8"} p
396
419
  }
397
420
  async runAffectedTestsAfterChange(changedFilePath, event) {
398
421
  let id = slash(changedFilePath);
399
- 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)
422
+ if (this.vitest?.logger.clearHighlightCache(id), this.updateLastChanged(id), event === "add" && this.registerTestFiles([id]), !this.testManager.store.getState().watching || !this.vitest)
400
423
  return;
401
424
  this.resetGlobalTestNamePattern();
402
425
  let storybookProject = this.vitest.projects.find((p) => this.isStorybookProject(p)), previewAnnotationSpecifications = this.testManager.previewAnnotations.map(
@@ -497,7 +520,7 @@ var testStateToStatusValueMap = {
497
520
  skipped: "status-value:unknown"
498
521
  }, TestManager = class _TestManager {
499
522
  constructor(options) {
500
- this.storyIndex = { v: 5, entries: {} };
523
+ this._storyIndex = { v: 5, entries: {} };
501
524
  this.batchedTestCaseResults = [];
502
525
  this.runComponentTestStatuses = [];
503
526
  this.runA11yStatuses = [];
@@ -575,6 +598,19 @@ var testStateToStatusValueMap = {
575
598
  this.reportFatalError("Failed to start Vitest", e);
576
599
  });
577
600
  }
601
+ get storyIndex() {
602
+ return this._storyIndex;
603
+ }
604
+ set storyIndex(index) {
605
+ let previousImportPaths = new Set(
606
+ Object.values(this._storyIndex.entries).map((entry) => entry.importPath)
607
+ );
608
+ this._storyIndex = index;
609
+ let newImportPaths = new Set(
610
+ Object.values(index.entries).map((entry) => entry.importPath).filter((importPath) => !previousImportPaths.has(importPath))
611
+ );
612
+ this.vitestManager.registerTestFiles([...newImportPaths].map(toModuleId));
613
+ }
578
614
  async handleTriggerRunEvent(event) {
579
615
  await this.runTestsWithState({
580
616
  storyIds: event.payload.storyIds,
@@ -1,32 +1,32 @@
1
- import CJS_COMPAT_NODE_URL_q65v6j674l from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_q65v6j674l from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_q65v6j674l from "node:module";
1
+ import CJS_COMPAT_NODE_URL_ycvuvp62uk from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_ycvuvp62uk from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_ycvuvp62uk from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_q65v6j674l.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_q65v6j674l.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_q65v6j674l.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_ycvuvp62uk.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_ycvuvp62uk.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_ycvuvp62uk.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
  any
14
- } from "./_node-chunks/chunk-3BHG7ERW.js";
14
+ } from "./_node-chunks/chunk-KU7SQ3KB.js";
15
15
  import {
16
16
  require_dist
17
- } from "./_node-chunks/chunk-3W3XGTQZ.js";
17
+ } from "./_node-chunks/chunk-YLZRXWKY.js";
18
18
  import {
19
19
  dirname,
20
20
  normalize,
21
21
  relative,
22
22
  resolve
23
- } from "./_node-chunks/chunk-YGNVYBQM.js";
23
+ } from "./_node-chunks/chunk-H6P4MQ2A.js";
24
24
  import {
25
25
  DOCUMENTATION_LINK
26
- } from "./_node-chunks/chunk-U6IN5TYZ.js";
26
+ } from "./_node-chunks/chunk-M4HPIOHU.js";
27
27
  import {
28
28
  __toESM
29
- } from "./_node-chunks/chunk-4GNOAC4E.js";
29
+ } from "./_node-chunks/chunk-BIBVDNHH.js";
30
30
 
31
31
  // src/postinstall.ts
32
32
  import * as fs from "node:fs/promises";
@@ -130,7 +130,7 @@ import {
130
130
  staticKey
131
131
  } from "storybook/internal/csf-tools";
132
132
  async function getTemplatePath() {
133
- return import("./_node-chunks/vitest.config.4.template-QLM53UPV.js");
133
+ return import("./_node-chunks/vitest.config.4.template-G2P77GDP.js");
134
134
  }
135
135
  var loadTemplate = async (name, replacements) => {
136
136
  let template = (await getTemplatePath()).default;