Skip to content

Commit

Permalink
Added defer uploads option in test config endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmay-browserstack committed Sep 27, 2024
1 parent fe05534 commit 6fd3641
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ export function createPercyServer(percy, port) {
} else if (cmd === 'version') {
// the version command will update the api version header for testing
percy.testing.version = body;
} else if (cmd === 'widths') {
} else if (cmd === 'config') {
percy.config.snapshot.widths = body.config;
percy.deviceDetails = body.mobile?.map((w) => { return { width: w }; });
percy.config.snapshot.responsiveSnapshotCapture = !!body.responsive;
percy.config.percy.deferUploads = !!body.deferUploads;
} else if (cmd === 'error' || cmd === 'disconnect') {
// the error or disconnect commands will cause specific endpoints to fail
(percy.testing.api ||= {})[body] = cmd;
Expand Down
10 changes: 6 additions & 4 deletions packages/core/test/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,20 +731,22 @@ describe('API Server', () => {
expect(headers['x-percy-core-version']).toEqual('0.0.1');
});

it('can manipulate the config widths via /test/api/widths', async () => {
it('can manipulate the config widths via /test/api/config', async () => {
let { widths, config } = await get('/percy/healthcheck');
expect(widths.config).toEqual([375, 1280]);
expect(widths.mobile).toEqual([]);

await post('/test/api/widths', { config: [390] });
({ widths } = await get('/percy/healthcheck'));
await post('/test/api/config', { config: [390], deferUploads: true });
({ widths, config } = await get('/percy/healthcheck'));
expect(widths.config).toEqual([390]);
expect(config.snapshot.responsiveSnapshotCapture).toEqual(false);
expect(config.percy.deferUploads).toEqual(true);

await post('/test/api/widths', { config: [375, 1280], mobile: [456], responsive: true });
await post('/test/api/config', { config: [375, 1280], mobile: [456], responsive: true });
({ widths, config } = await get('/percy/healthcheck'));
expect(widths.mobile).toEqual([456]);
expect(config.snapshot.responsiveSnapshotCapture).toEqual(true);
expect(config.percy.deferUploads).toEqual(false);
});

it('can make endpoints return server errors via /test/api/error', async () => {
Expand Down

0 comments on commit 6fd3641

Please sign in to comment.