New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for capturing asset in multiple dpr and width combination #1536
Changes from 18 commits
eb9847d
a7e10e4
61113a9
b62f174
9877cc3
91e1b17
b90df23
dade996
2c31be6
11d8aff
3bad053
5e46151
45e1625
2eeef07
901d936
c9f1b43
7fe9bdb
957bc8a
fe4980f
9897bad
d808e07
240b409
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -353,6 +353,20 @@ describe('PercyClient', () => { | |||||
}); | ||||||
}); | ||||||
|
||||||
describe('#getDeviceDetails()', () => { | ||||||
it('in case of error return []', async () => { | ||||||
api.reply('/device-details', () => [500]); | ||||||
await expectAsync(client.getDeviceDetails()).toBeResolvedTo([]); | ||||||
}); | ||||||
|
||||||
it('gets device details', async () => { | ||||||
api.reply('/device-details', () => [200, { data: '<<device-data-without-build-id>>' }]); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
api.reply('/device-details?build_id=123', () => [200, { data: '<<device-data-with-build-id>>' }]); | ||||||
await expectAsync(client.getDeviceDetails()).toBeResolvedTo('<<device-data-without-build-id>>'); | ||||||
await expectAsync(client.getDeviceDetails(123)).toBeResolvedTo('<<device-data-with-build-id>>'); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe('#getBuilds()', () => { | ||||||
it('throws when missing a project path', async () => { | ||||||
await expectAsync(client.getBuilds()) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -55,6 +55,7 @@ function debugSnapshotOptions(snapshot) { | |||||||
debugProp(snapshot, 'discovery.authorization', JSON.stringify); | ||||||||
debugProp(snapshot, 'discovery.disableCache'); | ||||||||
debugProp(snapshot, 'discovery.captureMockedServiceWorker'); | ||||||||
debugProp(snapshot, 'discovery.captureSrcset'); | ||||||||
debugProp(snapshot, 'discovery.userAgent'); | ||||||||
debugProp(snapshot, 'clientInfo'); | ||||||||
debugProp(snapshot, 'environmentInfo'); | ||||||||
|
@@ -141,7 +142,7 @@ function processSnapshotResources({ domSnapshot, resources, ...snapshot }) { | |||||||
// the page and calling any provided execute options. | ||||||||
async function* captureSnapshotResources(page, snapshot, options) { | ||||||||
let { discovery, additionalSnapshots = [], ...baseSnapshot } = snapshot; | ||||||||
let { capture, captureWidths, deviceScaleFactor, mobile } = options; | ||||||||
let { capture, captureWidths, deviceScaleFactor, mobile, captureResponsiveDom } = options; | ||||||||
|
||||||||
// used to take snapshots and remove any discovered root resource | ||||||||
let takeSnapshot = async (options, width) => { | ||||||||
|
@@ -171,6 +172,14 @@ async function* captureSnapshotResources(page, snapshot, options) { | |||||||
yield page.evaluate(snapshot.execute.afterNavigation); | ||||||||
} | ||||||||
|
||||||||
// Running before page idle since this will trigger many network calls | ||||||||
// so need to run as early as possible. plus it is just reading urls from dom srcset | ||||||||
// which will be already loaded after navigation complete | ||||||||
if (discovery.captureSrcset) { | ||||||||
await page.insertPercyDom(); | ||||||||
yield page.eval('window.PercyDOM.loadAllSrcsetLinks()'); | ||||||||
} | ||||||||
|
||||||||
// iterate over additional snapshots for proper DOM capturing | ||||||||
for (let additionalSnapshot of [baseSnapshot, ...additionalSnapshots]) { | ||||||||
let isBaseSnapshot = additionalSnapshot === baseSnapshot; | ||||||||
|
@@ -189,6 +198,16 @@ async function* captureSnapshotResources(page, snapshot, options) { | |||||||
} | ||||||||
} | ||||||||
|
||||||||
if (captureResponsiveDom) { | ||||||||
for (const device of captureResponsiveDom) { | ||||||||
yield waitForDiscoveryNetworkIdle(page, discovery); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
yield* captureSnapshotResources(page, { ...snapshot, widths: [device.width] }, { | ||||||||
deviceScaleFactor: device.deviceScaleFactor, | ||||||||
mobile: true | ||||||||
}); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
if (capture && !snapshot.domSnapshot) { | ||||||||
// capture this snapshot and update the base snapshot after capture | ||||||||
let captured = yield takeSnapshot(snap, width); | ||||||||
|
@@ -203,13 +222,10 @@ async function* captureSnapshotResources(page, snapshot, options) { | |||||||
} | ||||||||
|
||||||||
// recursively trigger resource requests for any alternate device pixel ratio | ||||||||
if (deviceScaleFactor !== discovery.devicePixelRatio) { | ||||||||
yield waitForDiscoveryNetworkIdle(page, discovery); | ||||||||
|
||||||||
yield* captureSnapshotResources(page, snapshot, { | ||||||||
deviceScaleFactor: discovery.devicePixelRatio, | ||||||||
mobile: true | ||||||||
}); | ||||||||
if (discovery.devicePixelRatio) { | ||||||||
const log = logger('core:discovery'); | ||||||||
log.warn('discovery.devicePixelRatio is deprecated percy will now auto capture resource in all devicePixelRatio, Ignoring configuration'); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
discovery.devicePixelRatio = null; | ||||||||
} | ||||||||
|
||||||||
// wait for final network idle when not capturing DOM | ||||||||
|
@@ -308,7 +324,8 @@ export function createDiscoveryQueue(percy) { | |||||||
try { | ||||||||
yield* captureSnapshotResources(page, snapshot, { | ||||||||
captureWidths: !snapshot.domSnapshot && percy.deferUploads, | ||||||||
capture: callback | ||||||||
capture: callback, | ||||||||
captureResponsiveDom: percy.deviceDetails || [] | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. captureForDevices |
||||||||
}); | ||||||||
} finally { | ||||||||
// always close the page when done | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns list only correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes