@storybook/addon-vitest 11.0.0-beta.0 → 11.0.0-beta.1
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/_node-chunks/{chunk-3BHG7ERW.js → chunk-4O3ELV7Z.js} +6 -6
- package/dist/_node-chunks/{chunk-3W3XGTQZ.js → chunk-AWFFQZGX.js} +7 -7
- package/dist/_node-chunks/{chunk-ATRY5NRC.js → chunk-EZ2GJA55.js} +9 -9
- package/dist/_node-chunks/{chunk-U6IN5TYZ.js → chunk-F4S6LH6A.js} +6 -6
- package/dist/_node-chunks/{chunk-4GNOAC4E.js → chunk-H4T7M5H2.js} +6 -6
- package/dist/_node-chunks/{chunk-RNV4WF5A.js → chunk-M6KGRZCR.js} +7 -7
- package/dist/_node-chunks/{chunk-YGNVYBQM.js → chunk-QJJWKVEL.js} +6 -6
- package/dist/_node-chunks/{vitest.config.4.template-QLM53UPV.js → vitest.config.4.template-D5LCIFQF.js} +7 -7
- package/dist/constants.js +8 -8
- package/dist/node/coverage-reporter.js +333 -10
- package/dist/node/vitest.js +53 -17
- package/dist/postinstall.js +12 -12
- package/dist/preset.js +12 -885
- package/dist/vitest-plugin/global-setup.js +7 -7
- package/dist/vitest-plugin/index.js +11 -11
- package/package.json +6 -6
- package/dist/_node-chunks/chunk-GSEDOCKO.js +0 -351
package/dist/node/vitest.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_o9osjcq7sni from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_o9osjcq7sni from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_o9osjcq7sni from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_o9osjcq7sni.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_o9osjcq7sni.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_o9osjcq7sni.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-
|
|
16
|
+
} from "../_node-chunks/chunk-EZ2GJA55.js";
|
|
17
17
|
import {
|
|
18
18
|
any,
|
|
19
19
|
up
|
|
20
|
-
} from "../_node-chunks/chunk-
|
|
21
|
-
import "../_node-chunks/chunk-
|
|
20
|
+
} from "../_node-chunks/chunk-4O3ELV7Z.js";
|
|
21
|
+
import "../_node-chunks/chunk-M6KGRZCR.js";
|
|
22
22
|
import {
|
|
23
23
|
dirname,
|
|
24
24
|
join,
|
|
25
25
|
normalize,
|
|
26
26
|
path,
|
|
27
27
|
resolve
|
|
28
|
-
} from "../_node-chunks/chunk-
|
|
28
|
+
} from "../_node-chunks/chunk-QJJWKVEL.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-
|
|
38
|
-
import "../_node-chunks/chunk-
|
|
37
|
+
} from "../_node-chunks/chunk-F4S6LH6A.js";
|
|
38
|
+
import "../_node-chunks/chunk-H4T7M5H2.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 =
|
|
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
|
|
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.
|
|
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.
|
|
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,
|
package/dist/postinstall.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_o9osjcq7sni from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_o9osjcq7sni from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_o9osjcq7sni from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_o9osjcq7sni.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_o9osjcq7sni.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_o9osjcq7sni.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-
|
|
14
|
+
} from "./_node-chunks/chunk-4O3ELV7Z.js";
|
|
15
15
|
import {
|
|
16
16
|
require_dist
|
|
17
|
-
} from "./_node-chunks/chunk-
|
|
17
|
+
} from "./_node-chunks/chunk-AWFFQZGX.js";
|
|
18
18
|
import {
|
|
19
19
|
dirname,
|
|
20
20
|
normalize,
|
|
21
21
|
relative,
|
|
22
22
|
resolve
|
|
23
|
-
} from "./_node-chunks/chunk-
|
|
23
|
+
} from "./_node-chunks/chunk-QJJWKVEL.js";
|
|
24
24
|
import {
|
|
25
25
|
DOCUMENTATION_LINK
|
|
26
|
-
} from "./_node-chunks/chunk-
|
|
26
|
+
} from "./_node-chunks/chunk-F4S6LH6A.js";
|
|
27
27
|
import {
|
|
28
28
|
__toESM
|
|
29
|
-
} from "./_node-chunks/chunk-
|
|
29
|
+
} from "./_node-chunks/chunk-H4T7M5H2.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-
|
|
133
|
+
return import("./_node-chunks/vitest.config.4.template-D5LCIFQF.js");
|
|
134
134
|
}
|
|
135
135
|
var loadTemplate = async (name, replacements) => {
|
|
136
136
|
let template = (await getTemplatePath()).default;
|