creevey 0.8.2-fix-wait.0 → 0.8.2-fix-wait.2

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.
@@ -137,10 +137,11 @@ async function waitForStorybook(browser) {
137
137
  }, 60000);
138
138
 
139
139
  while (wait !== false) {
140
- wait = await browser.executeAsyncScript(function (SET_STORIES, callback) {
141
- if (typeof window.__STORYBOOK_ADDONS_CHANNEL__ == 'undefined') return callback(true);
142
- if (window.__STORYBOOK_ADDONS_CHANNEL__.last(SET_STORIES) == undefined) return callback(true);
143
- return callback(false);
140
+ wait = await browser.executeScript(function (SET_STORIES) {
141
+ if (typeof window.__STORYBOOK_ADDONS_CHANNEL__ == 'undefined') return true;
142
+ if (window.__STORYBOOK_ADDONS_CHANNEL__.last(SET_STORIES) == undefined) return true;
143
+ if (typeof window.__CREEVEY_UPDATE_GLOBALS__ == 'undefined') return true;
144
+ return false;
144
145
  }, Events.SET_STORIES);
145
146
  if (!wait) clearTimeout(initiateTimeout);
146
147
  }
@@ -411,10 +412,12 @@ async function resolveCreeveyHost(browser, port) {
411
412
  const addresses = getAddresses();
412
413
  creeveyServerHost = await browser.executeAsyncScript(function (hosts, port, callback) {
413
414
  void Promise.all(hosts.map(function (host) {
414
- // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
415
- return fetch('http://' + host + ':' + port + '/ping').then(function (response) {
415
+ return Promise.race([// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
416
+ fetch('http://' + host + ':' + port + '/ping').then(function (response) {
416
417
  return response.text();
417
- }).then(function (pong) {
418
+ }), new Promise((_resolve, reject) => {
419
+ setTimeout(reject, 5000);
420
+ })]).then(function (pong) {
418
421
  return pong == 'pong' ? host : null;
419
422
  }).catch(function () {
420
423
  return null;
@@ -109,10 +109,11 @@ async function waitForStorybook(browser) {
109
109
  }, 60000);
110
110
 
111
111
  while (wait !== false) {
112
- wait = await browser.executeAsyncScript(function (SET_STORIES, callback) {
113
- if (typeof window.__STORYBOOK_ADDONS_CHANNEL__ == 'undefined') return callback(true);
114
- if (window.__STORYBOOK_ADDONS_CHANNEL__.last(SET_STORIES) == undefined) return callback(true);
115
- return callback(false);
112
+ wait = await browser.executeScript(function (SET_STORIES) {
113
+ if (typeof window.__STORYBOOK_ADDONS_CHANNEL__ == 'undefined') return true;
114
+ if (window.__STORYBOOK_ADDONS_CHANNEL__.last(SET_STORIES) == undefined) return true;
115
+ if (typeof window.__CREEVEY_UPDATE_GLOBALS__ == 'undefined') return true;
116
+ return false;
116
117
  }, Events.SET_STORIES);
117
118
  if (!wait) clearTimeout(initiateTimeout);
118
119
  }
@@ -383,10 +384,12 @@ async function resolveCreeveyHost(browser, port) {
383
384
  const addresses = getAddresses();
384
385
  creeveyServerHost = await browser.executeAsyncScript(function (hosts, port, callback) {
385
386
  void Promise.all(hosts.map(function (host) {
386
- // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
387
- return fetch('http://' + host + ':' + port + '/ping').then(function (response) {
387
+ return Promise.race([// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
388
+ fetch('http://' + host + ':' + port + '/ping').then(function (response) {
388
389
  return response.text();
389
- }).then(function (pong) {
390
+ }), new Promise((_resolve, reject) => {
391
+ setTimeout(reject, 5000);
392
+ })]).then(function (pong) {
390
393
  return pong == 'pong' ? host : null;
391
394
  }).catch(function () {
392
395
  return null;
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "addon",
14
14
  "test"
15
15
  ],
16
- "version": "0.8.2-fix-wait.0",
16
+ "version": "0.8.2-fix-wait.2",
17
17
  "bin": {
18
18
  "creevey": "./lib/cjs/cli.js"
19
19
  },