@argos-ci/storybook 4.0.5 → 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.
@@ -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.setViewportSize("default");
122
- await setStorybookGlobals({ handler, globals: {} });
123
- if (context.afterScreenshot) {
124
- await context.afterScreenshot({
125
- handler,
126
- globals: {}
127
- });
128
- }
123
+ await context.afterScreenshot?.({ handler, globals: {} });
129
124
  return allAttachments;
130
125
  }
131
126
  async function setStorybookGlobals(args) {
@@ -154,12 +149,6 @@ async function setStorybookGlobals(args) {
154
149
  async function runHooksAndScreenshot(args) {
155
150
  const { handler, context, options, globals, metadata } = args;
156
151
  await setStorybookGlobals({ handler, globals });
157
- if (context.beforeScreenshot) {
158
- await context.beforeScreenshot({
159
- handler,
160
- globals
161
- });
162
- }
163
152
  const viewportFromGlobals = globals.viewport ? getViewport(context.story.parameters, globals.viewport) : null;
164
153
  const viewport = viewportFromGlobals ?? getDefaultViewport(context.story.parameters) ?? "default";
165
154
  await context.setViewportSize(viewport);
@@ -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);
@@ -193,10 +184,14 @@ async function argosScreenshot(page, context, options) {
193
184
  globals: null
194
185
  },
195
186
  setViewportSize: async (size) => {
196
- if (size === "default") {
197
- await page.setViewportSize({ width: 1280, height: 720 });
198
- } else {
199
- await page.setViewportSize(size);
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
  },
@@ -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.setViewportSize("default");
119
- await setStorybookGlobals({ handler, globals: {} });
120
- if (context.afterScreenshot) {
121
- await context.afterScreenshot({
122
- handler,
123
- globals: {}
124
- });
125
- }
120
+ await context.afterScreenshot?.({ handler, globals: {} });
126
121
  return allAttachments;
127
122
  }
128
123
  async function setStorybookGlobals(args) {
@@ -151,12 +146,6 @@ async function setStorybookGlobals(args) {
151
146
  async function runHooksAndScreenshot(args) {
152
147
  const { handler, context, options, globals, metadata } = args;
153
148
  await setStorybookGlobals({ handler, globals });
154
- if (context.beforeScreenshot) {
155
- await context.beforeScreenshot({
156
- handler,
157
- globals
158
- });
159
- }
160
149
  const viewportFromGlobals = globals.viewport ? getViewport(context.story.parameters, globals.viewport) : null;
161
150
  const viewport = viewportFromGlobals ?? getDefaultViewport(context.story.parameters) ?? "default";
162
151
  await context.setViewportSize(viewport);
@@ -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 ?? ""),
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.5",
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": "cc53d0519b6e07fd339bd3e200626ec7833fc495"
100
+ "gitHead": "c6358550bc0c149d65ea2aaa27e05bd06166cb63"
101
101
  }