From 5b18b1d363c76f5076aa02d5fd5f3a3fbadfdf85 Mon Sep 17 00:00:00 2001 From: rishigupta1599 Date: Tue, 12 Nov 2024 21:21:03 +0530 Subject: [PATCH] Adding visual scanner support --- packages/client/src/client.js | 2 ++ packages/client/test/client.test.js | 5 ++++ packages/core/src/percy.js | 11 +++++-- packages/core/test/percy.test.js | 46 +++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/packages/client/src/client.js b/packages/client/src/client.js index 2cf2b886d..7bee9cce5 100644 --- a/packages/client/src/client.js +++ b/packages/client/src/client.js @@ -688,6 +688,8 @@ export class PercyClient { return 'app'; case 'ss': return 'generic'; + case 'vmw': + return 'visual_scanner'; default: return 'web'; } diff --git a/packages/client/test/client.test.js b/packages/client/test/client.test.js index 6532fe5fb..c7299cfaa 100644 --- a/packages/client/test/client.test.js +++ b/packages/client/test/client.test.js @@ -1592,6 +1592,11 @@ describe('PercyClient', () => { expect(client.tokenType()).toBe('web'); }); + it('should return visual_scanner for vmw token', () => { + client.token = 'vmw_abc'; + expect(client.tokenType()).toBe('visual_scanner'); + }); + it('should return web for no token', () => { client.token = ''; expect(client.tokenType()).toBe('web'); diff --git a/packages/core/src/percy.js b/packages/core/src/percy.js index 6276ccb28..89de52890 100644 --- a/packages/core/src/percy.js +++ b/packages/core/src/percy.js @@ -128,6 +128,10 @@ export class Percy { return this.server?.address(); } + renderingTypeProject() { + return this.projectType === 'web' || this.projectType === 'visual_scanner'; + } + // Set client & environment info, and override loaded config options set({ clientInfo, environmentInfo, ...config }) { this.client.addClientInfo(clientInfo); @@ -179,12 +183,12 @@ export class Percy { if (!this.skipDiscovery) yield this.#discovery.start(); // start a local API server for SDK communication if (this.server) yield this.server.listen(); - if (this.projectType === 'web') { + if (this.renderingTypeProject()) { if (!process.env.PERCY_DO_NOT_CAPTURE_RESPONSIVE_ASSETS || process.env.PERCY_DO_NOT_CAPTURE_RESPONSIVE_ASSETS !== 'true') { this.deviceDetails = yield this.client.getDeviceDetails(this.build?.id); } } - const snapshotType = this.projectType === 'web' ? 'snapshot' : 'comparison'; + const snapshotType = this.renderingTypeProject() ? 'snapshot' : 'comparison'; this.syncQueue = new WaitForJob(snapshotType, this); // log and mark this instance as started this.log.info('Percy has started!'); @@ -435,7 +439,8 @@ export class Percy { shouldSkipAssetDiscovery(tokenType) { if (this.testing && JSON.stringify(this.testing) === JSON.stringify({})) { return true; } - return tokenType !== 'web'; + const assetDiscoverySupportedTypes = ['web', 'visual_scanner']; + return !assetDiscoverySupportedTypes.includes(tokenType); } syncMode(options) { diff --git a/packages/core/test/percy.test.js b/packages/core/test/percy.test.js index ee6aeb314..fec47941a 100644 --- a/packages/core/test/percy.test.js +++ b/packages/core/test/percy.test.js @@ -1120,6 +1120,17 @@ describe('Percy', () => { }); expect(percy.shouldSkipAssetDiscovery(percy.client.tokenType())).toBe(true); }); + + it('should return false if visual scanner token is set', () => { + percy = new Percy({ + token: 'vmw_PERCY_TOKEN', + snapshot: { widths: [1000] }, + discovery: { concurrency: 1 }, + clientInfo: 'client-info', + environmentInfo: 'env-info' + }); + expect(percy.shouldSkipAssetDiscovery(percy.client.tokenType())).toBe(false); + }); }); describe('sendBuildLogs', () => { @@ -1423,4 +1434,39 @@ describe('Percy', () => { expect(logger.stderr).toEqual(jasmine.arrayContaining([])); }); }); + + describe('#renderingTypeProject', () => { + it('should return true if project type is web', async () => { + percy = new Percy({ + token: 'PERCY_TOKEN', + projectType: 'web', + snapshot: { widths: [1000] }, + discovery: { concurrency: 1 } + }); + + expect(percy.renderingTypeProject()).toEqual(true); + }); + + it('should return true if project type is web', async () => { + percy = new Percy({ + token: 'PERCY_TOKEN', + projectType: 'visual_scanner', + snapshot: { widths: [1000] }, + discovery: { concurrency: 1 } + }); + + expect(percy.renderingTypeProject()).toEqual(true); + }); + + it('should return false if project type is app', async () => { + percy = new Percy({ + token: 'PERCY_TOKEN', + projectType: 'app', + snapshot: { widths: [1000] }, + discovery: { concurrency: 1 } + }); + + expect(percy.renderingTypeProject()).toEqual(false); + }); + }); });