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

✨ Introduce new config option enableLayout for enabling layout testing. #1378

Merged
merged 5 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion packages/cli-upload/test/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ describe('percy upload', () => {
widths: [10],
scope: null,
'minimum-height': 10,
'enable-javascript': null
'enable-javascript': null,
'enable-layout': false
},
relationships: {
resources: {
Expand Down
4 changes: 3 additions & 1 deletion packages/client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export class PercyClient {
scope,
minHeight,
enableJavaScript,
enableLayout,
clientInfo,
environmentInfo,
resources = []
Expand Down Expand Up @@ -324,7 +325,8 @@ export class PercyClient {
widths: widths || null,
scope: scope || null,
'minimum-height': minHeight || null,
'enable-javascript': enableJavaScript || null
'enable-javascript': enableJavaScript || null,
'enable-layout': enableLayout || false
},
relationships: {
resources: {
Expand Down
13 changes: 9 additions & 4 deletions packages/client/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ describe('PercyClient', () => {
scope: '#main',
minHeight: 1000,
enableJavaScript: true,
enableLayout: true,
clientInfo: 'sdk/info',
environmentInfo: 'sdk/env',
resources: [{
Expand Down Expand Up @@ -615,7 +616,8 @@ describe('PercyClient', () => {
widths: [1000],
scope: '#main',
'minimum-height': 1000,
'enable-javascript': true
'enable-javascript': true,
'enable-layout': true
},
relationships: {
resources: {
Expand Down Expand Up @@ -657,7 +659,8 @@ describe('PercyClient', () => {
widths: null,
scope: null,
'minimum-height': null,
'enable-javascript': null
'enable-javascript': null,
'enable-layout': false
},
relationships: {
resources: {
Expand Down Expand Up @@ -721,7 +724,8 @@ describe('PercyClient', () => {
scope: null,
'enable-javascript': null,
'minimum-height': null,
widths: null
widths: null,
'enable-layout': false
},
relationships: {
resources: {
Expand Down Expand Up @@ -1217,7 +1221,8 @@ describe('PercyClient', () => {
scope: null,
'enable-javascript': null,
'minimum-height': null,
widths: null
widths: null,
'enable-layout': false
},
relationships: {
resources: {
Expand Down
18 changes: 12 additions & 6 deletions packages/config/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,8 @@ describe('PercyConfig', () => {
'enable-javascript': false,
'disable-shadow-dom': true,
'cli-enable-javascript': true,
'ignore-region-xpaths': ['']
'ignore-region-xpaths': [''],
'enable-layout': false
})).toEqual({
fooBar: 'baz',
foo: { barBaz: 'qux' },
Expand All @@ -1211,7 +1212,8 @@ describe('PercyConfig', () => {
enableJavaScript: false,
disableShadowDOM: true,
cliEnableJavaScript: true,
ignoreRegionXPaths: ['']
ignoreRegionXPaths: [''],
enableLayout: false
});
});

Expand All @@ -1224,7 +1226,8 @@ describe('PercyConfig', () => {
enableJavaScript: false,
disableShadowDOM: true,
cliEnableJavaScript: true,
ignoreRegionXPaths: ['']
ignoreRegionXPaths: [''],
enableLayout: false
}, { kebab: true })).toEqual({
'foo-bar': 'baz',
foo: { 'bar-baz': 'qux' },
Expand All @@ -1233,7 +1236,8 @@ describe('PercyConfig', () => {
'enable-javascript': false,
'disable-shadow-dom': true,
'cli-enable-javascript': true,
'ignore-region-xpaths': ['']
'ignore-region-xpaths': [''],
'enable-layout': false
});
});

Expand All @@ -1246,7 +1250,8 @@ describe('PercyConfig', () => {
enableJavaScript: false,
disableShadowDOM: true,
cliEnableJavaScript: true,
ignoreRegionXPaths: ['']
ignoreRegionXPaths: [''],
enableLayout: false
}, { snake: true })).toEqual({
foo_bar: 'baz',
foo: { bar_baz: 'qux' },
Expand All @@ -1255,7 +1260,8 @@ describe('PercyConfig', () => {
enable_javascript: false,
disable_shadow_dom: true,
cli_enable_javascript: true,
ignore_region_xpaths: ['']
ignore_region_xpaths: [''],
enable_layout: false
});
});

Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export const configSchema = {
type: 'boolean',
default: false
},
enableLayout: {
type: 'boolean',
default: false
itsjwala marked this conversation as resolved.
Show resolved Hide resolved
},
domTransformation: {
type: 'string'
},
Expand Down Expand Up @@ -206,6 +210,7 @@ export const snapshotSchema = {
cliEnableJavaScript: { $ref: '/config/snapshot#/properties/cliEnableJavaScript' },
disableShadowDOM: { $ref: '/config/snapshot#/properties/disableShadowDOM' },
domTransformation: { $ref: '/config/snapshot#/properties/domTransformation' },
enableLayout: { $ref: '/config/snapshot#/properties/enableLayout' },
discovery: {
type: 'object',
additionalProperties: false,
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 @@ -36,6 +36,7 @@ function debugSnapshotOptions(snapshot) {
debugProp(snapshot, 'enableJavaScript');
debugProp(snapshot, 'cliEnableJavaScript');
debugProp(snapshot, 'disableShadowDOM');
debugProp(snapshot, 'enableLayout');
debugProp(snapshot, 'deviceScaleFactor');
debugProp(snapshot, 'waitForTimeout');
debugProp(snapshot, 'waitForSelector');
Expand Down
77 changes: 77 additions & 0 deletions packages/core/test/discovery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1930,4 +1930,81 @@ describe('Discovery', () => {
});
});
});

describe('Enable Layout =>', () => {
beforeEach(() => {
// global defaults
percy.config.snapshot.enableLayout = false;
});

describe('cli-snapshot =>', () => {
it('disabled by default', async () => {
percy.loglevel('debug');

await percy.snapshot({
name: 'test snapshot',
url: 'http://localhost:8000',
domSnapshot: ''
});

await percy.idle();

expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy:core:snapshot] - enableLayout: false'
]));
});

it('enable when enableLayout: true', async () => {
percy.config.snapshot.enableLayout = true;
percy.loglevel('debug');

await percy.snapshot({
name: 'test snapshot',
url: 'http://localhost:8000',
domSnapshot: ''
});

await percy.idle();

expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy:core:snapshot] - enableLayout: true'
]));
});
});

describe('percySnapshot with cli-exec =>', () => {
it('disabled by default', async () => {
percy.loglevel('debug');

await percy.snapshot({
name: 'test snapshot',
url: 'http://localhost:8000',
domSnapshot: testDOM
});

await percy.idle();

expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy:core:snapshot] - enableLayout: false'
]));
});

it('enable when enableLayout: true', async () => {
percy.config.snapshot.enableLayout = true;
percy.loglevel('debug');

await percy.snapshot({
name: 'test snapshot',
url: 'http://localhost:8000',
domSnapshot: testDOM
});

await percy.idle();

expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy:core:snapshot] - enableLayout: true'
]));
});
});
});
});
3 changes: 2 additions & 1 deletion packages/core/test/percy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ describe('Percy', () => {
percyCSS: '',
enableJavaScript: false,
disableShadowDOM: false,
cliEnableJavaScript: true
cliEnableJavaScript: true,
enableLayout: false
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface CommonSnapshotOptions {
percyCSS?: string;
enableJavaScript?: boolean;
disableShadowDOM?: boolean;
enableLayout?: boolean;
devicePixelRatio?: number;
scope?: string;
}
Expand Down
1 change: 1 addition & 0 deletions packages/dom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const domSnapshot = await page.evaluate(() => PercyDOM.serialize(options))
- `enableJavaScript` — When true, does not serialize some DOM elements
- `domTransformation` — Function to transform the DOM after serialization
- `disableShadowDOM` — disable shadow DOM capturing, this option can be passed to `percySnapshot` its part of per-snapshot config.
- `enableLayout` - When true, It enables layout testing.
itsjwala marked this conversation as resolved.
Show resolved Hide resolved

## Serialized Content

Expand Down