@storybook/addon-vitest 0.0.0-pr-32412-sha-4e0feb24 → 0.0.0-pr-32458-sha-a8934fc9

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/preset.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_tr2v1yz0ftg from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_tr2v1yz0ftg from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_tr2v1yz0ftg from "node:module";
1
+ import CJS_COMPAT_NODE_URL_5w076g95rck from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_5w076g95rck from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_5w076g95rck from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_tr2v1yz0ftg.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_tr2v1yz0ftg.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_tr2v1yz0ftg.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_5w076g95rck.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_5w076g95rck.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_5w076g95rck.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -12,11 +12,11 @@ var require = CJS_COMPAT_NODE_MODULE_tr2v1yz0ftg.createRequire(import.meta.url);
12
12
  import {
13
13
  log,
14
14
  noop
15
- } from "./_node-chunks/chunk-Y3DMC4DM.js";
15
+ } from "./_node-chunks/chunk-T4BKNWFR.js";
16
16
  import {
17
17
  execaNode,
18
18
  importMetaResolve
19
- } from "./_node-chunks/chunk-5HXFH4CR.js";
19
+ } from "./_node-chunks/chunk-5IRNZM6E.js";
20
20
  import {
21
21
  ADDON_ID,
22
22
  COVERAGE_DIRECTORY,
@@ -25,17 +25,17 @@ import {
25
25
  STORYBOOK_ADDON_TEST_CHANNEL,
26
26
  TEST_PROVIDER_STORE_CHANNEL_EVENT_NAME,
27
27
  storeOptions
28
- } from "./_node-chunks/chunk-OZHW4RTJ.js";
28
+ } from "./_node-chunks/chunk-3USXLZ32.js";
29
29
  import {
30
30
  require_picocolors
31
- } from "./_node-chunks/chunk-N34KX3CN.js";
31
+ } from "./_node-chunks/chunk-226MMIJW.js";
32
32
  import {
33
33
  normalize
34
- } from "./_node-chunks/chunk-MHB2QQK5.js";
34
+ } from "./_node-chunks/chunk-T4U7VHZY.js";
35
35
  import {
36
36
  __name,
37
37
  __toESM
38
- } from "./_node-chunks/chunk-X2ZIL2ID.js";
38
+ } from "./_node-chunks/chunk-E3O3SZWH.js";
39
39
 
40
40
  // src/preset.ts
41
41
  import { mkdir } from "node:fs/promises";
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_tr2v1yz0ftg from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_tr2v1yz0ftg from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_tr2v1yz0ftg from "node:module";
1
+ import CJS_COMPAT_NODE_URL_5w076g95rck from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_5w076g95rck from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_5w076g95rck from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_tr2v1yz0ftg.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_tr2v1yz0ftg.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_tr2v1yz0ftg.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_5w076g95rck.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_5w076g95rck.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_5w076g95rck.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -14,7 +14,7 @@ import {
14
14
  __name,
15
15
  __require,
16
16
  __toESM
17
- } from "../_node-chunks/chunk-X2ZIL2ID.js";
17
+ } from "../_node-chunks/chunk-E3O3SZWH.js";
18
18
 
19
19
  // ../../node_modules/tree-kill/index.js
20
20
  var require_tree_kill = __commonJS({
@@ -1,30 +1,30 @@
1
- import CJS_COMPAT_NODE_URL_tr2v1yz0ftg from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_tr2v1yz0ftg from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_tr2v1yz0ftg from "node:module";
1
+ import CJS_COMPAT_NODE_URL_5w076g95rck from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_5w076g95rck from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_5w076g95rck from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_tr2v1yz0ftg.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_tr2v1yz0ftg.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_tr2v1yz0ftg.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_5w076g95rck.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_5w076g95rck.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_5w076g95rck.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
  require_picocolors
14
- } from "../_node-chunks/chunk-N34KX3CN.js";
14
+ } from "../_node-chunks/chunk-226MMIJW.js";
15
15
  import {
16
16
  join,
17
17
  normalize,
18
18
  relative,
19
19
  resolve,
20
20
  sep
21
- } from "../_node-chunks/chunk-MHB2QQK5.js";
21
+ } from "../_node-chunks/chunk-T4U7VHZY.js";
22
22
  import {
23
23
  __commonJS,
24
24
  __name,
25
25
  __require,
26
26
  __toESM
27
- } from "../_node-chunks/chunk-X2ZIL2ID.js";
27
+ } from "../_node-chunks/chunk-E3O3SZWH.js";
28
28
 
29
29
  // ../../node_modules/braces/lib/utils.js
30
30
  var require_utils = __commonJS({
@@ -3592,7 +3592,8 @@ var storybookTest = /* @__PURE__ */ __name(async (options) => {
3592
3592
  staticDirs,
3593
3593
  previewLevelTags,
3594
3594
  core,
3595
- extraOptimizeDeps
3595
+ extraOptimizeDeps,
3596
+ features
3596
3597
  ] = await Promise.all([
3597
3598
  getStoryGlobsAndFiles(presets, directories),
3598
3599
  presets.apply("framework", void 0),
@@ -3601,7 +3602,8 @@ var storybookTest = /* @__PURE__ */ __name(async (options) => {
3601
3602
  presets.apply("staticDirs", []),
3602
3603
  extractTagsFromPreview(finalOptions.configDir),
3603
3604
  presets.apply("core"),
3604
- presets.apply("optimizeViteDeps", [])
3605
+ presets.apply("optimizeViteDeps", []),
3606
+ presets.apply("features", {})
3605
3607
  ]);
3606
3608
  const pluginsToIgnore = [
3607
3609
  "storybook:react-docgen-plugin",
@@ -3731,7 +3733,8 @@ var storybookTest = /* @__PURE__ */ __name(async (options) => {
3731
3733
  ]
3732
3734
  },
3733
3735
  define: {
3734
- ...frameworkName?.includes("vue3") ? { __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "false" } : {}
3736
+ ...frameworkName?.includes("vue3") ? { __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "false" } : {},
3737
+ FEATURES: JSON.stringify(features)
3735
3738
  }
3736
3739
  };
3737
3740
  const config = mergeConfig(
@@ -3,6 +3,7 @@ import {
3
3
  } from "../_browser-chunks/chunk-JK72E6FR.js";
4
4
 
5
5
  // src/vitest-plugin/test-utils.ts
6
+ import { getStoryChildren, isStory } from "storybook/internal/csf";
6
7
  import { server } from "@vitest/browser/context";
7
8
  import { composeStory, getCsfFactoryAnnotations } from "storybook/preview-api";
8
9
 
@@ -53,15 +54,15 @@ var setViewport = /* @__PURE__ */ __name(async (parameters = {}, globals = {}) =
53
54
  if (!page || !globalThis.__vitest_browser__) {
54
55
  return;
55
56
  }
56
- const viewports = {
57
+ const options = {
57
58
  ...MINIMAL_VIEWPORTS,
58
59
  ...viewportsParam.viewports,
59
60
  ...viewportsParam.options
60
61
  };
61
62
  let viewportWidth = DEFAULT_VIEWPORT_DIMENSIONS.width;
62
63
  let viewportHeight = DEFAULT_VIEWPORT_DIMENSIONS.height;
63
- if (defaultViewport && defaultViewport in viewports) {
64
- const styles = viewports[defaultViewport].styles;
64
+ if (defaultViewport && defaultViewport in options) {
65
+ const { styles } = options[defaultViewport];
65
66
  if (styles?.width && styles?.height) {
66
67
  const { width, height } = styles;
67
68
  viewportWidth = parseDimension(width, "width");
@@ -78,11 +79,13 @@ var convertToFilePath = /* @__PURE__ */ __name((url) => {
78
79
  const normalizedPath = path.replace(/^\/+([a-zA-Z]:)/, "$1");
79
80
  return normalizedPath.replace(/%20/g, " ");
80
81
  }, "convertToFilePath");
81
- var testStory = /* @__PURE__ */ __name((exportName, story, meta, skipTags) => {
82
+ var testStory = /* @__PURE__ */ __name((exportName, story, meta, skipTags, storyId, testName) => {
82
83
  return async (context) => {
83
84
  const annotations = getCsfFactoryAnnotations(story, meta);
85
+ const test = isStory(story) && testName ? getStoryChildren(story).find((child) => child.input.name === testName) : void 0;
86
+ const storyAnnotations = test ? test.input : annotations.story;
84
87
  const composedStory = composeStory(
85
- annotations.story,
88
+ storyAnnotations,
86
89
  annotations.meta,
87
90
  { initialGlobals: await getInitialGlobals?.() ?? {} },
88
91
  annotations.preview ?? globalThis.globalProjectAnnotations,
@@ -93,9 +96,9 @@ var testStory = /* @__PURE__ */ __name((exportName, story, meta, skipTags) => {
93
96
  }
94
97
  context.story = composedStory;
95
98
  const _task = context.task;
96
- _task.meta.storyId = composedStory.id;
99
+ _task.meta.storyId = storyId;
97
100
  await setViewport(composedStory.parameters, composedStory.globals);
98
- await composedStory.run();
101
+ await composedStory.run(void 0);
99
102
  _task.meta.reports = composedStory.reporting.reports;
100
103
  };
101
104
  }, "testStory");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-vitest",
3
- "version": "0.0.0-pr-32412-sha-4e0feb24",
3
+ "version": "0.0.0-pr-32458-sha-a8934fc9",
4
4
  "description": "Storybook Vitest addon: Blazing fast component testing using stories",
5
5
  "keywords": [
6
6
  "storybook",
@@ -73,7 +73,7 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@storybook/global": "^5.0.0",
76
- "@storybook/icons": "^1.4.0",
76
+ "@storybook/icons": "^1.6.0",
77
77
  "prompts": "^2.4.0",
78
78
  "ts-dedent": "^2.2.0"
79
79
  },
@@ -85,9 +85,9 @@
85
85
  "@vitest/browser": "^3.2.4",
86
86
  "@vitest/runner": "^3.2.4",
87
87
  "boxen": "^8.0.1",
88
+ "empathic": "^2.0.0",
88
89
  "es-toolkit": "^1.36.0",
89
90
  "execa": "^8.0.1",
90
- "find-up": "^7.0.0",
91
91
  "istanbul-lib-report": "^3.0.1",
92
92
  "micromatch": "^4.0.8",
93
93
  "pathe": "^1.1.2",
@@ -106,7 +106,7 @@
106
106
  "peerDependencies": {
107
107
  "@vitest/browser": "^3.0.0",
108
108
  "@vitest/runner": "^3.0.0",
109
- "storybook": "^0.0.0-pr-32412-sha-4e0feb24",
109
+ "storybook": "^0.0.0-pr-32458-sha-a8934fc9",
110
110
  "vitest": "^3.0.0"
111
111
  },
112
112
  "peerDependenciesMeta": {
@@ -1,295 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_tr2v1yz0ftg from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_tr2v1yz0ftg from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_tr2v1yz0ftg from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_tr2v1yz0ftg.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_tr2v1yz0ftg.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_tr2v1yz0ftg.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
- import {
13
- __name
14
- } from "./chunk-X2ZIL2ID.js";
15
-
16
- // src/utils.ts
17
- function getAddonNames(mainConfig) {
18
- const addons = mainConfig.addons || [];
19
- const addonList = addons.map((addon) => {
20
- let name = "";
21
- if (typeof addon === "string") {
22
- name = addon;
23
- } else if (typeof addon === "object") {
24
- name = addon.name;
25
- }
26
- return name;
27
- });
28
- return addonList.filter((item) => item != null);
29
- }
30
- __name(getAddonNames, "getAddonNames");
31
- function errorToErrorLike(error) {
32
- return {
33
- message: error.message,
34
- name: error.name,
35
- // avoid duplicating the error message in the stack trace
36
- stack: error.stack?.replace(error.message, ""),
37
- cause: error.cause && error.cause instanceof Error ? errorToErrorLike(error.cause) : void 0
38
- };
39
- }
40
- __name(errorToErrorLike, "errorToErrorLike");
41
-
42
- // ../../node_modules/find-up/index.js
43
- import path2 from "node:path";
44
-
45
- // ../../node_modules/locate-path/index.js
46
- import process from "node:process";
47
- import path from "node:path";
48
- import fs, { promises as fsPromises } from "node:fs";
49
- import { fileURLToPath } from "node:url";
50
-
51
- // ../../node_modules/yocto-queue/index.js
52
- var Node = class {
53
- static {
54
- __name(this, "Node");
55
- }
56
- value;
57
- next;
58
- constructor(value) {
59
- this.value = value;
60
- }
61
- };
62
- var Queue = class {
63
- static {
64
- __name(this, "Queue");
65
- }
66
- #head;
67
- #tail;
68
- #size;
69
- constructor() {
70
- this.clear();
71
- }
72
- enqueue(value) {
73
- const node = new Node(value);
74
- if (this.#head) {
75
- this.#tail.next = node;
76
- this.#tail = node;
77
- } else {
78
- this.#head = node;
79
- this.#tail = node;
80
- }
81
- this.#size++;
82
- }
83
- dequeue() {
84
- const current = this.#head;
85
- if (!current) {
86
- return;
87
- }
88
- this.#head = this.#head.next;
89
- this.#size--;
90
- return current.value;
91
- }
92
- peek() {
93
- if (!this.#head) {
94
- return;
95
- }
96
- return this.#head.value;
97
- }
98
- clear() {
99
- this.#head = void 0;
100
- this.#tail = void 0;
101
- this.#size = 0;
102
- }
103
- get size() {
104
- return this.#size;
105
- }
106
- *[Symbol.iterator]() {
107
- let current = this.#head;
108
- while (current) {
109
- yield current.value;
110
- current = current.next;
111
- }
112
- }
113
- *drain() {
114
- while (this.#head) {
115
- yield this.dequeue();
116
- }
117
- }
118
- };
119
-
120
- // ../../node_modules/locate-path/node_modules/p-limit/index.js
121
- function pLimit(concurrency) {
122
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
123
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
124
- }
125
- const queue = new Queue();
126
- let activeCount = 0;
127
- const next = /* @__PURE__ */ __name(() => {
128
- activeCount--;
129
- if (queue.size > 0) {
130
- queue.dequeue()();
131
- }
132
- }, "next");
133
- const run = /* @__PURE__ */ __name(async (fn, resolve, args) => {
134
- activeCount++;
135
- const result = (async () => fn(...args))();
136
- resolve(result);
137
- try {
138
- await result;
139
- } catch {
140
- }
141
- next();
142
- }, "run");
143
- const enqueue = /* @__PURE__ */ __name((fn, resolve, args) => {
144
- queue.enqueue(run.bind(void 0, fn, resolve, args));
145
- (async () => {
146
- await Promise.resolve();
147
- if (activeCount < concurrency && queue.size > 0) {
148
- queue.dequeue()();
149
- }
150
- })();
151
- }, "enqueue");
152
- const generator = /* @__PURE__ */ __name((fn, ...args) => new Promise((resolve) => {
153
- enqueue(fn, resolve, args);
154
- }), "generator");
155
- Object.defineProperties(generator, {
156
- activeCount: {
157
- get: /* @__PURE__ */ __name(() => activeCount, "get")
158
- },
159
- pendingCount: {
160
- get: /* @__PURE__ */ __name(() => queue.size, "get")
161
- },
162
- clearQueue: {
163
- value: /* @__PURE__ */ __name(() => {
164
- queue.clear();
165
- }, "value")
166
- }
167
- });
168
- return generator;
169
- }
170
- __name(pLimit, "pLimit");
171
-
172
- // ../../node_modules/locate-path/node_modules/p-locate/index.js
173
- var EndError = class extends Error {
174
- static {
175
- __name(this, "EndError");
176
- }
177
- constructor(value) {
178
- super();
179
- this.value = value;
180
- }
181
- };
182
- var testElement = /* @__PURE__ */ __name(async (element, tester) => tester(await element), "testElement");
183
- var finder = /* @__PURE__ */ __name(async (element) => {
184
- const values = await Promise.all(element);
185
- if (values[1] === true) {
186
- throw new EndError(values[0]);
187
- }
188
- return false;
189
- }, "finder");
190
- async function pLocate(iterable, tester, {
191
- concurrency = Number.POSITIVE_INFINITY,
192
- preserveOrder = true
193
- } = {}) {
194
- const limit = pLimit(concurrency);
195
- const items = [...iterable].map((element) => [element, limit(testElement, element, tester)]);
196
- const checkLimit = pLimit(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
197
- try {
198
- await Promise.all(items.map((element) => checkLimit(finder, element)));
199
- } catch (error) {
200
- if (error instanceof EndError) {
201
- return error.value;
202
- }
203
- throw error;
204
- }
205
- }
206
- __name(pLocate, "pLocate");
207
-
208
- // ../../node_modules/locate-path/index.js
209
- var typeMappings = {
210
- directory: "isDirectory",
211
- file: "isFile"
212
- };
213
- function checkType(type) {
214
- if (Object.hasOwnProperty.call(typeMappings, type)) {
215
- return;
216
- }
217
- throw new Error(`Invalid type specified: ${type}`);
218
- }
219
- __name(checkType, "checkType");
220
- var matchType = /* @__PURE__ */ __name((type, stat) => stat[typeMappings[type]](), "matchType");
221
- var toPath = /* @__PURE__ */ __name((urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath, "toPath");
222
- async function locatePath(paths, {
223
- cwd = process.cwd(),
224
- type = "file",
225
- allowSymlinks = true,
226
- concurrency,
227
- preserveOrder
228
- } = {}) {
229
- checkType(type);
230
- cwd = toPath(cwd);
231
- const statFunction = allowSymlinks ? fsPromises.stat : fsPromises.lstat;
232
- return pLocate(paths, async (path_) => {
233
- try {
234
- const stat = await statFunction(path.resolve(cwd, path_));
235
- return matchType(type, stat);
236
- } catch {
237
- return false;
238
- }
239
- }, { concurrency, preserveOrder });
240
- }
241
- __name(locatePath, "locatePath");
242
-
243
- // ../../node_modules/find-up/node_modules/unicorn-magic/node.js
244
- import { fileURLToPath as fileURLToPath2 } from "node:url";
245
- function toPath2(urlOrPath) {
246
- return urlOrPath instanceof URL ? fileURLToPath2(urlOrPath) : urlOrPath;
247
- }
248
- __name(toPath2, "toPath");
249
-
250
- // ../../node_modules/find-up/index.js
251
- var findUpStop = Symbol("findUpStop");
252
- async function findUpMultiple(name, options = {}) {
253
- let directory = path2.resolve(toPath2(options.cwd) ?? "");
254
- const { root } = path2.parse(directory);
255
- const stopAt = path2.resolve(directory, toPath2(options.stopAt ?? root));
256
- const limit = options.limit ?? Number.POSITIVE_INFINITY;
257
- const paths = [name].flat();
258
- const runMatcher = /* @__PURE__ */ __name(async (locateOptions) => {
259
- if (typeof name !== "function") {
260
- return locatePath(paths, locateOptions);
261
- }
262
- const foundPath = await name(locateOptions.cwd);
263
- if (typeof foundPath === "string") {
264
- return locatePath([foundPath], locateOptions);
265
- }
266
- return foundPath;
267
- }, "runMatcher");
268
- const matches = [];
269
- while (true) {
270
- const foundPath = await runMatcher({ ...options, cwd: directory });
271
- if (foundPath === findUpStop) {
272
- break;
273
- }
274
- if (foundPath) {
275
- matches.push(path2.resolve(directory, foundPath));
276
- }
277
- if (directory === stopAt || matches.length >= limit) {
278
- break;
279
- }
280
- directory = path2.dirname(directory);
281
- }
282
- return matches;
283
- }
284
- __name(findUpMultiple, "findUpMultiple");
285
- async function findUp(name, options = {}) {
286
- const matches = await findUpMultiple(name, { ...options, limit: 1 });
287
- return matches[0];
288
- }
289
- __name(findUp, "findUp");
290
-
291
- export {
292
- getAddonNames,
293
- errorToErrorLike,
294
- findUp
295
- };