Skip to content

Commit 19d9af2

Browse files
Adding visual scanner support (#1778)
1 parent 744f0a7 commit 19d9af2

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

packages/client/src/client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@ export class PercyClient {
688688
return 'app';
689689
case 'ss':
690690
return 'generic';
691+
case 'vmw':
692+
return 'visual_scanner';
691693
default:
692694
return 'web';
693695
}

packages/client/test/client.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,11 @@ describe('PercyClient', () => {
15921592
expect(client.tokenType()).toBe('web');
15931593
});
15941594

1595+
it('should return visual_scanner for vmw token', () => {
1596+
client.token = 'vmw_abc';
1597+
expect(client.tokenType()).toBe('visual_scanner');
1598+
});
1599+
15951600
it('should return web for no token', () => {
15961601
client.token = '';
15971602
expect(client.tokenType()).toBe('web');

packages/core/src/percy.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ export class Percy {
128128
return this.server?.address();
129129
}
130130

131+
renderingTypeProject() {
132+
return this.projectType === 'web' || this.projectType === 'visual_scanner';
133+
}
134+
131135
// Set client & environment info, and override loaded config options
132136
set({ clientInfo, environmentInfo, ...config }) {
133137
this.client.addClientInfo(clientInfo);
@@ -179,12 +183,12 @@ export class Percy {
179183
if (!this.skipDiscovery) yield this.#discovery.start();
180184
// start a local API server for SDK communication
181185
if (this.server) yield this.server.listen();
182-
if (this.projectType === 'web') {
186+
if (this.renderingTypeProject()) {
183187
if (!process.env.PERCY_DO_NOT_CAPTURE_RESPONSIVE_ASSETS || process.env.PERCY_DO_NOT_CAPTURE_RESPONSIVE_ASSETS !== 'true') {
184188
this.deviceDetails = yield this.client.getDeviceDetails(this.build?.id);
185189
}
186190
}
187-
const snapshotType = this.projectType === 'web' ? 'snapshot' : 'comparison';
191+
const snapshotType = this.renderingTypeProject() ? 'snapshot' : 'comparison';
188192
this.syncQueue = new WaitForJob(snapshotType, this);
189193
// log and mark this instance as started
190194
this.log.info('Percy has started!');
@@ -435,7 +439,8 @@ export class Percy {
435439

436440
shouldSkipAssetDiscovery(tokenType) {
437441
if (this.testing && JSON.stringify(this.testing) === JSON.stringify({})) { return true; }
438-
return tokenType !== 'web';
442+
const assetDiscoverySupportedTypes = ['web', 'visual_scanner'];
443+
return !assetDiscoverySupportedTypes.includes(tokenType);
439444
}
440445

441446
syncMode(options) {

packages/core/test/percy.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,17 @@ describe('Percy', () => {
11201120
});
11211121
expect(percy.shouldSkipAssetDiscovery(percy.client.tokenType())).toBe(true);
11221122
});
1123+
1124+
it('should return false if visual scanner token is set', () => {
1125+
percy = new Percy({
1126+
token: 'vmw_PERCY_TOKEN',
1127+
snapshot: { widths: [1000] },
1128+
discovery: { concurrency: 1 },
1129+
clientInfo: 'client-info',
1130+
environmentInfo: 'env-info'
1131+
});
1132+
expect(percy.shouldSkipAssetDiscovery(percy.client.tokenType())).toBe(false);
1133+
});
11231134
});
11241135

11251136
describe('sendBuildLogs', () => {
@@ -1423,4 +1434,39 @@ describe('Percy', () => {
14231434
expect(logger.stderr).toEqual(jasmine.arrayContaining([]));
14241435
});
14251436
});
1437+
1438+
describe('#renderingTypeProject', () => {
1439+
it('should return true if project type is web', async () => {
1440+
percy = new Percy({
1441+
token: 'PERCY_TOKEN',
1442+
projectType: 'web',
1443+
snapshot: { widths: [1000] },
1444+
discovery: { concurrency: 1 }
1445+
});
1446+
1447+
expect(percy.renderingTypeProject()).toEqual(true);
1448+
});
1449+
1450+
it('should return true if project type is web', async () => {
1451+
percy = new Percy({
1452+
token: 'PERCY_TOKEN',
1453+
projectType: 'visual_scanner',
1454+
snapshot: { widths: [1000] },
1455+
discovery: { concurrency: 1 }
1456+
});
1457+
1458+
expect(percy.renderingTypeProject()).toEqual(true);
1459+
});
1460+
1461+
it('should return false if project type is app', async () => {
1462+
percy = new Percy({
1463+
token: 'PERCY_TOKEN',
1464+
projectType: 'app',
1465+
snapshot: { widths: [1000] },
1466+
discovery: { concurrency: 1 }
1467+
});
1468+
1469+
expect(percy.renderingTypeProject()).toEqual(false);
1470+
});
1471+
});
14261472
});

0 commit comments

Comments
 (0)