Skip to content

Commit

Permalink
Add build info in percy-info (#1269)
Browse files Browse the repository at this point in the history
* add build info in percy

* fix tests

* make coverage 100%
  • Loading branch information
pankaj443 authored Jun 2, 2023
1 parent b9c3734 commit 1d0255c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export function createPercyServer(percy, port) {
} else if (cmd === 'build-failure') {
// the build-failure command will cause api errors to include a failed build
percy.testing.build = { failed: true, error: 'Build failed' };
} else if (cmd === 'build-created') {
// the build-failure command will cause api errors to include a failed build
percy.testing.build = { id: '123', url: 'https://percy.io/test/test/123' };
} else {
// 404 for unknown commands
return res.send(404);
Expand Down
2 changes: 2 additions & 0 deletions packages/core/test/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ describe('API Server', () => {
expect(percy.testing).toEqual({});
await post('/test/api/build-failure');
expect(percy.testing).toHaveProperty('build', { failed: true, error: 'Build failed' });
await post('/test/api/build-created');
expect(percy.testing).toHaveProperty('build', { id: '123', url: 'https://percy.io/test/test/123' });
await post('/test/api/error', '/percy/healthcheck');
expect(percy.testing).toHaveProperty('api', { '/percy/healthcheck': 'error' });
await post('/test/api/disconnect', '/percy/healthcheck');
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-utils/src/percy-enabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export async function isPercyEnabled() {
let response = await request('/percy/healthcheck');
percy.version = response.headers['x-percy-core-version'];
percy.config = response.body.config;
percy.build = response.body.build;
percy.enabled = true;
} catch (e) {
percy.enabled = false;
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-utils/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const helpers = {
async setupTest({ logger = true } = {}) {
utils.percy.version = '';
delete utils.percy.config;
delete utils.percy.build;
delete utils.percy.enabled;
delete utils.percy.domScript;
delete utils.logger.log.history;
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk-utils/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('SDK Utils', () => {

beforeEach(async () => {
await helpers.test('version', '1.2.3-beta.4');
await helpers.test('build-created');
await expectAsync(isPercyEnabled()).toBeResolvedTo(true);
});

Expand All @@ -51,6 +52,11 @@ describe('SDK Utils', () => {
it('contains percy config', () => {
expect(percy).toHaveProperty('config.snapshot.widths', [375, 1280]);
});

it('contains percy build info', () => {
expect(percy.build).toHaveProperty('id', '123');
expect(percy.build).toHaveProperty('url', 'https://percy.io/test/test/123');
});
});
});

Expand Down

0 comments on commit 1d0255c

Please sign in to comment.