@applitools/eyes-storybook 3.53.6 → 3.53.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.53.7](https://github.com/Applitools-Dev/sdk/compare/js/eyes-storybook@3.53.6...js/eyes-storybook@3.53.7) (2025-02-10)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * remove deprecated postinstall script ([#2729](https://github.com/Applitools-Dev/sdk/issues/2729)) ([28075c1](https://github.com/Applitools-Dev/sdk/commit/28075c10342c1e169040ac8b720f5c273bc9bf31))
9
+ * respect readStoriesTimeout ([#2776](https://github.com/Applitools-Dev/sdk/issues/2776)) ([8c841f4](https://github.com/Applitools-Dev/sdk/commit/8c841f492641759f056af889dbac68e711782b26))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * @applitools/ufg-client bumped to 1.16.4
15
+ #### Bug Fixes
16
+
17
+ * environment without type in ios should be considered web ([#2779](https://github.com/Applitools-Dev/sdk/issues/2779)) ([1a0dc18](https://github.com/Applitools-Dev/sdk/commit/1a0dc186d782ee8dacccf4ea9d10b513416b7492))
18
+ * specifying chrome version in UFG chrome emulations ([#2773](https://github.com/Applitools-Dev/sdk/issues/2773)) ([e86af5d](https://github.com/Applitools-Dev/sdk/commit/e86af5d8d616fb54a6cbe0a23db691d0b190b0f6))
19
+ * @applitools/core bumped to 4.31.2
20
+ #### Bug Fixes
21
+
22
+ * environment without type in ios should be considered web ([#2779](https://github.com/Applitools-Dev/sdk/issues/2779)) ([1a0dc18](https://github.com/Applitools-Dev/sdk/commit/1a0dc186d782ee8dacccf4ea9d10b513416b7492))
23
+ * move log line for closing batch in offline cli ([#2768](https://github.com/Applitools-Dev/sdk/issues/2768)) ([bfb51a9](https://github.com/Applitools-Dev/sdk/commit/bfb51a94d8e7d51020aac62dd78038fdeb819a68))
24
+
25
+
26
+
27
+ * @applitools/eyes bumped to 1.32.1
28
+
29
+
3
30
  ## [3.53.6](https://github.com/Applitools-Dev/sdk/compare/js/eyes-storybook@3.53.5...js/eyes-storybook@3.53.6) (2025-01-30)
4
31
 
5
32
 
@@ -190,7 +190,7 @@ function __getClientAPI(...args) {
190
190
  throw new Error('Cannot get client API: no frameWindow');
191
191
  }
192
192
 
193
- async function getClientAPIWithRetries({timeout = 10000} = {}) {
193
+ async function getClientAPIWithRetries({timeout = 5000} = {}) {
194
194
  let error = 'Unknown error';
195
195
  const RETRY_INTERVAL = 100;
196
196
  const totalAttempts = timeout / RETRY_INTERVAL;
@@ -190,7 +190,7 @@ function __getStories(...args) {
190
190
  throw new Error('Cannot get client API: no frameWindow');
191
191
  }
192
192
 
193
- async function getClientAPIWithRetries({timeout = 10000} = {}) {
193
+ async function getClientAPIWithRetries({timeout = 5000} = {}) {
194
194
  let error = 'Unknown error';
195
195
  const RETRY_INTERVAL = 100;
196
196
  const totalAttempts = timeout / RETRY_INTERVAL;
@@ -210,9 +210,7 @@ function __getStories(...args) {
210
210
 
211
211
  var getClientAPI_1 = getClientAPIWithRetries;
212
212
 
213
- const DEFAULT_TIMEOUT = 60000;
214
-
215
- async function getStories({timeout = DEFAULT_TIMEOUT} = {timeout: DEFAULT_TIMEOUT}) {
213
+ async function getStories() {
216
214
  const Stories = {
217
215
  _getStoriesV2: () => {
218
216
  let categories = getCategoriesV2();
@@ -297,7 +295,7 @@ function __getStories(...args) {
297
295
  },
298
296
  };
299
297
 
300
- const clientApi = await waitForClientAPI();
298
+ const clientApi = await getClientAPI_1().catch(() => null);
301
299
 
302
300
  if (clientApi) {
303
301
  console.log(`getting stories from storybook via API. ${clientApi.version}`);
@@ -376,36 +374,6 @@ function __getStories(...args) {
376
374
  s => s.innerText === 'loading story',
377
375
  );
378
376
  }
379
-
380
- function waitForClientAPI() {
381
- return ptimeoutWithValue(_waitForClientAPI, timeout, undefined);
382
-
383
- async function _waitForClientAPI() {
384
- try {
385
- return getClientAPI_1({timeout});
386
- } catch (ex) {
387
- await delay(100);
388
- return _waitForClientAPI();
389
- }
390
- }
391
- }
392
-
393
- async function delay(time) {
394
- return new Promise(res => {
395
- setTimeout(res, time);
396
- });
397
- }
398
-
399
- async function ptimeoutWithValue(getPromise, delay, value) {
400
- let _res, _rej;
401
- const result = new Promise((res, rej) => ((_res = res), (_rej = rej)));
402
- const cancel = setTimeout(() => _res(value), delay);
403
- getPromise()
404
- .then(v => _res(v))
405
- .catch(e => _rej(e))
406
- .finally(() => clearTimeout(cancel));
407
- return result;
408
- }
409
377
  }
410
378
 
411
379
  var getStories_1 = getStories;
@@ -190,7 +190,7 @@ function __renderStoryWithClientAPI(...args) {
190
190
  throw new Error('Cannot get client API: no frameWindow');
191
191
  }
192
192
 
193
- async function getClientAPIWithRetries({timeout = 10000} = {}) {
193
+ async function getClientAPIWithRetries({timeout = 5000} = {}) {
194
194
  let error = 'Unknown error';
195
195
  const RETRY_INTERVAL = 100;
196
196
  const totalAttempts = timeout / RETRY_INTERVAL;
@@ -190,7 +190,7 @@ function __runRunAfterScript(...args) {
190
190
  throw new Error('Cannot get client API: no frameWindow');
191
191
  }
192
192
 
193
- async function getClientAPIWithRetries({timeout = 10000} = {}) {
193
+ async function getClientAPIWithRetries({timeout = 5000} = {}) {
194
194
  let error = 'Unknown error';
195
195
  const RETRY_INTERVAL = 100;
196
196
  const totalAttempts = timeout / RETRY_INTERVAL;
@@ -190,7 +190,7 @@ function __runRunBeforeScript(...args) {
190
190
  throw new Error('Cannot get client API: no frameWindow');
191
191
  }
192
192
 
193
- async function getClientAPIWithRetries({timeout = 10000} = {}) {
193
+ async function getClientAPIWithRetries({timeout = 5000} = {}) {
194
194
  let error = 'Unknown error';
195
195
  const RETRY_INTERVAL = 100;
196
196
  const totalAttempts = timeout / RETRY_INTERVAL;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/eyes-storybook",
3
- "version": "3.53.6",
3
+ "version": "3.53.7",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "applitools",
@@ -50,18 +50,17 @@
50
50
  "changelog": "git changelog -x -p -f v$npm_package_version > History.md && git add ./History.md && git commit -am 'changelog'",
51
51
  "changelog:init": "git config changelog.format \"* %s [[%h]($(echo $npm_package_repository_url|cut -d+ -f2|cut -d. -f1-2)/commit/%H)]\"",
52
52
  "changelog:install": "sudo apt-get install git-extras",
53
- "postinstall": "node src/postinstall",
54
53
  "up:framework": "cd test/fixtures/storybook-versions/${APPLITOOLS_FRAMEWORK_VERSION} && npm ci"
55
54
  },
56
55
  "dependencies": {
57
- "@applitools/core": "4.31.0",
56
+ "@applitools/core": "4.31.2",
58
57
  "@applitools/driver": "1.20.4",
59
- "@applitools/eyes": "1.32.0",
58
+ "@applitools/eyes": "1.32.1",
60
59
  "@applitools/functional-commons": "1.6.0",
61
60
  "@applitools/logger": "2.1.0",
62
61
  "@applitools/monitoring-commons": "1.0.19",
63
62
  "@applitools/spec-driver-puppeteer": "1.4.24",
64
- "@applitools/ufg-client": "1.16.3",
63
+ "@applitools/ufg-client": "1.16.4",
65
64
  "@applitools/utils": "1.7.7",
66
65
  "boxen": "4.2.0",
67
66
  "chalk": "3.0.0",
@@ -187,7 +187,7 @@ function getFrameWindow() {
187
187
  throw new Error('Cannot get client API: no frameWindow');
188
188
  }
189
189
 
190
- async function getClientAPIWithRetries({timeout = 10000} = {}) {
190
+ async function getClientAPIWithRetries({timeout = 5000} = {}) {
191
191
  let error = 'Unknown error';
192
192
  const RETRY_INTERVAL = 100;
193
193
  const totalAttempts = timeout / RETRY_INTERVAL;
@@ -1,8 +1,6 @@
1
1
  const getClientAPI = require('./getClientAPI');
2
2
 
3
- const DEFAULT_TIMEOUT = 60000;
4
-
5
- async function getStories({timeout = DEFAULT_TIMEOUT} = {timeout: DEFAULT_TIMEOUT}) {
3
+ async function getStories() {
6
4
  const Stories = {
7
5
  _getStoriesV2: () => {
8
6
  let categories = getCategoriesV2();
@@ -87,7 +85,7 @@ async function getStories({timeout = DEFAULT_TIMEOUT} = {timeout: DEFAULT_TIMEOU
87
85
  },
88
86
  };
89
87
 
90
- const clientApi = await waitForClientAPI();
88
+ const clientApi = await getClientAPI().catch(() => null);
91
89
 
92
90
  if (clientApi) {
93
91
  console.log(`getting stories from storybook via API. ${clientApi.version}`);
@@ -166,36 +164,6 @@ async function getStories({timeout = DEFAULT_TIMEOUT} = {timeout: DEFAULT_TIMEOU
166
164
  s => s.innerText === 'loading story',
167
165
  );
168
166
  }
169
-
170
- function waitForClientAPI() {
171
- return ptimeoutWithValue(_waitForClientAPI, timeout, undefined);
172
-
173
- async function _waitForClientAPI() {
174
- try {
175
- return getClientAPI({timeout});
176
- } catch (ex) {
177
- await delay(100);
178
- return _waitForClientAPI();
179
- }
180
- }
181
- }
182
-
183
- async function delay(time) {
184
- return new Promise(res => {
185
- setTimeout(res, time);
186
- });
187
- }
188
-
189
- async function ptimeoutWithValue(getPromise, delay, value) {
190
- let _res, _rej;
191
- const result = new Promise((res, rej) => ((_res = res), (_rej = rej)));
192
- const cancel = setTimeout(() => _res(value), delay);
193
- getPromise()
194
- .then(v => _res(v))
195
- .catch(e => _rej(e))
196
- .finally(() => clearTimeout(cancel));
197
- return result;
198
- }
199
167
  }
200
168
 
201
169
  module.exports = getStories;
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
  const puppeteer = require('puppeteer');
3
3
  const getStories = require('../dist/getStories');
4
- const {presult, delay} = require('@applitools/functional-commons');
4
+ const {presult} = require('@applitools/functional-commons');
5
+ const {executeWithRetry} = require('./utils/executeWithRetry');
5
6
  const chalk = require('chalk');
6
7
  const makeInitPage = require('./initPage');
7
8
  const makeRenderStory = require('./renderStory');
@@ -23,9 +24,6 @@ const {extractEnvironment} = require('./extractEnvironment');
23
24
  const {makeCore} = require('@applitools/core');
24
25
  const makeGetStoriesWithConfig = require('./getStoriesWithConfig');
25
26
 
26
- const MAX_RETRIES = 30;
27
- const RETRY_INTERVAL = 1000;
28
-
29
27
  async function eyesStorybook({
30
28
  config,
31
29
  logger,
@@ -166,7 +164,7 @@ async function eyesStorybook({
166
164
  const renderStories = makeRenderStories({
167
165
  getStoryData,
168
166
  renderStory,
169
- getClientAPI,
167
+ sanityCheckForPage,
170
168
  storybookUrl,
171
169
  logger,
172
170
  stream: outputStream,
@@ -234,7 +232,7 @@ async function eyesStorybook({
234
232
  throw new Error();
235
233
  }
236
234
 
237
- const [getStoriesErr, stories] = await readStoriesWithRetry(MAX_RETRIES);
235
+ const [getStoriesErr, stories] = await presult(readStoriesWithRetry());
238
236
 
239
237
  if (getStoriesErr) {
240
238
  logger.log('Error when reading stories:', getStoriesErr);
@@ -283,21 +281,46 @@ async function eyesStorybook({
283
281
  return transitioning;
284
282
  }
285
283
 
286
- async function readStoriesWithRetry(remainingRetries) {
287
- const [getStoriesErr, stories] = await presult(
288
- page.evaluate(getStories, {timeout: readStoriesTimeout}),
284
+ async function readStoriesWithRetry() {
285
+ return executeWithRetry(
286
+ _readStoriesWithRetry,
287
+ {
288
+ timeout: readStoriesTimeout,
289
+ delayBetweenRetries: 1000,
290
+ initialErrMessage: `Could not get stories since readStoriesTimeout is too short (${readStoriesTimeout}ms)`,
291
+ },
292
+ readStoriesTimeout,
289
293
  );
290
- if (stories?.length > 0 || remainingRetries == 0) {
291
- return [getStoriesErr, stories];
292
- } else {
293
- remainingRetries--;
294
- if (getStoriesErr) {
295
- logger.log('Error in getStories:', getStoriesErr, `, ${remainingRetries} retries are left`);
296
- } else {
297
- logger.log(`Got 0 stories, ${remainingRetries} retries are left`);
294
+
295
+ async function _readStoriesWithRetry() {
296
+ try {
297
+ const stories = await page.evaluate(getStories);
298
+ if (stories.length > 0) {
299
+ return stories;
300
+ } else {
301
+ throw new Error('Got 0 stories');
302
+ }
303
+ } catch (err) {
304
+ logger.log('Error in _readStoriesWithRetry:', err, ', retrying...');
305
+ throw err;
306
+ }
307
+ }
308
+ }
309
+
310
+ async function sanityCheckForPage(page) {
311
+ return executeWithRetry(_sanityCheckForPage, {
312
+ timeout: readStoriesTimeout,
313
+ delayBetweenRetries: 1000,
314
+ initialErrMessage: `Could not get client API in sanity check since readStoriesTimeout is too short (${readStoriesTimeout}ms)`,
315
+ });
316
+
317
+ async function _sanityCheckForPage() {
318
+ try {
319
+ await page.evaluate(getClientAPI);
320
+ } catch (err) {
321
+ logger.log('Error in getClientAPI during sanity check:', err, ', retrying...');
322
+ throw err;
298
323
  }
299
- await delay(RETRY_INTERVAL);
300
- return await readStoriesWithRetry(remainingRetries);
301
324
  }
302
325
  }
303
326
  }
package/src/pagePool.js CHANGED
@@ -86,6 +86,7 @@ function createPagePool({initPage, logger}) {
86
86
  };
87
87
 
88
88
  function markPageAsFree() {
89
+ logger.log('[page pool] marking page as free', pageId);
89
90
  resolveWork();
90
91
  }
91
92
 
@@ -2,10 +2,7 @@
2
2
  const getStoryUrl = require('./getStoryUrl');
3
3
  const getStoryBaselineName = require('./getStoryBaselineName');
4
4
  const ora = require('ora');
5
- const {presult, delay} = require('@applitools/functional-commons');
6
-
7
- const MAX_RETRIES = 30;
8
- const RETRY_INTERVAL = 1000;
5
+ const {presult} = require('@applitools/functional-commons');
9
6
 
10
7
  function makeRenderStories({
11
8
  getStoryData,
@@ -14,7 +11,7 @@ function makeRenderStories({
14
11
  storybookUrl,
15
12
  logger,
16
13
  stream,
17
- getClientAPI,
14
+ sanityCheckForPage,
18
15
  maxPageTTL = 60000,
19
16
  }) {
20
17
  let newPageIdToAdd;
@@ -154,33 +151,19 @@ function makeRenderStories({
154
151
 
155
152
  const {pageId, page} = pageObj;
156
153
  logger.log(`[prepareNewPage] new page is ready: ${pageId}`);
157
- const [errorInSanity] = await getClientAPIWithRetry(page, MAX_RETRIES);
158
- if (errorInSanity) {
154
+ try {
155
+ await sanityCheckForPage(page);
156
+ logger.log(`[prepareNewPage] setting new page for replacement: ${pageId}`);
157
+ newPageIdToAdd = pageId;
158
+ } catch (errorInSanity) {
159
159
  logger.log(
160
- `[prepareNewPage] new page ${pageId} is corrupted. preparing new page. ${errorInSanity}`,
160
+ `[prepareNewPage] new page ${pageId} is corrupted. preparing new page.`,
161
+ errorInSanity,
161
162
  );
162
163
  prepareNewPage();
163
- return;
164
164
  }
165
-
166
- logger.log(`[prepareNewPage] setting new page for replacement: ${pageId}`);
167
-
168
- newPageIdToAdd = pageId;
169
165
  }
170
166
  };
171
-
172
- async function getClientAPIWithRetry(page, remainingRetries) {
173
- const [err] = await presult(page.evaluate(getClientAPI, {timeout: 10000}));
174
- if (!err || remainingRetries == 0) {
175
- return [err];
176
- } else if (err) {
177
- logger.log(
178
- `Error in getClientAPI: ${err.message} retrying... ${remainingRetries - 1} are left`,
179
- );
180
- await delay(RETRY_INTERVAL);
181
- return await getClientAPIWithRetry(page, remainingRetries - 1);
182
- }
183
- }
184
167
  }
185
168
 
186
169
  module.exports = makeRenderStories;
@@ -0,0 +1,22 @@
1
+ const {delay, ptimeoutWithFunction} = require('@applitools/functional-commons');
2
+
3
+ async function executeWithRetry(fn, {timeout, initialErrMessage, delayBetweenRetries}) {
4
+ let err = new Error(initialErrMessage);
5
+
6
+ return ptimeoutWithFunction(_executeWithRetry, timeout, () => Promise.reject(err));
7
+
8
+ async function _executeWithRetry(hasAborted) {
9
+ try {
10
+ return await fn();
11
+ } catch (fnErr) {
12
+ err = fnErr;
13
+ }
14
+
15
+ if (!hasAborted()) {
16
+ await delay(delayBetweenRetries);
17
+ return await _executeWithRetry(hasAborted);
18
+ }
19
+ }
20
+ }
21
+
22
+ module.exports = {executeWithRetry};
@@ -1,16 +0,0 @@
1
- const chalk = require('chalk');
2
- const boxen = require('boxen');
3
- console.log(
4
- boxen(
5
- `This is version 3 of ${chalk.cyan('@applitools/eyes-storybook')}.
6
- This version includes a wide variety of performance improvements and features.
7
- We recommend checking out the release notes:
8
- ${chalk.yellow('https://github.com/applitools/eyes-storybook/blob/v3.0.1/docs/release-notes-v3.md')}
9
-
10
- If you experience a difference in behavior between v2 and v3, it's possible to opt out of the optimization
11
- by configuring ${chalk.cyan('reloadPagePerStory')} to ${chalk.cyan(
12
- 'true',
13
- )}. And, do read the release notes - they explain it perfectly :-)`,
14
- {padding: 1, borderColor: 'cyan', align: 'center'},
15
- ),
16
- );