@percy/core
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -8,3 +8,3 @@ import PercyClient from '@percy/client'; | ||
import { gatherSnapshots, validateSnapshotOptions, discoverSnapshotResources } from './snapshot.js'; | ||
import { generatePromise } from './utils.js'; // A Percy instance will create a new build when started, handle snapshot | ||
import { generatePromise, yieldAll } from './utils.js'; // A Percy instance will create a new build when started, handle snapshot | ||
// creation, asset discovery, and resource uploads, and will finalize the build | ||
@@ -375,3 +375,3 @@ // when stopped. Snapshots are processed concurrently and the build is not | ||
} else if (Array.isArray(options)) { | ||
return Promise.all(options.map(o => this.snapshot(o))); | ||
return yieldAll(options.map(o => this.yield.snapshot(o))); | ||
} | ||
@@ -403,9 +403,7 @@ | ||
let snapshots = yield gatherSnapshots(this, options); | ||
let snapshots = yield* gatherSnapshots(this, options); | ||
try { | ||
// yield each task individually to allow canceling | ||
let tasks = snapshots.map(s => this._takeSnapshot(s)); | ||
for (let task of tasks) yield task; | ||
// use a try-catch to cancel snapshots that haven't started when the error occurred | ||
yield* yieldAll(snapshots.map(s => this._takeSnapshot(s))); | ||
} catch (error) { | ||
@@ -412,0 +410,0 @@ // cancel queued snapshots that may not have started |
@@ -5,3 +5,3 @@ import logger from '@percy/logger'; | ||
import { configSchema } from './config.js'; | ||
import { request, hostnameMatches, createRootResource, createPercyCSSResource, createLogResource } from './utils.js'; // Throw a better error message for missing or invalid urls | ||
import { request, hostnameMatches, createRootResource, createPercyCSSResource, createLogResource, yieldTo } from './utils.js'; // Throw a better error message for missing or invalid urls | ||
@@ -96,3 +96,3 @@ export function validURL(url, base) { | ||
export async function gatherSnapshots(percy, options) { | ||
export async function* gatherSnapshots(percy, options) { | ||
let { | ||
@@ -103,11 +103,10 @@ baseUrl, | ||
if ('url' in options) snapshots = [options]; | ||
if ('sitemap' in options) snapshots = await getSitemapSnapshots(options); // validate evaluated snapshots | ||
if ('sitemap' in options) snapshots = yield getSitemapSnapshots(options); // validate evaluated snapshots | ||
if (typeof snapshots === 'function') { | ||
({ | ||
snapshots = yield* yieldTo(snapshots(baseUrl)); | ||
snapshots = validateSnapshotOptions({ | ||
baseUrl, | ||
snapshots | ||
} = validateSnapshotOptions({ | ||
baseUrl, | ||
snapshots: await snapshots(baseUrl) | ||
})); | ||
}).snapshots; | ||
} // map snapshots with snapshot options | ||
@@ -114,0 +113,0 @@ |
@@ -49,2 +49,6 @@ import EventEmitter from 'events'; | ||
return createResource(`/percy.${Date.now()}.log`, JSON.stringify(logs), 'text/plain'); | ||
} // Returns true or false if the provided object is a generator or not | ||
export function isGenerator(subject) { | ||
return typeof (subject === null || subject === void 0 ? void 0 : subject.next) === 'function' && (typeof subject[Symbol.iterator] === 'function' || typeof subject[Symbol.asyncIterator] === 'function'); | ||
} // Iterates over the provided generator and resolves to the final value when done. With an | ||
@@ -56,4 +60,2 @@ // AbortSignal, the generator will throw with the abort reason when aborted. Also accepts an | ||
try { | ||
var _gen; | ||
if (typeof signal === 'function') [cb, signal] = [signal]; | ||
@@ -64,6 +66,6 @@ if (typeof gen === 'function') gen = await gen(); | ||
value | ||
} = typeof ((_gen = gen) === null || _gen === void 0 ? void 0 : _gen.next) === 'function' && (typeof gen[Symbol.iterator] === 'function' || typeof gen[Symbol.asyncIterator] === 'function') ? await gen.next() : { | ||
} = !isGenerator(gen) ? { | ||
done: true, | ||
value: await gen | ||
}; | ||
} : await gen.next(); | ||
@@ -109,2 +111,29 @@ while (!done) { | ||
} // An async generator that yields after every event loop until the promise settles | ||
export async function* yieldTo(subject) { | ||
var _subject; | ||
let pending = typeof ((_subject = subject) === null || _subject === void 0 ? void 0 : _subject.finally) === 'function'; | ||
if (pending) subject = subject.finally(() => pending = false); | ||
/* eslint-disable-next-line no-unmodified-loop-condition */ | ||
while (pending) yield new Promise(r => setImmediate(r)); | ||
return isGenerator(subject) ? yield* subject : await subject; | ||
} // An async generator that runs provided generators concurrently | ||
export async function* yieldAll(all) { | ||
let res = new Array(all.length).fill(); | ||
all = all.map(yieldTo); | ||
while (true) { | ||
res = await Promise.all(all.map((g, i) => { | ||
var _res$i, _res$i2; | ||
return (_res$i = res[i]) !== null && _res$i !== void 0 && _res$i.done ? res[i] : g.next((_res$i2 = res[i]) === null || _res$i2 === void 0 ? void 0 : _res$i2.value); | ||
})); | ||
let vals = res.map(r => r === null || r === void 0 ? void 0 : r.value); | ||
if (res.some(r => !(r !== null && r !== void 0 && r.done))) yield vals;else return vals; | ||
} | ||
} // An async generator that infinitely yields to the predicate function until a truthy value is | ||
@@ -214,3 +243,3 @@ // returned. When a timeout is provided, an error will be thrown during the next iteration after the | ||
fnbody = 'function withPercyHelpers() {\n' + ['const { config, snapshot } = window.__PERCY__ ?? {};', `return (${fnbody})({`, ' config, snapshot, generatePromise, yieldFor,', ' waitFor, waitForTimeout, waitForSelector, waitForXPath,', ' scrollToBottom', '}, ...arguments);', `${generatePromise}`, `${yieldFor}`, `${waitFor}`, `${waitForTimeout}`, `${waitForSelector}`, `${waitForXPath}`, `${scrollToBottom}`].join('\n') + '\n}'; | ||
fnbody = 'function withPercyHelpers() {\n' + ['const { config, snapshot } = window.__PERCY__ ?? {};', `return (${fnbody})({`, ' config, snapshot, generatePromise, yieldFor,', ' waitFor, waitForTimeout, waitForSelector, waitForXPath,', ' scrollToBottom', '}, ...arguments);', `${isGenerator}`, `${generatePromise}`, `${yieldFor}`, `${waitFor}`, `${waitForTimeout}`, `${waitForSelector}`, `${waitForXPath}`, `${scrollToBottom}`].join('\n') + '\n}'; | ||
/* istanbul ignore else: ironic. */ | ||
@@ -217,0 +246,0 @@ |
{ | ||
"name": "@percy/core", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"license": "MIT", | ||
@@ -42,6 +42,6 @@ "repository": { | ||
"dependencies": { | ||
"@percy/client": "1.7.0", | ||
"@percy/config": "1.7.0", | ||
"@percy/dom": "1.7.0", | ||
"@percy/logger": "1.7.0", | ||
"@percy/client": "1.7.1", | ||
"@percy/config": "1.7.1", | ||
"@percy/dom": "1.7.1", | ||
"@percy/logger": "1.7.1", | ||
"content-disposition": "^0.5.4", | ||
@@ -57,3 +57,3 @@ "cross-spawn": "^7.0.3", | ||
}, | ||
"gitHead": "f1418fb1effdaad2d32c65d1a358282ab1f9ec32" | ||
"gitHead": "012892cdaf7a07aa1b5aa355017639cee0e8a19e" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149702
3322
+ Added@percy/client@1.7.1(transitive)
+ Added@percy/config@1.7.1(transitive)
+ Added@percy/dom@1.7.1(transitive)
+ Added@percy/env@1.7.1(transitive)
+ Added@percy/logger@1.7.1(transitive)
- Removed@percy/client@1.7.0(transitive)
- Removed@percy/config@1.7.0(transitive)
- Removed@percy/dom@1.7.0(transitive)
- Removed@percy/env@1.7.0(transitive)
- Removed@percy/logger@1.7.0(transitive)
Updated@percy/client@1.7.1
Updated@percy/config@1.7.1
Updated@percy/dom@1.7.1
Updated@percy/logger@1.7.1