Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding visual scanner support #1778

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,8 @@ export class PercyClient {
return 'app';
case 'ss':
return 'generic';
case 'vmw':
return 'visual_scanner';
default:
return 'web';
}
Expand Down
5 changes: 5 additions & 0 deletions packages/client/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/percy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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!');
Expand Down Expand Up @@ -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) {
Expand Down
46 changes: 46 additions & 0 deletions packages/core/test/percy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
});
Loading