@cappa/plugin-storybook 0.2.4 → 0.2.6
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/.turbo/turbo-build.log +38 -39
- package/CHANGELOG.md +15 -0
- package/dist/index.d.mts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +21 -6
- package/dist/index.mjs +21 -6
- package/package.json +3 -2
- package/src/cappa/plugin.test.ts +380 -0
- package/src/cappa/plugin.ts +69 -11
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[34mCLI[39m
|
|
7
|
-
[34mCLI[39m
|
|
8
|
-
[34mCLI[39m tsup
|
|
9
|
-
[34mCLI[39m
|
|
10
|
-
[34mCLI[39m
|
|
11
|
-
[34mCLI[39m
|
|
12
|
-
[34mCLI[39m tsup
|
|
13
|
-
[34mCLI[39m
|
|
14
|
-
[34mCLI[39m
|
|
15
|
-
[34mCLI[39m
|
|
16
|
-
[34mCLI[39m tsup
|
|
17
|
-
[34mCLI[39m
|
|
18
|
-
[34mCLI[39m Target:
|
|
19
|
-
[34mCLI[39m Target: node16
|
|
20
|
-
[34mCLI[39m
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[32mESM[39m
|
|
29
|
-
[32mESM[39m
|
|
30
|
-
[32mESM[39m
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[32mESM[39m
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
DTS dist/index.d.mts 905.00 B
|
|
1
|
+
|
|
2
|
+
> @cappa/plugin-storybook@0.2.6 build /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook
|
|
3
|
+
> tsup
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.5.0
|
|
8
|
+
[34mCLI[39m Using tsup config: /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
9
|
+
[34mCLI[39m Building entry: src/storybook/addon/browser.ts
|
|
10
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
11
|
+
[34mCLI[39m tsup v8.5.0
|
|
12
|
+
[34mCLI[39m Using tsup config: /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
13
|
+
[34mCLI[39m Building entry: src/storybook/addon/preview.ts
|
|
14
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
15
|
+
[34mCLI[39m tsup v8.5.0
|
|
16
|
+
[34mCLI[39m Using tsup config: /home/runner/work/cappa/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
17
|
+
[34mCLI[39m Target: esnext
|
|
18
|
+
[34mCLI[39m Target: es2015
|
|
19
|
+
[34mCLI[39m Target: node16
|
|
20
|
+
[34mCLI[39m Cleaning output folder
|
|
21
|
+
[34mCJS[39m Build start
|
|
22
|
+
[34mESM[39m Build start
|
|
23
|
+
[34mCLI[39m Cleaning output folder
|
|
24
|
+
[34mESM[39m Build start
|
|
25
|
+
[34mCLI[39m Cleaning output folder
|
|
26
|
+
[34mESM[39m Build start
|
|
27
|
+
[32mESM[39m [1mdist/browser.mjs [22m[32m138.00 B[39m
|
|
28
|
+
[32mESM[39m ⚡️ Build success in 50ms
|
|
29
|
+
[32mESM[39m [1mdist/preview.mjs [22m[32m1.41 KB[39m
|
|
30
|
+
[32mESM[39m ⚡️ Build success in 46ms
|
|
31
|
+
[32mCJS[39m [1mdist/index.js [22m[32m13.96 KB[39m
|
|
32
|
+
[32mCJS[39m ⚡️ Build success in 62ms
|
|
33
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m12.52 KB[39m
|
|
34
|
+
[32mESM[39m ⚡️ Build success in 63ms
|
|
35
|
+
[34mDTS[39m Build start
|
|
36
|
+
[32mDTS[39m ⚡️ Build success in 3613ms
|
|
37
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m2.63 KB[39m
|
|
38
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m2.63 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @cappa/plugin-storybook
|
|
2
2
|
|
|
3
|
+
## 0.2.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 80b44af: feat: add glob pattern for storybook include/exclude options
|
|
8
|
+
- Updated dependencies [e0f7f08]
|
|
9
|
+
- @cappa/core@0.3.0
|
|
10
|
+
|
|
11
|
+
## 0.2.5
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [faa5c05]
|
|
16
|
+
- @cappa/core@0.2.5
|
|
17
|
+
|
|
3
18
|
## 0.2.4
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -32,7 +32,34 @@ interface ScreenshotOptionsStorybook extends ScreenshotVariantOverrideStorybook
|
|
|
32
32
|
|
|
33
33
|
interface StorybookPluginOptions {
|
|
34
34
|
storybookUrl: string;
|
|
35
|
+
/**
|
|
36
|
+
* Array of glob patterns to include stories. Stories matching any of these patterns will be included.
|
|
37
|
+
* Patterns can match against:
|
|
38
|
+
* - Story ID (e.g., "button--primary")
|
|
39
|
+
* - Story title (e.g., "Button")
|
|
40
|
+
* - Story name (e.g., "Primary")
|
|
41
|
+
* - Full story path (e.g., "Button/Primary")
|
|
42
|
+
*
|
|
43
|
+
* Examples:
|
|
44
|
+
* - ["button--*"] - Include all button stories
|
|
45
|
+
* - ["*--primary"] - Include all primary stories
|
|
46
|
+
* - ["Button/*"] - Include all stories under Button title
|
|
47
|
+
* - ["*--*"] - Include all stories
|
|
48
|
+
*/
|
|
35
49
|
includeStories?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Array of glob patterns to exclude stories. Stories matching any of these patterns will be excluded.
|
|
52
|
+
* Patterns can match against:
|
|
53
|
+
* - Story ID (e.g., "button--primary")
|
|
54
|
+
* - Story title (e.g., "Button")
|
|
55
|
+
* - Story name (e.g., "Primary")
|
|
56
|
+
* - Full story path (e.g., "Button/Primary")
|
|
57
|
+
*
|
|
58
|
+
* Examples:
|
|
59
|
+
* - ["button--*"] - Exclude all button stories
|
|
60
|
+
* - ["*--secondary"] - Exclude all secondary stories
|
|
61
|
+
* - ["Input/*"] - Exclude all stories under Input title
|
|
62
|
+
*/
|
|
36
63
|
excludeStories?: string[];
|
|
37
64
|
defaultViewport?: {
|
|
38
65
|
width: number;
|
|
@@ -44,7 +71,8 @@ interface StorybookPluginOptions {
|
|
|
44
71
|
}
|
|
45
72
|
/**
|
|
46
73
|
* Storybook Plugin for Cappa
|
|
47
|
-
* Fetches stories from a running Storybook server and takes screenshots of each story
|
|
74
|
+
* Fetches stories from a running Storybook server and takes screenshots of each story.
|
|
75
|
+
* Supports glob pattern matching for includeStories and excludeStories options.
|
|
48
76
|
*/
|
|
49
77
|
declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
|
|
50
78
|
|
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,34 @@ interface ScreenshotOptionsStorybook extends ScreenshotVariantOverrideStorybook
|
|
|
32
32
|
|
|
33
33
|
interface StorybookPluginOptions {
|
|
34
34
|
storybookUrl: string;
|
|
35
|
+
/**
|
|
36
|
+
* Array of glob patterns to include stories. Stories matching any of these patterns will be included.
|
|
37
|
+
* Patterns can match against:
|
|
38
|
+
* - Story ID (e.g., "button--primary")
|
|
39
|
+
* - Story title (e.g., "Button")
|
|
40
|
+
* - Story name (e.g., "Primary")
|
|
41
|
+
* - Full story path (e.g., "Button/Primary")
|
|
42
|
+
*
|
|
43
|
+
* Examples:
|
|
44
|
+
* - ["button--*"] - Include all button stories
|
|
45
|
+
* - ["*--primary"] - Include all primary stories
|
|
46
|
+
* - ["Button/*"] - Include all stories under Button title
|
|
47
|
+
* - ["*--*"] - Include all stories
|
|
48
|
+
*/
|
|
35
49
|
includeStories?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Array of glob patterns to exclude stories. Stories matching any of these patterns will be excluded.
|
|
52
|
+
* Patterns can match against:
|
|
53
|
+
* - Story ID (e.g., "button--primary")
|
|
54
|
+
* - Story title (e.g., "Button")
|
|
55
|
+
* - Story name (e.g., "Primary")
|
|
56
|
+
* - Full story path (e.g., "Button/Primary")
|
|
57
|
+
*
|
|
58
|
+
* Examples:
|
|
59
|
+
* - ["button--*"] - Exclude all button stories
|
|
60
|
+
* - ["*--secondary"] - Exclude all secondary stories
|
|
61
|
+
* - ["Input/*"] - Exclude all stories under Input title
|
|
62
|
+
*/
|
|
36
63
|
excludeStories?: string[];
|
|
37
64
|
defaultViewport?: {
|
|
38
65
|
width: number;
|
|
@@ -44,7 +71,8 @@ interface StorybookPluginOptions {
|
|
|
44
71
|
}
|
|
45
72
|
/**
|
|
46
73
|
* Storybook Plugin for Cappa
|
|
47
|
-
* Fetches stories from a running Storybook server and takes screenshots of each story
|
|
74
|
+
* Fetches stories from a running Storybook server and takes screenshots of each story.
|
|
75
|
+
* Supports glob pattern matching for includeStories and excludeStories options.
|
|
48
76
|
*/
|
|
49
77
|
declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
|
|
50
78
|
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
37
37
|
|
|
38
38
|
// src/cappa/plugin.ts
|
|
39
39
|
var import_logger = require("@cappa/logger");
|
|
40
|
+
var import_minimatch = require("minimatch");
|
|
40
41
|
|
|
41
42
|
// src/cappa/storybook-url.ts
|
|
42
43
|
function encodePairs(obj) {
|
|
@@ -176,6 +177,24 @@ async function waitForPlayFunctionCompletion(page, storyName) {
|
|
|
176
177
|
});
|
|
177
178
|
}
|
|
178
179
|
}
|
|
180
|
+
function matchesGlobPatterns(story, patterns) {
|
|
181
|
+
return patterns.some((pattern) => {
|
|
182
|
+
if ((0, import_minimatch.minimatch)(story.id, pattern)) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
if ((0, import_minimatch.minimatch)(story.title, pattern)) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
if ((0, import_minimatch.minimatch)(story.name, pattern)) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
const fullPath = `${story.title}/${story.name}`;
|
|
192
|
+
if ((0, import_minimatch.minimatch)(fullPath, pattern)) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
179
198
|
function createLatch() {
|
|
180
199
|
let resolve;
|
|
181
200
|
const p = new Promise((r) => resolve = r);
|
|
@@ -212,16 +231,12 @@ var cappaPluginStorybook = (options) => {
|
|
|
212
231
|
let filteredStories = stories;
|
|
213
232
|
if (includeStories.length > 0) {
|
|
214
233
|
filteredStories = filteredStories.filter(
|
|
215
|
-
(story) => includeStories
|
|
216
|
-
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
217
|
-
)
|
|
234
|
+
(story) => matchesGlobPatterns(story, includeStories)
|
|
218
235
|
);
|
|
219
236
|
}
|
|
220
237
|
if (excludeStories.length > 0) {
|
|
221
238
|
filteredStories = filteredStories.filter(
|
|
222
|
-
(story) => !excludeStories
|
|
223
|
-
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
224
|
-
)
|
|
239
|
+
(story) => !matchesGlobPatterns(story, excludeStories)
|
|
225
240
|
);
|
|
226
241
|
}
|
|
227
242
|
filteredStories = filteredStories.filter(
|
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
7
7
|
|
|
8
8
|
// src/cappa/plugin.ts
|
|
9
9
|
import { getLogger } from "@cappa/logger";
|
|
10
|
+
import { minimatch } from "minimatch";
|
|
10
11
|
|
|
11
12
|
// src/cappa/storybook-url.ts
|
|
12
13
|
function encodePairs(obj) {
|
|
@@ -146,6 +147,24 @@ async function waitForPlayFunctionCompletion(page, storyName) {
|
|
|
146
147
|
});
|
|
147
148
|
}
|
|
148
149
|
}
|
|
150
|
+
function matchesGlobPatterns(story, patterns) {
|
|
151
|
+
return patterns.some((pattern) => {
|
|
152
|
+
if (minimatch(story.id, pattern)) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
if (minimatch(story.title, pattern)) {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
if (minimatch(story.name, pattern)) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
const fullPath = `${story.title}/${story.name}`;
|
|
162
|
+
if (minimatch(fullPath, pattern)) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
149
168
|
function createLatch() {
|
|
150
169
|
let resolve;
|
|
151
170
|
const p = new Promise((r) => resolve = r);
|
|
@@ -182,16 +201,12 @@ var cappaPluginStorybook = (options) => {
|
|
|
182
201
|
let filteredStories = stories;
|
|
183
202
|
if (includeStories.length > 0) {
|
|
184
203
|
filteredStories = filteredStories.filter(
|
|
185
|
-
(story) => includeStories
|
|
186
|
-
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
187
|
-
)
|
|
204
|
+
(story) => matchesGlobPatterns(story, includeStories)
|
|
188
205
|
);
|
|
189
206
|
}
|
|
190
207
|
if (excludeStories.length > 0) {
|
|
191
208
|
filteredStories = filteredStories.filter(
|
|
192
|
-
(story) => !excludeStories
|
|
193
|
-
(pattern) => story.title.includes(pattern) || story.name.includes(pattern)
|
|
194
|
-
)
|
|
209
|
+
(story) => !matchesGlobPatterns(story, excludeStories)
|
|
195
210
|
);
|
|
196
211
|
}
|
|
197
212
|
filteredStories = filteredStories.filter(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappa/plugin-storybook",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -30,8 +30,9 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@swc/core": "^1.13.5",
|
|
32
32
|
"chalk": "^5.6.2",
|
|
33
|
+
"minimatch": "^10.0.3",
|
|
33
34
|
"storybook": "^9.1.12",
|
|
34
|
-
"@cappa/core": "0.
|
|
35
|
+
"@cappa/core": "0.3.0",
|
|
35
36
|
"@cappa/logger": "0.0.4"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { cappaPluginStorybook, type StorybookStory } from "./plugin";
|
|
3
|
+
|
|
4
|
+
// Mock the logger
|
|
5
|
+
vi.mock("@cappa/logger", () => ({
|
|
6
|
+
getLogger: () => ({
|
|
7
|
+
debug: vi.fn(),
|
|
8
|
+
start: vi.fn(),
|
|
9
|
+
warn: vi.fn(),
|
|
10
|
+
error: vi.fn(),
|
|
11
|
+
}),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
// Mock fetch
|
|
15
|
+
global.fetch = vi.fn();
|
|
16
|
+
|
|
17
|
+
describe("cappaPluginStorybook - Glob Pattern Matching", () => {
|
|
18
|
+
const mockStories: StorybookStory[] = [
|
|
19
|
+
{
|
|
20
|
+
id: "button--primary",
|
|
21
|
+
name: "Primary",
|
|
22
|
+
title: "Button",
|
|
23
|
+
kind: "Button",
|
|
24
|
+
story: "Primary",
|
|
25
|
+
type: "story",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "button--secondary",
|
|
29
|
+
name: "Secondary",
|
|
30
|
+
title: "Button",
|
|
31
|
+
kind: "Button",
|
|
32
|
+
story: "Secondary",
|
|
33
|
+
type: "story",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "input--default",
|
|
37
|
+
name: "Default",
|
|
38
|
+
title: "Input",
|
|
39
|
+
kind: "Input",
|
|
40
|
+
story: "Default",
|
|
41
|
+
type: "story",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: "input--with-label",
|
|
45
|
+
name: "With Label",
|
|
46
|
+
title: "Input",
|
|
47
|
+
kind: "Input",
|
|
48
|
+
story: "With Label",
|
|
49
|
+
type: "story",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "card--basic",
|
|
53
|
+
name: "Basic",
|
|
54
|
+
title: "Card",
|
|
55
|
+
kind: "Card",
|
|
56
|
+
story: "Basic",
|
|
57
|
+
type: "story",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "card--advanced",
|
|
61
|
+
name: "Advanced",
|
|
62
|
+
title: "Card",
|
|
63
|
+
kind: "Card",
|
|
64
|
+
story: "Advanced",
|
|
65
|
+
type: "story",
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const mockStorybookResponse = {
|
|
70
|
+
entries: mockStories.reduce(
|
|
71
|
+
(acc, story) => {
|
|
72
|
+
acc[story.id] = story;
|
|
73
|
+
return acc;
|
|
74
|
+
},
|
|
75
|
+
{} as Record<string, StorybookStory>,
|
|
76
|
+
),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
vi.clearAllMocks();
|
|
81
|
+
(global.fetch as any).mockResolvedValue({
|
|
82
|
+
ok: true,
|
|
83
|
+
json: () => Promise.resolve(mockStorybookResponse),
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe("includeStories glob patterns", () => {
|
|
88
|
+
it("should include stories matching exact story id", async () => {
|
|
89
|
+
const plugin = cappaPluginStorybook({
|
|
90
|
+
storybookUrl: "http://localhost:6006",
|
|
91
|
+
includeStories: ["button--primary"],
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const result = await plugin.discover();
|
|
95
|
+
expect(result).toHaveLength(1);
|
|
96
|
+
expect(result[0].data.story.id).toBe("button--primary");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("should include stories matching wildcard patterns", async () => {
|
|
100
|
+
const plugin = cappaPluginStorybook({
|
|
101
|
+
storybookUrl: "http://localhost:6006",
|
|
102
|
+
includeStories: ["button--*"],
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const result = await plugin.discover();
|
|
106
|
+
expect(result).toHaveLength(2);
|
|
107
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
108
|
+
"button--primary",
|
|
109
|
+
"button--secondary",
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("should include stories matching title patterns", async () => {
|
|
114
|
+
const plugin = cappaPluginStorybook({
|
|
115
|
+
storybookUrl: "http://localhost:6006",
|
|
116
|
+
includeStories: ["Button"],
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const result = await plugin.discover();
|
|
120
|
+
expect(result).toHaveLength(2);
|
|
121
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
122
|
+
"button--primary",
|
|
123
|
+
"button--secondary",
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("should include stories matching name patterns", async () => {
|
|
128
|
+
const plugin = cappaPluginStorybook({
|
|
129
|
+
storybookUrl: "http://localhost:6006",
|
|
130
|
+
includeStories: ["Primary"],
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const result = await plugin.discover();
|
|
134
|
+
expect(result).toHaveLength(1);
|
|
135
|
+
expect(result[0].data.story.id).toBe("button--primary");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should include stories matching full path patterns", async () => {
|
|
139
|
+
const plugin = cappaPluginStorybook({
|
|
140
|
+
storybookUrl: "http://localhost:6006",
|
|
141
|
+
includeStories: ["Button/*"],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const result = await plugin.discover();
|
|
145
|
+
expect(result).toHaveLength(2);
|
|
146
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
147
|
+
"button--primary",
|
|
148
|
+
"button--secondary",
|
|
149
|
+
]);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("should include stories matching multiple patterns", async () => {
|
|
153
|
+
const plugin = cappaPluginStorybook({
|
|
154
|
+
storybookUrl: "http://localhost:6006",
|
|
155
|
+
includeStories: ["button--*", "input--*"],
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const result = await plugin.discover();
|
|
159
|
+
expect(result).toHaveLength(4);
|
|
160
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
161
|
+
"button--primary",
|
|
162
|
+
"button--secondary",
|
|
163
|
+
"input--default",
|
|
164
|
+
"input--with-label",
|
|
165
|
+
]);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("should include stories matching complex glob patterns", async () => {
|
|
169
|
+
const plugin = cappaPluginStorybook({
|
|
170
|
+
storybookUrl: "http://localhost:6006",
|
|
171
|
+
includeStories: ["*--primary", "*--default"],
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const result = await plugin.discover();
|
|
175
|
+
expect(result).toHaveLength(2);
|
|
176
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
177
|
+
"button--primary",
|
|
178
|
+
"input--default",
|
|
179
|
+
]);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe("excludeStories glob patterns", () => {
|
|
184
|
+
it("should exclude stories matching exact story id", async () => {
|
|
185
|
+
const plugin = cappaPluginStorybook({
|
|
186
|
+
storybookUrl: "http://localhost:6006",
|
|
187
|
+
excludeStories: ["button--primary"],
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const result = await plugin.discover();
|
|
191
|
+
expect(result).toHaveLength(5);
|
|
192
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
193
|
+
"button--primary",
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("should exclude stories matching wildcard patterns", async () => {
|
|
198
|
+
const plugin = cappaPluginStorybook({
|
|
199
|
+
storybookUrl: "http://localhost:6006",
|
|
200
|
+
excludeStories: ["button--*"],
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const result = await plugin.discover();
|
|
204
|
+
expect(result).toHaveLength(4);
|
|
205
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
206
|
+
"button--primary",
|
|
207
|
+
);
|
|
208
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
209
|
+
"button--secondary",
|
|
210
|
+
);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("should exclude stories matching title patterns", async () => {
|
|
214
|
+
const plugin = cappaPluginStorybook({
|
|
215
|
+
storybookUrl: "http://localhost:6006",
|
|
216
|
+
excludeStories: ["Button"],
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const result = await plugin.discover();
|
|
220
|
+
expect(result).toHaveLength(4);
|
|
221
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
222
|
+
"button--primary",
|
|
223
|
+
);
|
|
224
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
225
|
+
"button--secondary",
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("should exclude stories matching name patterns", async () => {
|
|
230
|
+
const plugin = cappaPluginStorybook({
|
|
231
|
+
storybookUrl: "http://localhost:6006",
|
|
232
|
+
excludeStories: ["Primary"],
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const result = await plugin.discover();
|
|
236
|
+
expect(result).toHaveLength(5);
|
|
237
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
238
|
+
"button--primary",
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("should exclude stories matching full path patterns", async () => {
|
|
243
|
+
const plugin = cappaPluginStorybook({
|
|
244
|
+
storybookUrl: "http://localhost:6006",
|
|
245
|
+
excludeStories: ["Button/*"],
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const result = await plugin.discover();
|
|
249
|
+
expect(result).toHaveLength(4);
|
|
250
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
251
|
+
"button--primary",
|
|
252
|
+
);
|
|
253
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
254
|
+
"button--secondary",
|
|
255
|
+
);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("should exclude stories matching multiple patterns", async () => {
|
|
259
|
+
const plugin = cappaPluginStorybook({
|
|
260
|
+
storybookUrl: "http://localhost:6006",
|
|
261
|
+
excludeStories: ["button--*", "input--*"],
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
const result = await plugin.discover();
|
|
265
|
+
expect(result).toHaveLength(2);
|
|
266
|
+
expect(result.map((r) => r.data.story.id)).toEqual([
|
|
267
|
+
"card--basic",
|
|
268
|
+
"card--advanced",
|
|
269
|
+
]);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
describe("combined includeStories and excludeStories", () => {
|
|
274
|
+
it("should apply include patterns first, then exclude patterns", async () => {
|
|
275
|
+
const plugin = cappaPluginStorybook({
|
|
276
|
+
storybookUrl: "http://localhost:6006",
|
|
277
|
+
includeStories: ["*--*"], // Include all stories
|
|
278
|
+
excludeStories: ["button--*"], // Then exclude button stories
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
const result = await plugin.discover();
|
|
282
|
+
expect(result).toHaveLength(4);
|
|
283
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
284
|
+
"button--primary",
|
|
285
|
+
);
|
|
286
|
+
expect(result.map((r) => r.data.story.id)).not.toContain(
|
|
287
|
+
"button--secondary",
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("should work with overlapping patterns", async () => {
|
|
292
|
+
const plugin = cappaPluginStorybook({
|
|
293
|
+
storybookUrl: "http://localhost:6006",
|
|
294
|
+
includeStories: ["*--primary", "*--default"], // Include primary and default stories
|
|
295
|
+
excludeStories: ["button--*"], // Exclude all button stories
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const result = await plugin.discover();
|
|
299
|
+
expect(result).toHaveLength(1);
|
|
300
|
+
expect(result[0].data.story.id).toBe("input--default");
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
describe("edge cases", () => {
|
|
305
|
+
it("should handle empty includeStories array", async () => {
|
|
306
|
+
const plugin = cappaPluginStorybook({
|
|
307
|
+
storybookUrl: "http://localhost:6006",
|
|
308
|
+
includeStories: [],
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
const result = await plugin.discover();
|
|
312
|
+
expect(result).toHaveLength(6); // All stories included
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("should handle empty excludeStories array", async () => {
|
|
316
|
+
const plugin = cappaPluginStorybook({
|
|
317
|
+
storybookUrl: "http://localhost:6006",
|
|
318
|
+
excludeStories: [],
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
const result = await plugin.discover();
|
|
322
|
+
expect(result).toHaveLength(6); // All stories included
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("should handle patterns that match no stories", async () => {
|
|
326
|
+
const plugin = cappaPluginStorybook({
|
|
327
|
+
storybookUrl: "http://localhost:6006",
|
|
328
|
+
includeStories: ["nonexistent--*"],
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const result = await plugin.discover();
|
|
332
|
+
expect(result).toHaveLength(0);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it("should handle case-sensitive matching", async () => {
|
|
336
|
+
const plugin = cappaPluginStorybook({
|
|
337
|
+
storybookUrl: "http://localhost:6006",
|
|
338
|
+
includeStories: ["button"], // lowercase
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
const result = await plugin.discover();
|
|
342
|
+
expect(result).toHaveLength(0); // No matches because "Button" is capitalized
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("should handle special glob characters in story names", async () => {
|
|
346
|
+
// Add a story with special characters
|
|
347
|
+
const specialStory: StorybookStory = {
|
|
348
|
+
id: "special--with-dots.and-brackets[test]",
|
|
349
|
+
name: "With Dots.And Brackets[Test]",
|
|
350
|
+
title: "Special",
|
|
351
|
+
kind: "Special",
|
|
352
|
+
story: "With Dots.And Brackets[Test]",
|
|
353
|
+
type: "story",
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
const specialResponse = {
|
|
357
|
+
entries: {
|
|
358
|
+
...mockStorybookResponse.entries,
|
|
359
|
+
[specialStory.id]: specialStory,
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
(global.fetch as any).mockResolvedValue({
|
|
364
|
+
ok: true,
|
|
365
|
+
json: () => Promise.resolve(specialResponse),
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
const plugin = cappaPluginStorybook({
|
|
369
|
+
storybookUrl: "http://localhost:6006",
|
|
370
|
+
includeStories: ["special--*"],
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
const result = await plugin.discover();
|
|
374
|
+
expect(result).toHaveLength(1);
|
|
375
|
+
expect(result[0].data.story.id).toBe(
|
|
376
|
+
"special--with-dots.and-brackets[test]",
|
|
377
|
+
);
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
});
|
package/src/cappa/plugin.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ScreenshotVariantWithUrl,
|
|
5
5
|
} from "@cappa/core";
|
|
6
6
|
import { getLogger } from "@cappa/logger";
|
|
7
|
+
import { minimatch } from "minimatch";
|
|
7
8
|
import type { Page } from "playwright-core";
|
|
8
9
|
import type {
|
|
9
10
|
ScreenshotOptionsStorybook,
|
|
@@ -63,13 +64,76 @@ export interface StorybookStory {
|
|
|
63
64
|
type: "story" | "docs";
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Matches a story against glob patterns
|
|
69
|
+
* @param story - The story to match
|
|
70
|
+
* @param patterns - Array of glob patterns to match against
|
|
71
|
+
* @returns true if the story matches any of the patterns
|
|
72
|
+
*/
|
|
73
|
+
function matchesGlobPatterns(
|
|
74
|
+
story: StorybookStory,
|
|
75
|
+
patterns: string[],
|
|
76
|
+
): boolean {
|
|
77
|
+
return patterns.some((pattern) => {
|
|
78
|
+
// Match against story id (e.g., "button--primary")
|
|
79
|
+
if (minimatch(story.id, pattern)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Match against story title (e.g., "Button")
|
|
84
|
+
if (minimatch(story.title, pattern)) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Match against story name (e.g., "Primary")
|
|
89
|
+
if (minimatch(story.name, pattern)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Match against full story path (e.g., "Button/Primary")
|
|
94
|
+
const fullPath = `${story.title}/${story.name}`;
|
|
95
|
+
if (minimatch(fullPath, pattern)) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return false;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
66
103
|
interface StorybookStoriesResponse {
|
|
67
104
|
entries: Record<string, StorybookStory>;
|
|
68
105
|
}
|
|
69
106
|
|
|
70
107
|
interface StorybookPluginOptions {
|
|
71
108
|
storybookUrl: string;
|
|
109
|
+
/**
|
|
110
|
+
* Array of glob patterns to include stories. Stories matching any of these patterns will be included.
|
|
111
|
+
* Patterns can match against:
|
|
112
|
+
* - Story ID (e.g., "button--primary")
|
|
113
|
+
* - Story title (e.g., "Button")
|
|
114
|
+
* - Story name (e.g., "Primary")
|
|
115
|
+
* - Full story path (e.g., "Button/Primary")
|
|
116
|
+
*
|
|
117
|
+
* Examples:
|
|
118
|
+
* - ["button--*"] - Include all button stories
|
|
119
|
+
* - ["*--primary"] - Include all primary stories
|
|
120
|
+
* - ["Button/*"] - Include all stories under Button title
|
|
121
|
+
* - ["*--*"] - Include all stories
|
|
122
|
+
*/
|
|
72
123
|
includeStories?: string[];
|
|
124
|
+
/**
|
|
125
|
+
* Array of glob patterns to exclude stories. Stories matching any of these patterns will be excluded.
|
|
126
|
+
* Patterns can match against:
|
|
127
|
+
* - Story ID (e.g., "button--primary")
|
|
128
|
+
* - Story title (e.g., "Button")
|
|
129
|
+
* - Story name (e.g., "Primary")
|
|
130
|
+
* - Full story path (e.g., "Button/Primary")
|
|
131
|
+
*
|
|
132
|
+
* Examples:
|
|
133
|
+
* - ["button--*"] - Exclude all button stories
|
|
134
|
+
* - ["*--secondary"] - Exclude all secondary stories
|
|
135
|
+
* - ["Input/*"] - Exclude all stories under Input title
|
|
136
|
+
*/
|
|
73
137
|
excludeStories?: string[];
|
|
74
138
|
defaultViewport?: { width: number; height: number };
|
|
75
139
|
waitForSelector?: string;
|
|
@@ -91,7 +155,8 @@ function createLatch<T>() {
|
|
|
91
155
|
|
|
92
156
|
/**
|
|
93
157
|
* Storybook Plugin for Cappa
|
|
94
|
-
* Fetches stories from a running Storybook server and takes screenshots of each story
|
|
158
|
+
* Fetches stories from a running Storybook server and takes screenshots of each story.
|
|
159
|
+
* Supports glob pattern matching for includeStories and excludeStories options.
|
|
95
160
|
*/
|
|
96
161
|
export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
97
162
|
options,
|
|
@@ -131,25 +196,18 @@ export const cappaPluginStorybook: Plugin<StorybookPluginOptions> = (
|
|
|
131
196
|
const data = (await response.json()) as StorybookStoriesResponse;
|
|
132
197
|
const stories = Object.values(data.entries);
|
|
133
198
|
|
|
134
|
-
// Filter stories based on include/exclude patterns
|
|
199
|
+
// Filter stories based on include/exclude glob patterns
|
|
135
200
|
let filteredStories = stories;
|
|
136
201
|
|
|
137
202
|
if (includeStories.length > 0) {
|
|
138
203
|
filteredStories = filteredStories.filter((story) =>
|
|
139
|
-
includeStories
|
|
140
|
-
(pattern) =>
|
|
141
|
-
story.title.includes(pattern) || story.name.includes(pattern),
|
|
142
|
-
),
|
|
204
|
+
matchesGlobPatterns(story, includeStories),
|
|
143
205
|
);
|
|
144
206
|
}
|
|
145
207
|
|
|
146
208
|
if (excludeStories.length > 0) {
|
|
147
209
|
filteredStories = filteredStories.filter(
|
|
148
|
-
(story) =>
|
|
149
|
-
!excludeStories.some(
|
|
150
|
-
(pattern) =>
|
|
151
|
-
story.title.includes(pattern) || story.name.includes(pattern),
|
|
152
|
-
),
|
|
210
|
+
(story) => !matchesGlobPatterns(story, excludeStories),
|
|
153
211
|
);
|
|
154
212
|
}
|
|
155
213
|
|