Skip to content

Commit

Permalink
Added a test case for retry
Browse files Browse the repository at this point in the history
  • Loading branch information
ninadbstack committed Mar 7, 2024
1 parent db8c48b commit 46701d8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ export const snapshotSchema = {
captureMockedServiceWorker: { $ref: '/config/discovery#/properties/captureMockedServiceWorker' },
captureSrcset: { $ref: '/config/discovery#/properties/captureSrcset' },
userAgent: { $ref: '/config/discovery#/properties/userAgent' },
devicePixelRatio: { $ref: '/config/discovery#/properties/devicePixelRatio' }
devicePixelRatio: { $ref: '/config/discovery#/properties/devicePixelRatio' },
retry: { $ref: '/config/discovery#/properties/retry' }
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const RESOURCE_CACHE_KEY = Symbol('resource-cache');
// Creates an asset discovery queue that uses the percy browser instance to create a page for each
// snapshot which is used to intercept and capture snapshot resource requests.
export function createDiscoveryQueue(percy) {
let { concurrency, retry } = percy.config.discovery;
let { concurrency } = percy.config.discovery;
let queue = new Queue('discovery');
let cache;

Expand Down Expand Up @@ -336,7 +336,7 @@ export function createDiscoveryQueue(percy) {
await page.close();
}
}, {
count: retry ? 3 : 1,
count: snapshot.discovery.retry ? 3 : 1,
onRetry: () => {
percy.log.info(`Retrying snapshot: ${snapshotLogName(snapshot.name, snapshot.meta)}`, snapshot.meta);
},
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ function getSnapshotOptions(options, { config, meta }) {
disableCache: config.discovery.disableCache,
captureMockedServiceWorker: config.discovery.captureMockedServiceWorker,
captureSrcset: config.discovery.captureSrcset,
userAgent: config.discovery.userAgent
userAgent: config.discovery.userAgent,
retry: config.discovery.retry
}
}, options], (path, prev, next) => {
switch (path.map(k => k.toString()).join('.')) {
Expand Down
35 changes: 35 additions & 0 deletions packages/core/test/discovery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,41 @@ describe('Discovery', () => {
});
});

fdescribe('discovery retry', () => {
let Page;

beforeEach(async () => {
// some async request that takes a while and only resolves 4th time
let counter = 0;
server.reply('/', () => new Promise(r => (
(counter += 1) &&
setTimeout(r, counter === 3 ? 0 : 3000, [200, 'text/html', '<html></html>']))));
});

it('should retry the snapshot discovery upto 3 times', async () => {
// reset page timeout so that it gets read from env again
({ Page } = await import('../src/page.js'));
Page.TIMEOUT = undefined;
process.env.PERCY_PAGE_LOAD_TIMEOUT = 1000;

await percy.snapshot({
name: 'test navigation timeout',
url: 'http://localhost:8000',
discovery: { retry: true },
widths: [400, 800]
});

await percy.idle();

expect(logger.stdout).toEqual([
'[percy] Percy has started!',
'[percy] Retrying snapshot: test navigation timeout',
'[percy] Retrying snapshot: test navigation timeout',
'[percy] Snapshot taken: test navigation timeout'
]);
});
});

describe('navigation timeout', () => {
let Page;

Expand Down

0 comments on commit 46701d8

Please sign in to comment.