Skip to content

Commit

Permalink
Add support for Scrollable single element screenshot (#1458)
Browse files Browse the repository at this point in the history
* Add support for Scrollable single element screenshot

* Fix breaking test

* Address comments

* Add test for dependency validation

* Address comment
  • Loading branch information
chinmay-browserstack authored Dec 19, 2023
1 parent 264fe03 commit bb2bfad
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/cli-upload/test/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('percy upload', () => {
name: 'test-1.png',
widths: [10],
scope: null,
'scope-options': {},
'minimum-height': 10,
'enable-javascript': null,
'enable-layout': false
Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export class PercyClient {
name,
widths,
scope,
scopeOptions,
minHeight,
enableJavaScript,
enableLayout,
Expand Down Expand Up @@ -329,6 +330,7 @@ export class PercyClient {
name: name || null,
widths: widths || null,
scope: scope || null,
'scope-options': scopeOptions || {},
'minimum-height': minHeight || null,
'enable-javascript': enableJavaScript || null,
'enable-layout': enableLayout || false
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 @@ -578,6 +578,7 @@ describe('PercyClient', () => {
name: 'snapfoo',
widths: [1000],
scope: '#main',
scopeOptions: { scroll: true },
minHeight: 1000,
enableJavaScript: true,
enableLayout: true,
Expand Down Expand Up @@ -612,6 +613,7 @@ describe('PercyClient', () => {
widths: [1000],
scope: '#main',
'minimum-height': 1000,
'scope-options': { scroll: true },
'enable-javascript': true,
'enable-layout': true
},
Expand Down Expand Up @@ -654,6 +656,7 @@ describe('PercyClient', () => {
name: null,
widths: null,
scope: null,
'scope-options': {},
'minimum-height': null,
'enable-javascript': null,
'enable-layout': false
Expand Down Expand Up @@ -718,6 +721,7 @@ describe('PercyClient', () => {
attributes: {
name: 'test snapshot name',
scope: null,
'scope-options': {},
'enable-javascript': null,
'minimum-height': null,
widths: null,
Expand Down Expand Up @@ -1215,6 +1219,7 @@ describe('PercyClient', () => {
attributes: {
name: 'test snapshot name',
scope: null,
'scope-options': {},
'enable-javascript': null,
'minimum-height': null,
widths: null,
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ export const configSchema = {
scope: {
type: 'string'
},
scopeOptions: {
type: 'object',
additionalProperties: false,
properties: {
scroll: {
type: 'boolean'
}
}
},
freezeAnimation: { // for backward compatibility
type: 'boolean',
onlyAutomate: true
Expand Down Expand Up @@ -244,6 +253,7 @@ export const snapshotSchema = {
domTransformation: { $ref: '/config/snapshot#/properties/domTransformation' },
enableLayout: { $ref: '/config/snapshot#/properties/enableLayout' },
reshuffleInvalidTags: { $ref: '/config/snapshot#/properties/reshuffleInvalidTags' },
scopeOptions: { $ref: '/config/snapshot#/properties/scopeOptions' },
discovery: {
type: 'object',
additionalProperties: false,
Expand All @@ -258,6 +268,9 @@ export const snapshotSchema = {
devicePixelRatio: { $ref: '/config/discovery#/properties/devicePixelRatio' }
}
}
},
dependencies: {
scopeOptions: ['scope']
}
},
exec: {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function debugSnapshotOptions(snapshot) {
debugProp(snapshot, 'deviceScaleFactor');
debugProp(snapshot, 'waitForTimeout');
debugProp(snapshot, 'waitForSelector');
debugProp(snapshot, 'scopeOptions.scroll');
debugProp(snapshot, 'execute.afterNavigation');
debugProp(snapshot, 'execute.beforeResize');
debugProp(snapshot, 'execute.afterResize');
Expand Down
34 changes: 34 additions & 0 deletions packages/core/test/unit/config.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logger from '@percy/logger/test/helpers';
import { configMigration, snapshotSchema } from '../../src/config.js';
import * as CoreConfig from '@percy/core/config';
import PercyConfig from '@percy/config';

describe('Unit / Config Migration', () => {
let mocked = {
Expand Down Expand Up @@ -82,4 +84,36 @@ describe('SnapshotSchema', () => {
it('should contain domTransformation', () => {
expect(snapshotSchema.$defs.common.properties).toEqual(jasmine.objectContaining({ domTransformation: jasmine.anything() }));
});

it('scopeOptions should work with scope', () => {
const comparison = {
name: 'snapfoo',
url: 'some_url',
widths: [1000],
scope: '#main',
scopeOptions: { scroll: true },
enableJavaScript: true
};

PercyConfig.addSchema(CoreConfig.schemas);
const errors = PercyConfig.validate(comparison, '/snapshot');
expect(errors).toBe(undefined);
});

it('scopeOptions should not work without scope', () => {
const comparison = {
name: 'snapfoo',
url: 'some_url',
widths: [1000],
scopeOptions: { scroll: true },
enableJavaScript: true
};

PercyConfig.addSchema(CoreConfig.schemas);
const errors = PercyConfig.validate(comparison, '/snapshot');
expect(errors).not.toBe(null);
expect(errors.length).toBe(1);
expect(errors[0].path).toBe('scope');
expect(errors[0].message).toBe('must have property scope when property scopeOptions is present');
});
});
5 changes: 5 additions & 0 deletions packages/core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ interface DiscoveryOptions {
captureMockedServiceWorker?: boolean;
}

interface ScopeOptions {
scroll?: boolean;
}

interface DiscoveryLaunchOptions {
executable?: string;
args?: string[];
Expand All @@ -45,6 +49,7 @@ interface CommonSnapshotOptions {
reshuffleInvalidTags?: boolean;
devicePixelRatio?: number;
scope?: string;
scopeOptions?: ScopeOptions;
}

export interface SnapshotOptions extends CommonSnapshotOptions {
Expand Down
1 change: 1 addition & 0 deletions packages/core/types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const percyOptions: PercyOptions = {
percyCSS: '.percy { color: purple; }',
enableJavaScript: false,
scope: '.percy',
scopeOptions: { scroll: true },
devicePixelRatio: 2
},
discovery: {
Expand Down

0 comments on commit bb2bfad

Please sign in to comment.