Skip to content

Commit

Permalink
Change behaviour of enable JS to prioritise options passed (#1001)
Browse files Browse the repository at this point in the history
* Change behaviour of enable JS to prioritize options passed

* Added tests
  • Loading branch information
chinmay-browserstack authored Jul 25, 2024
1 parent af9c33d commit a53974a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ export async function* takeStorybookSnapshots(percy, callback, { baseUrl, flags
// separate story and snapshot options
let { id, args, globals, queryParams, ...options } = snapshots[0];

if (flags.dryRun || options.enableJavaScript || percy.config.snapshot.enableJavaScript) {
const enableJavaScript = options.enableJavaScript ?? percy.config.snapshot.enableJavaScript;
if (flags.dryRun || enableJavaScript) {
log.debug(`Loading story via previewResource: ${options.name}`);
// when dry-running or when javascript is enabled, use the preview dom
options.domSnapshot = previewResource.content;
Expand Down
3 changes: 2 additions & 1 deletion test/.storybook/snapshot.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const First = () => (

First.parameters = {
percy: {
domTransformation: '(documentElement) => { documentElement.querySelectorAll(".removeMe").forEach(ele => ele.remove()); }'
domTransformation: '(documentElement) => { documentElement.querySelectorAll(".removeMe").forEach(ele => ele.remove()); }',
enableJavascript: false // this should be priotised over global config
}
}
export const Second = () => (
Expand Down
18 changes: 18 additions & 0 deletions test/storybook.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,24 @@ describe('percy storybook', () => {
expect(callArgs[1][0].domSnapshot).toEqual(previewDOM);
});

it('uses the preview dom when javascript is enabled', async () => {
fs.writeFileSync('.percy.yml', [
'version: 2',
'snapshot:',
' enableJavaScript: true'
].join('\n'));

// eslint-disable-next-line import/no-extraneous-dependencies
let { Percy } = await import('@percy/core');
spyOn(Percy.prototype, 'snapshot').and.callThrough();

await storybook(['http://localhost:9000', '--include=First', '--verbose']);

expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy:storybook] Loading story: Snapshot: First'
]));
});

it('removes element when domTransformation is passed', async () => {
// eslint-disable-next-line import/no-extraneous-dependencies
let { Percy } = await import('@percy/core');
Expand Down

0 comments on commit a53974a

Please sign in to comment.