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: test examples in real browsers #242

Merged
merged 8 commits into from
Jan 16, 2023
Merged

feat: test examples in real browsers #242

merged 8 commits into from
Jan 16, 2023

Conversation

olizilla
Copy link
Contributor

@olizilla olizilla commented Jan 11, 2023

Pulls example tests out to own dir so we can run the same test for each ui library!

fixes: #222

You can see it run in CI at https://github.com/web3-storage/w3ui/actions/runs/3901558574/jobs/6663550379#step:6:13 and you can try it out locally from this branch by running:

$ pnpm install

# one time download of test browsers
$ pnpx playwright install

# fails for vanilla currently, but is ok, proceed.
$ pnpm build:examples 

$ pnpm test:examples

Scope: 20 of 33 workspace projects
examples/test/playwright test$ playwright test
[30 lines collapsed]
│ [30/33] [webkit] › sign-up-in.spec.ts:4:3 › vue: sign in
│ [31/33] [webkit] › uploads-list.spec.ts:4:3 › react: uploads list
│ [32/33] [webkit] › uploads-list.spec.ts:4:3 › solid: uploads list
│ [33/33] [webkit] › uploads-list.spec.ts:4:3 › vue: uploads list
│ 
│   33 passed (7s)
│ To open last HTML report run:
│ 
│   npx playwright show-report
│ 
└─ Done in 7.6s

note: the build fails currently as our vanilla examples fail to build currently, which is why we need these tests!

Adds and updates run scripts to make it easy to run package or example tests. Most of the time we'd want to run package tests locally, so this is set as the default.

# runs package tests
$ pnpm test

# builkd examples. must be run before test so the dist dir exits for each
$ pnpm build:examples

# run example test
$ pnpm test:examples

# serve examples, so you can poke around as a dev. 
$ pnpm serve:examples

Updates examples to produce relative URLs by setting base: '' in vite config. This allows us to serve all the examples from a single static server in the examples dir, and serve is added with a serve.json config to rewrite the paths so the dist dir is served for each example.

Adds playwright config to fire up the example server

Adds github workflow to set up and run the browser tests only if we make a change to the examples. We may change this to run for every change in the future, as we should probably check if the examples still work if we change a package!

Reduces the scope of our local github action to just handle setting up node and pnpm which is needed by every workflow. lint and test are now specified explicitly in workflows that should run them. We don't need to run those steps when we're doing browser testing.

Screenshot 2023-01-12 at 02 03 41

Screenshot 2023-01-12 at 01 57 39

whoo!
Screenshot 2023-01-12 at 11 00 28

License: MIT
Signed-off-by: Oli Evans [email protected]

- pulls example tests out to own dir to reuse them for each ui library.

also explores using vitest to drive playwright tests. It's ok, but I think we want as little friction as possible for browser testing, and i'm now inclined to use @playwright/test instead after trying it in #238 and now i see it has support for what we need to do here https://playwright.dev/docs/test-advanced#projects and https://playwright.dev/docs/test-parameterize

License: MIT
Signed-off-by: Oli Evans <[email protected]>
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 11, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@olizilla
Copy link
Contributor Author

I explored using vitest to drive playwright tests. It's ok, but a little clunky and I think we want as little friction as possible for browser testing. i'm now inclined to use @playwright/test instead after trying it in #238 and now i see it has support for what we need to do here https://playwright.dev/docs/test-advanced#projects and https://playwright.dev/docs/test-parameterize and if we stick with vanilla @playwright/test we can use a service to run our tests for us if we want to.

- make it nice for running tests in many browsers

License: MIT
Signed-off-by: Oli Evans <[email protected]>
License: MIT
Signed-off-by: Oli Evans <[email protected]>
- `pnpm test` runs package tests
- `pnpm test:examples` runs examples tests

License: MIT
Signed-off-by: Oli Evans <[email protected]>
License: MIT
Signed-off-by: Oli Evans <[email protected]>
@olizilla
Copy link
Contributor Author

olizilla commented Jan 12, 2023

Here's a good example of the kind of info we get from this... Our vue multi-file-upload example is having a bad day. Passes in all browsers for other ui libraries

Screenshot 2023-01-12 at 11 17 29

EDIT: oh ho ho... we haven't written that ui + example combo yet! but you get the point, we will get a heads up when one of the 20 existing examples breaks.

License: MIT
Signed-off-by: Oli Evans <[email protected]>
@olizilla olizilla marked this pull request as ready for review January 12, 2023 12:00
@olizilla olizilla changed the title feat: shared example tests feat: test examples in real browsers Jan 12, 2023
@olizilla olizilla mentioned this pull request Jan 13, 2023
@olizilla olizilla added this to the w3up phase 2 milestone Jan 13, 2023
Copy link
Member

@travis travis left a comment

Choose a reason for hiding this comment

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

I love it! I'm going to start a discussion around which examples we want to keep longer-term so I wouldn't go too much deeper on this for now, but I'm super excited about the approach!

@@ -0,0 +1,13 @@
import { test, expect } from '@playwright/test'

for (const ui of ['react', 'solid', 'vue'/* 'vanilla' not work atm */]) {
Copy link
Member

Choose a reason for hiding this comment

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

this is dope af

@olizilla
Copy link
Contributor Author

@travis thanks! i'm gonna land this but i'm more than happy to iterate on it to work with #256

@olizilla olizilla merged commit f733227 into main Jan 16, 2023
@olizilla olizilla deleted the shared-example-tests branch January 16, 2023 11:22
@alanshaw alanshaw mentioned this pull request Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add integration tests
2 participants