Skip to content

Commit

Permalink
Feat: Send domInfoSha & PoA optimizations (#1270)
Browse files Browse the repository at this point in the history
* Adding Optimizations for Screenshot and all

* Adding major poa v2 changes

* Updating tests for cli v2

* [lint fix] Updating lint

* [add tests, few feats] + tokentype, + misc

* Addressing few changes

* Adding percyCSS options for PoA [Snapshot level] (#1281)

* Adding percyCSS options for PoA

* [addressing comments]

* Addressing comments on test

* fixing tests

* [Refactor], Resolving comments

* Increase Statement Coverage

* fixing tests and small comments

* fixing core tests

* Making backward compatability

* make sdk-utils like before

* making timin.test.js less strict

* making import changes as per comment

* adding changes as per suggestion

* increase coverage for client

* adding param to getToken

* adding tests for getToken

---------

Co-authored-by: amit3200 <tusharamit@yahoo.com>
  • Loading branch information
nilshah98 and Amit3200 committed Jun 29, 2023
1 parent 58c8129 commit bcf83d7
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/cli-exec/src/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const exec = command('exec', {
} else {
try {
percy.projectType = percy.client.tokenType();
percy.skipDiscovery = percy.projectType !== 'web';
percy.skipDiscovery = percy.shouldSkipAssetDiscovery(percy.projectType);
yield* percy.yield.start();
} catch (error) {
if (error.name === 'AbortError') throw error;
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export class PercyClient {
}

// Checks for a Percy token and returns it.
getToken() {
getToken(raiseIfMissing = true) {
let token = this.token || this.env.token;
if (!token) throw new Error('Missing Percy token');
if (!token && raiseIfMissing) throw new Error('Missing Percy token');
return token;
}

Expand Down Expand Up @@ -510,7 +510,7 @@ export class PercyClient {

// decides project type
tokenType() {
let token = this.getToken();
let token = this.getToken(false) || '';

const type = token.split('_')[0];
switch (type) {
Expand Down
20 changes: 18 additions & 2 deletions packages/client/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1259,9 +1259,25 @@ describe('PercyClient', () => {
expect(client.tokenType()).toBe('web');
});

it('should throw error for no token', () => {
it('should return web for no token', () => {
client.token = '';
expect(() => { client.tokenType(); }).toThrowError('Missing Percy token');
expect(client.tokenType()).toBe('web');
});
});

describe('#getToken', () => {
it('should throw error when called with true', () => {
const client = new PercyClient({});
expect(() => {
client.getToken();
}).toThrowError('Missing Percy token');
});

it('should not throw error when called with false', () => {
const client = new PercyClient({
token: 'PERCY_TOKEN'
});
expect(client.getToken(false)).toBe('PERCY_TOKEN');
});
});
});
5 changes: 5 additions & 0 deletions packages/core/src/percy.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ export class Percy {
}
}.call(this));
}

shouldSkipAssetDiscovery(tokenType) {
if (this.testing && JSON.stringify(this.testing) === JSON.stringify({})) { return true; }
return tokenType !== 'web';
}
}

export default Percy;
46 changes: 46 additions & 0 deletions packages/core/test/percy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,4 +843,50 @@ describe('Percy', () => {
expect(api.requests['/builds/123/snapshots']).toBeUndefined();
});
});

describe('#shouldSkipAssetDiscovery', () => {
it('should return true if testing is true', () => {
percy = new Percy({
token: 'PERCY_TOKEN',
snapshot: { widths: [1000] },
discovery: { concurrency: 1 },
clientInfo: 'client-info',
environmentInfo: 'env-info',
testing: true
});
expect(percy.shouldSkipAssetDiscovery(percy.client.tokenType())).toBe(true);
});

it('should return false if token is not set', () => {
percy = new Percy({
snapshot: { widths: [1000] },
discovery: { concurrency: 1 },
clientInfo: 'client-info',
environmentInfo: 'env-info'
});
expect(percy.shouldSkipAssetDiscovery(percy.client.tokenType())).toBe(false);
});

it('should return false if web token is set', () => {
percy = new Percy({
token: 'PERCY_TOKEN',
snapshot: { widths: [1000] },
discovery: { concurrency: 1 },
clientInfo: 'client-info',
environmentInfo: 'env-info'
});
expect(percy.shouldSkipAssetDiscovery(percy.client.tokenType())).toBe(false);
});

it('should return true if auto token is set', () => {
percy = new Percy({
token: 'auto_PERCY_TOKEN',
snapshot: { widths: [1000] },
discovery: { concurrency: 1 },
clientInfo: 'client-info',
environmentInfo: 'env-info'
});
expect(percy.shouldSkipAssetDiscovery(percy.client.tokenType())).toBe(true);
});
});
});
4 changes: 2 additions & 2 deletions packages/sdk-utils/test/timing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ describe('TimeIt', () => {
expect(Object.keys(summary).length).toEqual(2);

// funcReturns
expect(summary.funcReturns.min - 100).toBeLessThan(10.0); // keeping 3 ms as buffer
expect(summary.funcReturns.max - 100).toBeLessThan(10.0);
expect(summary.funcReturns.min - 100).toBeLessThan(15.0); // adding buffer for win test
expect(summary.funcReturns.max - 100).toBeLessThan(15.0); // adding buffer for win test
expect(summary.funcReturns.avg - 100).toBeLessThan(10.0);
expect(summary.funcReturns.vals.length).toEqual(3);

Expand Down
2 changes: 1 addition & 1 deletion packages/webdriver-utils/src/providers/automateProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Cache from '../util/cache.js';
import Tile from '../util/tile.js';

const log = utils.logger('webdriver-utils:automateProvider');
const TimeIt = utils.TimeIt;
const { TimeIt } = utils;

export default class AutomateProvider extends GenericProvider {
constructor(
Expand Down
13 changes: 6 additions & 7 deletions packages/webdriver-utils/src/providers/genericProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ export default class GenericProvider {
await this.driver.executeScript({ script: removeStyleElement, args: [] });
}

async screenshot(name) {
const {
ignoreRegionXpaths = [],
ignoreRegionSelectors = [],
ignoreRegionElements = [],
customIgnoreRegions = []
} = this.options;
async screenshot(name, {
ignoreRegionXpaths = [],
ignoreRegionSelectors = [],
ignoreRegionElements = [],
customIgnoreRegions = []
}) {
let fullscreen = false;

const percyCSS = this.options.percyCSS || '';
Expand Down
2 changes: 1 addition & 1 deletion packages/webdriver-utils/src/util/cache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import utils from '@percy/sdk-utils';
const Undefined = utils.Undefined;
const { Undefined } = utils;

export default class Cache {
static cache = {};
Expand Down

0 comments on commit bcf83d7

Please sign in to comment.