@storybook/addon-vitest 0.0.0-pr-31819-sha-323d0e88 → 0.0.0-pr-31987-sha-64db30c4

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.
Files changed (42) hide show
  1. package/dist/chunk-55WZLVGN.mjs +11 -0
  2. package/dist/chunk-JKRQGT2U.mjs +10 -0
  3. package/dist/index.js +6 -9
  4. package/dist/index.mjs +5 -0
  5. package/dist/manager.js +8 -5571
  6. package/dist/node/coverage-reporter.d.ts +184 -0
  7. package/dist/node/coverage-reporter.js +4 -1395
  8. package/dist/node/coverage-reporter.mjs +12 -0
  9. package/dist/node/vitest.d.ts +2 -0
  10. package/dist/node/vitest.js +17 -564
  11. package/dist/node/vitest.mjs +19 -0
  12. package/dist/postinstall.js +93 -1163
  13. package/dist/preset.js +32 -268
  14. package/dist/vitest-plugin/global-setup.d.ts +6 -0
  15. package/dist/vitest-plugin/global-setup.js +6 -146
  16. package/dist/vitest-plugin/global-setup.mjs +13 -0
  17. package/dist/vitest-plugin/index.js +43 -2589
  18. package/dist/vitest-plugin/index.mjs +28 -0
  19. package/dist/vitest-plugin/setup-file.d.ts +14 -0
  20. package/dist/vitest-plugin/setup-file.js +9 -28
  21. package/dist/vitest-plugin/setup-file.mjs +9 -0
  22. package/dist/vitest-plugin/test-utils.d.ts +20 -0
  23. package/dist/vitest-plugin/test-utils.js +8 -68
  24. package/dist/vitest-plugin/test-utils.mjs +8 -0
  25. package/manager.js +1 -0
  26. package/manager.mjs +1 -0
  27. package/package.json +89 -17
  28. package/postinstall.js +1 -0
  29. package/postinstall.mjs +1 -0
  30. package/preset.js +1 -0
  31. package/preset.mjs +1 -0
  32. package/dist/_browser-chunks/chunk-A47P2DCZ.js +0 -11
  33. package/dist/_browser-chunks/chunk-VMSW5DPM.js +0 -60
  34. package/dist/_node-chunks/chunk-C4NXJJA3.js +0 -324
  35. package/dist/_node-chunks/chunk-CIKGVIS6.js +0 -223
  36. package/dist/_node-chunks/chunk-FMQIQP6D.js +0 -96
  37. package/dist/_node-chunks/chunk-KVKHJ5OL.js +0 -46
  38. package/dist/_node-chunks/chunk-N3OFRDD3.js +0 -80
  39. package/dist/_node-chunks/chunk-VFT2PRGV.js +0 -5002
  40. package/dist/_node-chunks/chunk-W26ZMSD3.js +0 -143
  41. package/dist/_node-chunks/chunk-XWQZZ2C3.js +0 -1586
  42. package/static/coverage-reporter.cjs +0 -10
@@ -0,0 +1,184 @@
1
+ import { Vitest, TestSpecification, TestProject, WorkspaceProject, ResolvedCoverageOptions } from 'vitest/node';
2
+ import { ReportBase, Visitor, ReportNode } from 'istanbul-lib-report';
3
+ import { ThrottledFunction } from './function/throttle.js';
4
+ import { TestResult } from 'vitest/dist/node.js';
5
+ import { experimental_UniversalStore } from 'storybook/internal/core-server';
6
+ import { API_HashEntry, PreviewAnnotation, StoryId, Options, StatusStoreByTypeId, TestProviderStoreById } from 'storybook/internal/types';
7
+ import { Report } from 'storybook/preview-api';
8
+
9
+ interface VitestError extends Error {
10
+ VITEST_TEST_PATH?: string;
11
+ VITEST_TEST_NAME?: string;
12
+ stacks?: Array<{
13
+ line: number;
14
+ column: number;
15
+ file: string;
16
+ method: string;
17
+ }>;
18
+ }
19
+ type ErrorLike = {
20
+ message: string;
21
+ name?: string;
22
+ stack?: string;
23
+ cause?: ErrorLike;
24
+ };
25
+ type RunTrigger = 'run-all' | 'global' | 'watch' | Extract<API_HashEntry['type'], string>;
26
+ type StoreState = {
27
+ config: {
28
+ coverage: boolean;
29
+ a11y: boolean;
30
+ };
31
+ watching: boolean;
32
+ cancelling: boolean;
33
+ indexUrl: string | undefined;
34
+ previewAnnotations: PreviewAnnotation[];
35
+ fatalError: {
36
+ message: string | undefined;
37
+ error: ErrorLike;
38
+ } | undefined;
39
+ currentRun: {
40
+ triggeredBy: RunTrigger | undefined;
41
+ config: StoreState['config'];
42
+ componentTestCount: {
43
+ success: number;
44
+ error: number;
45
+ };
46
+ a11yCount: {
47
+ success: number;
48
+ warning: number;
49
+ error: number;
50
+ };
51
+ totalTestCount: number | undefined;
52
+ storyIds: StoryId[] | undefined;
53
+ startedAt: number | undefined;
54
+ finishedAt: number | undefined;
55
+ unhandledErrors: VitestError[];
56
+ coverageSummary: {
57
+ status: 'positive' | 'warning' | 'negative' | 'unknown';
58
+ percentage: number;
59
+ } | undefined;
60
+ };
61
+ };
62
+ type TriggerRunEvent = {
63
+ type: 'TRIGGER_RUN';
64
+ payload: {
65
+ storyIds?: string[] | undefined;
66
+ triggeredBy: RunTrigger;
67
+ };
68
+ };
69
+ type CancelRunEvent = {
70
+ type: 'CANCEL_RUN';
71
+ };
72
+ type ToggleWatchingEvent = {
73
+ type: 'TOGGLE_WATCHING';
74
+ payload: {
75
+ to: boolean;
76
+ };
77
+ };
78
+ type FatalErrorEvent = {
79
+ type: 'FATAL_ERROR';
80
+ payload: {
81
+ message: string;
82
+ error: ErrorLike;
83
+ };
84
+ };
85
+ type TestRunCompletedEvent = {
86
+ type: 'TEST_RUN_COMPLETED';
87
+ payload: StoreState['currentRun'];
88
+ };
89
+ type StoreEvent = TriggerRunEvent | CancelRunEvent | FatalErrorEvent | ToggleWatchingEvent | TestRunCompletedEvent;
90
+
91
+ declare class VitestManager {
92
+ private testManager;
93
+ vitest: Vitest | null;
94
+ vitestStartupCounter: number;
95
+ vitestRestartPromise: Promise<void> | null;
96
+ runningPromise: Promise<any> | null;
97
+ constructor(testManager: TestManager);
98
+ startVitest({ coverage }: {
99
+ coverage: boolean;
100
+ }): Promise<void>;
101
+ restartVitest({ coverage }: {
102
+ coverage: boolean;
103
+ }): Promise<void>;
104
+ private resetGlobalTestNamePattern;
105
+ private updateLastChanged;
106
+ private fetchStories;
107
+ private filterTestSpecifications;
108
+ runTests(runPayload: TriggerRunEvent['payload']): Promise<void>;
109
+ cancelCurrentRun(): Promise<void>;
110
+ getStorybookTestSpecifications(): Promise<TestSpecification[]>;
111
+ runAffectedTestsAfterChange(changedFilePath: string, event: 'change' | 'add'): Promise<void>;
112
+ private getTestDependencies;
113
+ registerVitestConfigListener(): Promise<void>;
114
+ setupWatchers(): Promise<void>;
115
+ isStorybookProject(project: TestProject | WorkspaceProject): boolean;
116
+ }
117
+
118
+ type TestManagerOptions = {
119
+ storybookOptions: Options;
120
+ store: experimental_UniversalStore<StoreState, StoreEvent>;
121
+ componentTestStatusStore: StatusStoreByTypeId;
122
+ a11yStatusStore: StatusStoreByTypeId;
123
+ testProviderStore: TestProviderStoreById;
124
+ onError?: (message: string, error: Error) => void;
125
+ onReady?: () => void;
126
+ };
127
+ declare class TestManager {
128
+ store: TestManagerOptions['store'];
129
+ vitestManager: VitestManager;
130
+ private componentTestStatusStore;
131
+ private a11yStatusStore;
132
+ private testProviderStore;
133
+ private onReady?;
134
+ storybookOptions: Options;
135
+ private batchedTestCaseResults;
136
+ constructor(options: TestManagerOptions);
137
+ handleTriggerRunEvent(event: TriggerRunEvent): Promise<void>;
138
+ handleCancelEvent(): Promise<void>;
139
+ runTestsWithState({ storyIds, triggeredBy, callback, }: {
140
+ storyIds?: string[];
141
+ triggeredBy: RunTrigger;
142
+ callback: () => Promise<void>;
143
+ }): Promise<void>;
144
+ onTestModuleCollected(collectedTestCount: number): void;
145
+ onTestCaseResult(result: {
146
+ storyId?: string;
147
+ testResult: TestResult;
148
+ reports?: Report[];
149
+ }): void;
150
+ /**
151
+ * Throttled function to process batched test case results.
152
+ *
153
+ * This function:
154
+ *
155
+ * 1. Takes all batched test case results and clears the batch
156
+ * 2. Updates the store state with new test counts (component tests and a11y tests)
157
+ * 3. Adjusts the totalTestCount if more tests were run than initially anticipated
158
+ * 4. Creates status objects for component tests and updates the component test status store
159
+ * 5. Creates status objects for a11y tests (if any) and updates the a11y status store
160
+ *
161
+ * The throttling (500ms) is necessary as the channel would otherwise get overwhelmed with events,
162
+ * eventually causing the manager and dev server to lose connection.
163
+ */
164
+ throttledFlushTestCaseResults: ThrottledFunction<() => void>;
165
+ onTestRunEnd(endResult: {
166
+ totalTestCount: number;
167
+ unhandledErrors: VitestError[];
168
+ }): void;
169
+ onCoverageCollected(coverageSummary: StoreState['currentRun']['coverageSummary']): void;
170
+ reportFatalError(message: string, error: Error | any): Promise<void>;
171
+ static start(options: TestManagerOptions): Promise<TestManager>;
172
+ }
173
+
174
+ type StorybookCoverageReporterOptions = {
175
+ testManager: TestManager;
176
+ coverageOptions: ResolvedCoverageOptions<'v8'> | undefined;
177
+ };
178
+ declare class StorybookCoverageReporter extends ReportBase implements Partial<Visitor> {
179
+ #private;
180
+ constructor(opts: StorybookCoverageReporterOptions);
181
+ onSummary(node: ReportNode): void;
182
+ }
183
+
184
+ export { StorybookCoverageReporterOptions, StorybookCoverageReporter as default };