@cappa/plugin-storybook 0.0.11 → 0.0.13
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 +36 -28
- package/CHANGELOG.md +16 -0
- package/README.md +96 -0
- package/dist/browser.mjs +7 -0
- package/dist/index.d.mts +14 -17
- package/dist/index.d.ts +14 -17
- package/dist/index.js +165 -182
- package/dist/index.mjs +143 -166
- package/dist/preview.mjs +58 -0
- package/package.json +14 -7
- package/src/cappa/plugin.ts +22 -53
- package/src/cappa/util.ts +2 -4
- package/src/index.ts +2 -1
- package/src/storybook/addon/browser.ts +6 -0
- package/src/storybook/{decorator.ts → addon/decorator.ts} +6 -1
- package/src/storybook/addon/preview.ts +15 -0
- package/src/storybook/util.ts +1 -1
- package/tsup.config.ts +29 -0
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/src/storybook/screenshot.ts +0 -108
- package/tsdown.config.ts +0 -10
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,31 +1,39 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @cappa/plugin-storybook@0.0.
|
|
4
|
-
>
|
|
3
|
+
> @cappa/plugin-storybook@0.0.12 build /home/tim/code/work/cappa/packages/plugins/plugin-storybook
|
|
4
|
+
> tsup
|
|
5
5
|
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
|
|
18
|
-
[
|
|
19
|
-
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
6
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
7
|
+
[34mCLI[39m Using tsconfig: ../../../tsconfig.json
|
|
8
|
+
[34mCLI[39m tsup v8.5.0
|
|
9
|
+
[34mCLI[39m Using tsup config: /home/tim/code/work/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
10
|
+
[34mCLI[39m Building entry: src/storybook/addon/preview.ts
|
|
11
|
+
[34mCLI[39m Using tsconfig: ../../../tsconfig.json
|
|
12
|
+
[34mCLI[39m tsup v8.5.0
|
|
13
|
+
[34mCLI[39m Using tsup config: /home/tim/code/work/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
14
|
+
[34mCLI[39m Building entry: src/storybook/addon/browser.ts
|
|
15
|
+
[34mCLI[39m Using tsconfig: ../../../tsconfig.json
|
|
16
|
+
[34mCLI[39m tsup v8.5.0
|
|
17
|
+
[34mCLI[39m Using tsup config: /home/tim/code/work/cappa/packages/plugins/plugin-storybook/tsup.config.ts
|
|
18
|
+
[34mCLI[39m Target: esnext
|
|
19
|
+
[34mCLI[39m Target: node16
|
|
20
|
+
[34mCLI[39m Target: es2015
|
|
21
|
+
[34mCLI[39m Cleaning output folder
|
|
22
|
+
[34mCJS[39m Build start
|
|
23
|
+
[34mESM[39m Build start
|
|
24
|
+
[34mCLI[39m Cleaning output folder
|
|
25
|
+
[34mESM[39m Build start
|
|
26
|
+
[34mCLI[39m Cleaning output folder
|
|
27
|
+
[34mESM[39m Build start
|
|
28
|
+
[32mESM[39m [1mdist/preview.mjs [22m[32m1.49 KB[39m
|
|
29
|
+
[32mESM[39m ⚡️ Build success in 7ms
|
|
30
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m5.70 KB[39m
|
|
31
|
+
[32mESM[39m ⚡️ Build success in 9ms
|
|
32
|
+
[32mCJS[39m [1mdist/index.js [22m[32m6.99 KB[39m
|
|
33
|
+
[32mCJS[39m ⚡️ Build success in 9ms
|
|
34
|
+
[32mESM[39m [1mdist/browser.mjs [22m[32m138.00 B[39m
|
|
35
|
+
[32mESM[39m ⚡️ Build success in 7ms
|
|
36
|
+
DTS Build start
|
|
37
|
+
DTS ⚡️ Build success in 843ms
|
|
38
|
+
DTS dist/index.d.ts 593.00 B
|
|
39
|
+
DTS dist/index.d.mts 593.00 B
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @cappa/plugin-storybook
|
|
2
2
|
|
|
3
|
+
## 0.0.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c538974: Replace playwright with playwright-core
|
|
8
|
+
- Updated dependencies [c538974]
|
|
9
|
+
- @cappa/core@0.0.13
|
|
10
|
+
|
|
11
|
+
## 0.0.12
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 4e529fd: New options
|
|
16
|
+
- Updated dependencies [4e529fd]
|
|
17
|
+
- @cappa/core@0.0.12
|
|
18
|
+
|
|
3
19
|
## 0.0.11
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Storybook Plugin for Cappa
|
|
2
|
+
|
|
3
|
+
This plugin allows to take screenshots of Storybook stories with Cappa.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @cappa/plugin-storybook
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Add the plugin to your cappa config:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { defineConfig } from "@cappa/core";
|
|
17
|
+
import { cappaPluginStorybook } from "@cappa/plugin-storybook";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [cappaPluginStorybook({ storybookUrl: "http://localhost:8080" })],
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
> Make sure to have a running Storybook server on the given url.
|
|
25
|
+
|
|
26
|
+
Add the plugin to your storybook config:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const config: StorybookConfig = {
|
|
30
|
+
addons: ["@cappa/plugin-storybook"],
|
|
31
|
+
};
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Run cappa cli in the directory of your cappa config:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
cappa
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Options
|
|
41
|
+
|
|
42
|
+
## Storybook options
|
|
43
|
+
|
|
44
|
+
Cappa uses a storybook addon that allows you to pass options from storybook into cappa.
|
|
45
|
+
|
|
46
|
+
### Parameters
|
|
47
|
+
|
|
48
|
+
| Option | Description | Default |
|
|
49
|
+
| ------ | ---------------------------------------------- | --------------- |
|
|
50
|
+
| skip | Whether to skip the screenshot | false |
|
|
51
|
+
| delay | The delay to wait before taking the screenshot | null (no delay) |
|
|
52
|
+
|
|
53
|
+
#### Example
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
export const Primary: Story = {
|
|
57
|
+
parameters: {
|
|
58
|
+
cappa: {
|
|
59
|
+
skip: true,
|
|
60
|
+
delay: 1000,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Play function
|
|
67
|
+
|
|
68
|
+
cappa automatically waits for the play function to finish, before taking screenshots. This allows you to define 'actions' that are executed before the screenshot is taken e.g. clicking on a button.
|
|
69
|
+
|
|
70
|
+
> `delay` is added "on top" of the play function execution.
|
|
71
|
+
|
|
72
|
+
#### Example
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
export const Primary: Story = {
|
|
76
|
+
play: async ({ canvasElement }) => {
|
|
77
|
+
const canvas = within(canvasElement);
|
|
78
|
+
await userEvent.click(canvas.getByRole("button"));
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Flakiness
|
|
84
|
+
|
|
85
|
+
To avoid flakiness, cappa disables css animations and transitions by default. For additional use cases or animation libraries, you can use the `isCappa` function to check if the current window is a cappa window. You can use it inside of your storybook preview file (`.storybook/preview.ts`):
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
if (isCappa()) {
|
|
89
|
+
import("disable-animations.css");
|
|
90
|
+
MotionGlobalConfig.disableAnimations = true;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## How it works
|
|
95
|
+
|
|
96
|
+
cappa uses a 'one way binding' to pass options from storybook into cappa. That means that the storybook addon is responsible for passing options into cappa and 'communicating' the correct timing to take the screenshot.
|
package/dist/browser.mjs
ADDED
package/dist/index.d.mts
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
import { Plugin } from
|
|
1
|
+
import { Plugin } from '@cappa/core';
|
|
2
2
|
|
|
3
|
-
//#region src/cappa/plugin.d.ts
|
|
4
3
|
interface StorybookPluginOptions {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
storybookUrl: string;
|
|
5
|
+
includeStories?: string[];
|
|
6
|
+
excludeStories?: string[];
|
|
7
|
+
defaultViewport?: {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
waitForSelector?: string;
|
|
12
|
+
waitForTimeout?: number;
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* Storybook Plugin for Cappa
|
|
17
16
|
* Fetches stories from a running Storybook server and takes screenshots of each story
|
|
18
17
|
*/
|
|
19
18
|
declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export { cappaPluginStorybook, withCappaDecorator };
|
|
25
|
-
//# sourceMappingURL=index.d.mts.map
|
|
19
|
+
|
|
20
|
+
declare const previewAnnotations: string[];
|
|
21
|
+
|
|
22
|
+
export { cappaPluginStorybook, previewAnnotations };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
import { Plugin } from
|
|
1
|
+
import { Plugin } from '@cappa/core';
|
|
2
2
|
|
|
3
|
-
//#region src/cappa/plugin.d.ts
|
|
4
3
|
interface StorybookPluginOptions {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
storybookUrl: string;
|
|
5
|
+
includeStories?: string[];
|
|
6
|
+
excludeStories?: string[];
|
|
7
|
+
defaultViewport?: {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
waitForSelector?: string;
|
|
12
|
+
waitForTimeout?: number;
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* Storybook Plugin for Cappa
|
|
17
16
|
* Fetches stories from a running Storybook server and takes screenshots of each story
|
|
18
17
|
*/
|
|
19
18
|
declare const cappaPluginStorybook: Plugin<StorybookPluginOptions>;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export { cappaPluginStorybook, withCappaDecorator };
|
|
25
|
-
//# sourceMappingURL=index.d.ts.map
|
|
19
|
+
|
|
20
|
+
declare const previewAnnotations: string[];
|
|
21
|
+
|
|
22
|
+
export { cappaPluginStorybook, previewAnnotations };
|
package/dist/index.js
CHANGED
|
@@ -1,203 +1,186 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
8
12
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
17
19
|
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
cappaPluginStorybook: () => cappaPluginStorybook,
|
|
34
|
+
previewAnnotations: () => previewAnnotations
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
37
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*/
|
|
33
|
-
const freezeUI = async (page) => {
|
|
34
|
-
await page.addStyleTag({ content: `
|
|
38
|
+
// src/cappa/util.ts
|
|
39
|
+
var freezeUI = async (page) => {
|
|
40
|
+
await page.addStyleTag({
|
|
41
|
+
content: `
|
|
35
42
|
* { transition: none !important; animation: none !important }
|
|
36
43
|
* { caret-color: transparent !important }
|
|
37
44
|
::-webkit-scrollbar { display: none }
|
|
38
|
-
`
|
|
45
|
+
`
|
|
46
|
+
});
|
|
39
47
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
await page.evaluate(async () => {
|
|
47
|
-
if (document.fonts?.ready) await document.fonts.ready;
|
|
48
|
-
await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
|
|
49
|
-
});
|
|
48
|
+
var waitForVisualIdle = async (page) => {
|
|
49
|
+
await page.waitForLoadState("networkidle");
|
|
50
|
+
await page.evaluate(async () => {
|
|
51
|
+
if (document.fonts?.ready) await document.fonts.ready;
|
|
52
|
+
await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
|
|
53
|
+
});
|
|
50
54
|
};
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
//#region src/cappa/plugin.ts
|
|
54
|
-
/**
|
|
55
|
-
* Create a latch for a Promise. A latch is a Promise that can be resolved from outside.
|
|
56
|
-
* @param T - The type of the Promise
|
|
57
|
-
* @returns A latch for a Promise
|
|
58
|
-
*/
|
|
56
|
+
// src/cappa/plugin.ts
|
|
59
57
|
function createLatch() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
resolve
|
|
64
|
-
};
|
|
58
|
+
let resolve;
|
|
59
|
+
const p = new Promise((r) => resolve = r);
|
|
60
|
+
return { p, resolve };
|
|
65
61
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
62
|
+
var cappaPluginStorybook = (options) => {
|
|
63
|
+
return {
|
|
64
|
+
name: "StorybookPlugin",
|
|
65
|
+
description: "Takes screenshots of Storybook stories with configurable options",
|
|
66
|
+
version: "1.0.0",
|
|
67
|
+
execute: async (screenshotTool) => {
|
|
68
|
+
if (!options) {
|
|
69
|
+
throw new Error("Storybook plugin options are required");
|
|
70
|
+
}
|
|
71
|
+
if (!options.storybookUrl) {
|
|
72
|
+
throw new Error("storybookUrl is required");
|
|
73
|
+
}
|
|
74
|
+
const {
|
|
75
|
+
storybookUrl,
|
|
76
|
+
includeStories = [],
|
|
77
|
+
excludeStories = [],
|
|
78
|
+
defaultViewport = { width: 1920, height: 1080 },
|
|
79
|
+
waitForSelector,
|
|
80
|
+
waitForTimeout
|
|
81
|
+
} = options;
|
|
82
|
+
const storiesUrl = `${storybookUrl}/index.json`;
|
|
83
|
+
console.log(`Fetching stories from: ${storiesUrl}`);
|
|
84
|
+
try {
|
|
85
|
+
const response = await fetch(storiesUrl);
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
throw new Error(`Failed to fetch stories: ${response.status} ${response.statusText}`);
|
|
88
|
+
}
|
|
89
|
+
const data = await response.json();
|
|
90
|
+
const stories = Object.values(data.entries);
|
|
91
|
+
let filteredStories = stories;
|
|
92
|
+
if (includeStories.length > 0) {
|
|
93
|
+
filteredStories = filteredStories.filter(
|
|
94
|
+
(story) => includeStories.some((pattern) => story.title.includes(pattern) || story.name.includes(pattern))
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
if (excludeStories.length > 0) {
|
|
98
|
+
filteredStories = filteredStories.filter(
|
|
99
|
+
(story) => !excludeStories.some((pattern) => story.title.includes(pattern) || story.name.includes(pattern))
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
filteredStories = filteredStories.filter((story) => story.type === "story");
|
|
103
|
+
console.log(`Found ${filteredStories.length} stories to screenshot`);
|
|
104
|
+
const results = [];
|
|
105
|
+
await screenshotTool.init();
|
|
106
|
+
let currentLatch = createLatch();
|
|
107
|
+
await screenshotTool.page?.exposeFunction("__cappa_parameters", async (payload) => {
|
|
108
|
+
currentLatch.resolve(payload);
|
|
109
|
+
});
|
|
110
|
+
for (const story of filteredStories) {
|
|
111
|
+
try {
|
|
112
|
+
const storyUrl = `${storybookUrl}/iframe.html?id=${story.id}&viewMode=story`;
|
|
113
|
+
const screenshotOptions = {
|
|
114
|
+
viewport: defaultViewport,
|
|
115
|
+
waitForSelector,
|
|
116
|
+
waitForTimeout,
|
|
117
|
+
fullPage: true,
|
|
118
|
+
quality: 90,
|
|
119
|
+
type: "jpeg"
|
|
120
|
+
};
|
|
121
|
+
const filename = `${story.title.replace(
|
|
122
|
+
/[^a-zA-Z0-9]/g,
|
|
123
|
+
"_"
|
|
124
|
+
)}_${story.name.replace(/[^a-zA-Z0-9]/g, "_")}.${screenshotOptions.type}`;
|
|
125
|
+
const page = screenshotTool.page;
|
|
126
|
+
if (!page) {
|
|
127
|
+
throw new Error("Page not initialized");
|
|
128
|
+
}
|
|
129
|
+
page.on("console", (message) => {
|
|
130
|
+
console.log("console", message.text());
|
|
131
|
+
});
|
|
132
|
+
page.on("pageerror", (error) => {
|
|
133
|
+
console.log("pageerror", error);
|
|
134
|
+
});
|
|
135
|
+
await page.goto(storyUrl);
|
|
136
|
+
const options2 = await currentLatch.p;
|
|
137
|
+
currentLatch = createLatch();
|
|
138
|
+
if (options2.skip) {
|
|
139
|
+
console.log(`Skipping story ${story.title} - ${story.name}`);
|
|
140
|
+
}
|
|
141
|
+
await freezeUI(page);
|
|
142
|
+
await waitForVisualIdle(page);
|
|
143
|
+
if (options2.delay) {
|
|
144
|
+
await page.waitForTimeout(options2.delay);
|
|
145
|
+
}
|
|
146
|
+
const actualFilepath = await screenshotTool.takeScreenshot(page, filename, {
|
|
147
|
+
fullPage: options2.fullPage ?? screenshotOptions.fullPage,
|
|
148
|
+
type: options2.type ?? screenshotOptions.type,
|
|
149
|
+
waitForSelector: options2.waitForSelector ?? screenshotOptions.waitForSelector,
|
|
150
|
+
waitForTimeout: options2.waitForTimeout ?? screenshotOptions.waitForTimeout
|
|
151
|
+
});
|
|
152
|
+
results.push({
|
|
153
|
+
storyId: story.id,
|
|
154
|
+
storyName: story.name,
|
|
155
|
+
storyTitle: story.title,
|
|
156
|
+
success: true,
|
|
157
|
+
filepath: actualFilepath
|
|
158
|
+
});
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error(`Error taking screenshot of story ${story.title} - ${story.name}:`, error.message);
|
|
161
|
+
results.push({
|
|
162
|
+
storyId: story.id,
|
|
163
|
+
storyName: story.name,
|
|
164
|
+
storyTitle: story.title,
|
|
165
|
+
success: false,
|
|
166
|
+
error: error.message
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
console.log(`Completed screenshots: ${results.filter((r) => r.success).length}/${results.length} successful`);
|
|
171
|
+
return results;
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.error("Error in Storybook plugin:", error.message);
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
156
178
|
};
|
|
157
179
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
* @returns The function or rejects if the function is not exposed within the timeout
|
|
165
|
-
*/
|
|
166
|
-
const waitForExposed = (name, timeoutMs = 5e3) => {
|
|
167
|
-
return new Promise((resolve, reject) => {
|
|
168
|
-
const start = performance.now();
|
|
169
|
-
const t = setInterval(() => {
|
|
170
|
-
const fn = window[name];
|
|
171
|
-
if (typeof fn === "function") {
|
|
172
|
-
clearInterval(t);
|
|
173
|
-
resolve(fn);
|
|
174
|
-
} else if (performance.now() - start > timeoutMs) {
|
|
175
|
-
clearInterval(t);
|
|
176
|
-
reject(/* @__PURE__ */ new Error(`Timed out waiting for ${name}`));
|
|
177
|
-
}
|
|
178
|
-
}, 16);
|
|
179
|
-
});
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
//#endregion
|
|
183
|
-
//#region src/storybook/decorator.ts
|
|
184
|
-
const withCappaDecorator = (0, storybook_preview_api.makeDecorator)({
|
|
185
|
-
name: "withCappa",
|
|
186
|
-
parameterName: "cappa",
|
|
187
|
-
skipIfNoParametersOrOptions: false,
|
|
188
|
-
wrapper: (getStory, context, { parameters }) => {
|
|
189
|
-
queueMicrotask(async () => {
|
|
190
|
-
try {
|
|
191
|
-
(await waitForExposed("__cappa_parameters"))(parameters ?? {});
|
|
192
|
-
} catch (error) {
|
|
193
|
-
console.error(error);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
return getStory(context);
|
|
197
|
-
}
|
|
180
|
+
// src/index.ts
|
|
181
|
+
var previewAnnotations = [require.resolve("./preview.mjs")];
|
|
182
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
183
|
+
0 && (module.exports = {
|
|
184
|
+
cappaPluginStorybook,
|
|
185
|
+
previewAnnotations
|
|
198
186
|
});
|
|
199
|
-
|
|
200
|
-
//#endregion
|
|
201
|
-
exports.cappaPluginStorybook = cappaPluginStorybook;
|
|
202
|
-
exports.withCappaDecorator = withCappaDecorator;
|
|
203
|
-
//# sourceMappingURL=index.js.map
|