KittyCAD / modeling-app

The KittyCAD modeling app.
https://kittycad.io/modeling-app/download
MIT License
414 stars 35 forks source link

Playwright improvements #3065

Open Irev-Dev opened 3 months ago

Irev-Dev commented 3 months ago

Here's some broad stokes of what we'd love to see happen. Break these into as many PRs as you see fit.

Optional

ryanrosello-og commented 3 months ago

Other actionable items:

Irev-Dev commented 3 months ago

Excited for all this.

Tests in a single spec file I can add some context here. The main reason why there are just two files snapshot-tests.spec.ts and flow-tests.spec.ts is because the way we decided to do the snapshot tests, first of all we try and use snapshots sparingly, but there are a few places where it's the best way to verify something. But the motivation for having them in their own dedicated file was I've not seen a great way to update snapshot when they need to. In another repo I had this elaborate series of actions that would make a comment on PRs with the failed snapshots, and then if you made a special comment on the PR another action would run and update the snapshots, but honestly it was a big PITA.

So what we've opted for here is no always run snapshot-tests.spec.ts with --update-snapshots and then automatically commit the images in the PR, that way the images show up as part of the PR, if they needed updating then good, if the diff revealed a bug, you should notice and you can either force push away the image commit or just leave it since we squash merge our PR.

All that is to say in order to break up flow-tests.spec.ts then we'd just need to change the action from run only flow-tests.spec.ts to run everything except for snapshot-tests.spec.ts.

Add test-id attributes to the major components in the UI to ensure the tests don't become brittle by relying on css selectors that are prone to changes

Probably the worst cases for selectors are things like cm-content or cm-xxx really. The cm stands for code mirror, i.e. it's a library, I've not looked into how hard it would be get other attributes onto the elements we're interested in.

ryanrosello-og commented 3 months ago

ah good info.

I think we should be able to make use of Playwrights' Tagging mechanism

Essentially, we can tag all of the snapshot-tests with @snapshot

Tweak the GH Action:-

Run snapshot tests only:

yarn playwright test --project="Google Chrome" --grep @snapshot

Run all of the other tests (excluding snapshot tests)

yarn playwright test --project="Google Chrome" --grep-invert @snapshot

^ This way, we are not bound to the spec files.