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

Change behaviour of enable JS to prioritise options passed #1001

Merged
merged 2 commits into from
Jul 25, 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
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
Loading