@argos-ci/storybook 4.0.4 → 4.0.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/dist/test-runner.js +14 -19
- package/dist/vitest-plugin.d.ts +26 -18
- package/dist/vitest-plugin.js +6 -15
- package/dist/vitest.d.ts +5 -17
- package/package.json +2 -2
package/dist/test-runner.js
CHANGED
|
@@ -107,6 +107,8 @@ async function storybookArgosScreenshot(handler, context, options) {
|
|
|
107
107
|
}
|
|
108
108
|
});
|
|
109
109
|
allAttachments.push(...attachments);
|
|
110
|
+
await context.setViewportSize("default");
|
|
111
|
+
await setStorybookGlobals({ handler, globals: {} });
|
|
110
112
|
}
|
|
111
113
|
} else {
|
|
112
114
|
const attachments = await runHooksAndScreenshot({
|
|
@@ -118,14 +120,7 @@ async function storybookArgosScreenshot(handler, context, options) {
|
|
|
118
120
|
});
|
|
119
121
|
allAttachments.push(...attachments);
|
|
120
122
|
}
|
|
121
|
-
await context.
|
|
122
|
-
if (context.applyGlobals) {
|
|
123
|
-
await context.applyGlobals({
|
|
124
|
-
handler,
|
|
125
|
-
globals: {}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
await setStorybookGlobals({ handler, globals: {} });
|
|
123
|
+
await context.afterScreenshot?.({ handler, globals: {} });
|
|
129
124
|
return allAttachments;
|
|
130
125
|
}
|
|
131
126
|
async function setStorybookGlobals(args) {
|
|
@@ -153,12 +148,6 @@ async function setStorybookGlobals(args) {
|
|
|
153
148
|
}
|
|
154
149
|
async function runHooksAndScreenshot(args) {
|
|
155
150
|
const { handler, context, options, globals, metadata } = args;
|
|
156
|
-
if (context.applyGlobals) {
|
|
157
|
-
await context.applyGlobals({
|
|
158
|
-
handler,
|
|
159
|
-
globals
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
151
|
await setStorybookGlobals({ handler, globals });
|
|
163
152
|
const viewportFromGlobals = globals.viewport ? getViewport(context.story.parameters, globals.viewport) : null;
|
|
164
153
|
const viewport = viewportFromGlobals ?? getDefaultViewport(context.story.parameters) ?? "default";
|
|
@@ -167,6 +156,7 @@ async function runHooksAndScreenshot(args) {
|
|
|
167
156
|
...metadata,
|
|
168
157
|
viewport: viewport && viewport !== "default" ? viewport : void 0
|
|
169
158
|
});
|
|
159
|
+
await context.beforeScreenshot?.({ handler, globals });
|
|
170
160
|
return argosPlaywrightScreenshot(
|
|
171
161
|
handler,
|
|
172
162
|
context.name + (args.suffix ?? ""),
|
|
@@ -175,6 +165,7 @@ async function runHooksAndScreenshot(args) {
|
|
|
175
165
|
}
|
|
176
166
|
|
|
177
167
|
// src/test-runner.ts
|
|
168
|
+
var DEFAULT_PLAYWRIGHT_VIEWPORT_SIZE = { width: 1280, height: 720 };
|
|
178
169
|
async function argosScreenshot(page, context, options) {
|
|
179
170
|
const storyContext = await getStoryContext(page, context);
|
|
180
171
|
const fitToContent = getFitToContentFromParameters(storyContext.parameters);
|
|
@@ -183,7 +174,7 @@ async function argosScreenshot(page, context, options) {
|
|
|
183
174
|
{
|
|
184
175
|
name: storyContext.id,
|
|
185
176
|
playwrightLibraries: ["@storybook/test-runner"],
|
|
186
|
-
|
|
177
|
+
beforeScreenshot: async ({ handler }) => {
|
|
187
178
|
await waitForPageReady(handler);
|
|
188
179
|
},
|
|
189
180
|
story: {
|
|
@@ -193,10 +184,14 @@ async function argosScreenshot(page, context, options) {
|
|
|
193
184
|
globals: null
|
|
194
185
|
},
|
|
195
186
|
setViewportSize: async (size) => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
await page.setViewportSize(
|
|
187
|
+
const actualSize = await page.viewportSize();
|
|
188
|
+
const absoluteSize = size === "default" ? DEFAULT_PLAYWRIGHT_VIEWPORT_SIZE : size;
|
|
189
|
+
if (!actualSize || actualSize.height !== absoluteSize.height || actualSize.width !== absoluteSize.width) {
|
|
190
|
+
await page.setViewportSize(absoluteSize);
|
|
191
|
+
await page.waitForFunction(
|
|
192
|
+
({ width, height }) => window.innerWidth === width && window.innerHeight === height,
|
|
193
|
+
{ width: absoluteSize.width, height: absoluteSize.height }
|
|
194
|
+
);
|
|
200
195
|
}
|
|
201
196
|
}
|
|
202
197
|
},
|
package/dist/vitest-plugin.d.ts
CHANGED
|
@@ -11,23 +11,11 @@ type StorybookScreenshotContext<Handler extends Page | Frame> = {
|
|
|
11
11
|
playwrightLibraries: string[];
|
|
12
12
|
test?: MetadataConfig["test"];
|
|
13
13
|
setViewportSize: (size: ViewportSize | "default") => Promise<void>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* applyGlobals: async ({ frame, globals }) => {
|
|
20
|
-
* await frame.evaluate((globals) => {
|
|
21
|
-
* if (globals.theme === "dark") {
|
|
22
|
-
* document.documentElement.classList.add("dark");
|
|
23
|
-
* } else {
|
|
24
|
-
* document.documentElement.classList.remove("dark");
|
|
25
|
-
* }
|
|
26
|
-
* }, globals);
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
applyGlobals?: (input: {
|
|
14
|
+
beforeScreenshot?: (input: {
|
|
15
|
+
handler: Handler;
|
|
16
|
+
globals: StorybookGlobals;
|
|
17
|
+
}) => Promise<void>;
|
|
18
|
+
afterScreenshot?: (input: {
|
|
31
19
|
handler: Handler;
|
|
32
20
|
globals: StorybookGlobals;
|
|
33
21
|
}) => Promise<void>;
|
|
@@ -44,12 +32,32 @@ type ArgosReporterConfig = UploadParameters;
|
|
|
44
32
|
type ArgosScreenshotCommandArgs = [
|
|
45
33
|
Pick<StorybookScreenshotContext<Frame>, "name" | "story" | "test">
|
|
46
34
|
];
|
|
47
|
-
interface ArgosVitestPluginOptions extends
|
|
35
|
+
interface ArgosVitestPluginOptions extends ArgosReporterConfig, ArgosScreenshotOptions {
|
|
48
36
|
/**
|
|
49
37
|
* Upload the report to Argos.
|
|
50
38
|
* @default true
|
|
51
39
|
*/
|
|
52
40
|
uploadToArgos?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Opportunity to apply globals or other context-specific settings.
|
|
43
|
+
* This can be useful to emulate dark mode or other visual modes.
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* applyGlobals: async ({ frame, globals }) => {
|
|
47
|
+
* await frame.evaluate((globals) => {
|
|
48
|
+
* if (globals.theme === "dark") {
|
|
49
|
+
* document.documentElement.classList.add("dark");
|
|
50
|
+
* } else {
|
|
51
|
+
* document.documentElement.classList.remove("dark");
|
|
52
|
+
* }
|
|
53
|
+
* }, globals);
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
applyGlobals?: (input: {
|
|
58
|
+
handler: Frame;
|
|
59
|
+
globals: StorybookGlobals;
|
|
60
|
+
}) => Promise<void>;
|
|
53
61
|
}
|
|
54
62
|
/**
|
|
55
63
|
* Create a command for taking Argos screenshots in Vitest.
|
package/dist/vitest-plugin.js
CHANGED
|
@@ -104,6 +104,8 @@ async function storybookArgosScreenshot(handler, context, options) {
|
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
allAttachments.push(...attachments);
|
|
107
|
+
await context.setViewportSize("default");
|
|
108
|
+
await setStorybookGlobals({ handler, globals: {} });
|
|
107
109
|
}
|
|
108
110
|
} else {
|
|
109
111
|
const attachments = await runHooksAndScreenshot({
|
|
@@ -115,14 +117,7 @@ async function storybookArgosScreenshot(handler, context, options) {
|
|
|
115
117
|
});
|
|
116
118
|
allAttachments.push(...attachments);
|
|
117
119
|
}
|
|
118
|
-
await context.
|
|
119
|
-
if (context.applyGlobals) {
|
|
120
|
-
await context.applyGlobals({
|
|
121
|
-
handler,
|
|
122
|
-
globals: {}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
await setStorybookGlobals({ handler, globals: {} });
|
|
120
|
+
await context.afterScreenshot?.({ handler, globals: {} });
|
|
126
121
|
return allAttachments;
|
|
127
122
|
}
|
|
128
123
|
async function setStorybookGlobals(args) {
|
|
@@ -150,12 +145,6 @@ async function setStorybookGlobals(args) {
|
|
|
150
145
|
}
|
|
151
146
|
async function runHooksAndScreenshot(args) {
|
|
152
147
|
const { handler, context, options, globals, metadata } = args;
|
|
153
|
-
if (context.applyGlobals) {
|
|
154
|
-
await context.applyGlobals({
|
|
155
|
-
handler,
|
|
156
|
-
globals
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
148
|
await setStorybookGlobals({ handler, globals });
|
|
160
149
|
const viewportFromGlobals = globals.viewport ? getViewport(context.story.parameters, globals.viewport) : null;
|
|
161
150
|
const viewport = viewportFromGlobals ?? getDefaultViewport(context.story.parameters) ?? "default";
|
|
@@ -164,6 +153,7 @@ async function runHooksAndScreenshot(args) {
|
|
|
164
153
|
...metadata,
|
|
165
154
|
viewport: viewport && viewport !== "default" ? viewport : void 0
|
|
166
155
|
});
|
|
156
|
+
await context.beforeScreenshot?.({ handler, globals });
|
|
167
157
|
return argosPlaywrightScreenshot(
|
|
168
158
|
handler,
|
|
169
159
|
context.name + (args.suffix ?? ""),
|
|
@@ -227,7 +217,8 @@ var createArgosScreenshotCommand = (pluginOptions) => {
|
|
|
227
217
|
}
|
|
228
218
|
}, size);
|
|
229
219
|
},
|
|
230
|
-
applyGlobals
|
|
220
|
+
beforeScreenshot: applyGlobals,
|
|
221
|
+
afterScreenshot: applyGlobals
|
|
231
222
|
},
|
|
232
223
|
applyFitToContent(screenshotOptions, fitToContent)
|
|
233
224
|
);
|
package/dist/vitest.d.ts
CHANGED
|
@@ -8,23 +8,11 @@ type StorybookScreenshotContext<Handler extends Page | Frame> = {
|
|
|
8
8
|
playwrightLibraries: string[];
|
|
9
9
|
test?: MetadataConfig["test"];
|
|
10
10
|
setViewportSize: (size: ViewportSize | "default") => Promise<void>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* applyGlobals: async ({ frame, globals }) => {
|
|
17
|
-
* await frame.evaluate((globals) => {
|
|
18
|
-
* if (globals.theme === "dark") {
|
|
19
|
-
* document.documentElement.classList.add("dark");
|
|
20
|
-
* } else {
|
|
21
|
-
* document.documentElement.classList.remove("dark");
|
|
22
|
-
* }
|
|
23
|
-
* }, globals);
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
applyGlobals?: (input: {
|
|
11
|
+
beforeScreenshot?: (input: {
|
|
12
|
+
handler: Handler;
|
|
13
|
+
globals: StorybookGlobals;
|
|
14
|
+
}) => Promise<void>;
|
|
15
|
+
afterScreenshot?: (input: {
|
|
28
16
|
handler: Handler;
|
|
29
17
|
globals: StorybookGlobals;
|
|
30
18
|
}) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/storybook",
|
|
3
3
|
"description": "Visual testing for Storybook test runner.",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.6",
|
|
5
5
|
"author": "Smooth Code",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"check-format": "prettier --check --ignore-unknown --ignore-path=./.gitignore --ignore-path=../../.gitignore --ignore-path=../../.prettierignore .",
|
|
98
98
|
"lint": "eslint ."
|
|
99
99
|
},
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "c6358550bc0c149d65ea2aaa27e05bd06166cb63"
|
|
101
101
|
}
|