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

feat: add alpha support for PWT snapshot testing #876

Merged
merged 9 commits into from
Nov 6, 2023
Merged

Conversation

clample
Copy link
Collaborator

@clample clample commented Oct 31, 2023

I hereby confirm that I followed the code guidelines found at engineering guidelines

Affected Components

  • CLI
  • Create CLI
  • Test
  • Docs
  • Examples
  • Other

Notes for the Reviewer

This PR adds initial support for PWT snapshot testing in the CLI . npx checkly test --update-snapshots updates any snapshots using the actual result of this test run. npx checkly deploy can then be used to actually push the snapshots: it updates the snapshots used by the check on Checkly.

TODO:

  • Update examples
  • Add integration test

One limitation in the current implementation is that we push the files to storage with every npx checkly deploy. We could probably improve this by adding some change detection using hashing. Such an implementation would be more complicated, though, so maybe we save it for later.

Integration tests are failing since the backend hasn't been deployed with the new schema yet.

Copy link

This pull request has been linked to Shortcut Story #17854: Add snapshot support to the CLI.

@clample clample force-pushed the chrislample/sc-17854 branch from 5ea330c to cccd7da Compare November 2, 2023 15:31
@clample clample requested a review from umutuzgur November 2, 2023 15:42
@clample clample marked this pull request as ready for review November 2, 2023 15:42
@clample clample force-pushed the chrislample/sc-17854 branch from cccd7da to 7e81874 Compare November 2, 2023 15:43
@clample clample force-pushed the chrislample/sc-17854 branch from 7e81874 to 6ee168d Compare November 2, 2023 16:02
@clample clample force-pushed the chrislample/sc-17854 branch from 6ee168d to 7bdc0cf Compare November 2, 2023 16:04
}
}

export function detectSnapshots (projectBasePath: string, scriptFilePath: string) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO:

Playwright is able to maintain different snapshot files for different platforms (f.ex *-chromium-linux.png for Chromium Linux, which is what we use in our runtimes).

This current implementation will detect all of the snapshots, though, rather than just pushing the Chromium Linux ones.

Comment on lines 250 to 252
if (updateSnapshots) {
await pullSnapshots(configDirectory, result.assets?.snapshots)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given we will write/update stuff in the local env, maybe we should ask a confirmation from the user at end of the test session

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure. I think that the whole point of --update-snapshots is to pull down the snapshots. I think that the user passing --update-snapshots is already enough of a confirmation to do this. I double checked and PWT also doesn't ask for additional confirmation.

@clample clample force-pushed the chrislample/sc-17854 branch from 7955a5e to 2f6ce1b Compare November 3, 2023 09:44
@@ -43,6 +43,35 @@ export async function walkDirectory (
}
}

export function findFilesRecursively (directory: string, ignoredPaths: Array<string> = []) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have a directory walker somewhere? I think we need a more flexible solution to support multiple scenarios. This is already the case at the runners IMO

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have walkDirectory here in util.ts. It's unused, though, and calls a callback rather than giving a list of matching files. I'll probably delete it.

findFilesRecursively should be basically the same as the one we have in runners, it's just missing the filePredicate arg. Should I go ahead and proactively add the filePredicate arg? Is there anything else that I should add to this one?

umutuzgur
umutuzgur previously approved these changes Nov 3, 2023
@clample clample changed the title feat: add support for PWT snapshot testing feat: add alpha support for PWT snapshot testing Nov 6, 2023
@clample clample added the build Issue regarding building and packaging label Nov 6, 2023

This comment has been minimized.

@clample clample added build Issue regarding building and packaging and removed build Issue regarding building and packaging labels Nov 6, 2023
Copy link

github-actions bot commented Nov 6, 2023

🎉 Experimental release successfully published on npm

npm install checkly@0.0.0-pr.876.77297fe

@clample clample requested a review from umutuzgur November 6, 2023 09:29
@clample
Copy link
Collaborator Author

clample commented Nov 6, 2023

@umutuzgur or @maxigimenez I deleted a leftover from when I was using EventEmitter: 77297fe. Could you please re-approve?

@clample clample requested a review from maxigimenez November 6, 2023 09:30
@clample clample enabled auto-merge (squash) November 6, 2023 09:32
@clample clample merged commit 711ddd6 into main Nov 6, 2023
4 checks passed
@clample clample deleted the chrislample/sc-17854 branch November 6, 2023 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issue regarding building and packaging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants