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

add tests #150

Closed
travis opened this issue Dec 7, 2022 · 9 comments
Closed

add tests #150

travis opened this issue Dec 7, 2022 · 9 comments
Assignees
Milestone

Comments

@travis
Copy link
Member

travis commented Dec 7, 2022

UI testing! A very special hell that we should probably brave sooner than later.

We currently have a codesandbox integration configured that at least builds the example apps in CI.

We should add tests similar to the ones in the HeadlessUI component library, eg:

https://github.com/tailwindlabs/headlessui/blob/main/packages/%40headlessui-react/src/components/combobox/combobox.test.tsx

Now that we have a bit of complexity in this library, some basic testing will probably make our lives easier down the road.

@heyjay44 heyjay44 added this to the w3up phase 2 milestone Dec 7, 2022
@alanshaw
Copy link
Member

🙏 yes please, I am the worst for not adding in the first place.

@travis
Copy link
Member Author

travis commented Jan 3, 2023

I spent a bit of time before the break on this and ran into some annoying issues where Jest had trouble loading ESM dependencies. @hugomrdias mentioned yesterday that he was interested in looking into alternatives to Jest, which I'd be excited about based on this experience and others, and spent a bit of time researching the state of the art during which I found this article:

https://whistlr.info/2022/test-react-builtin/

TLDR is

a) Node 18 comes with a builtin testing library node:test that uses ESM rather than insisting on CJS as Jest does, which should help with the issues I was having
b) node:test is definitely much more barebones than Jest or Mocha, and needs some sugar to feel as slick as Jest or Mocha
c) because node:test uses ESM, mocking third party dependencies is hard:
Screen Shot 2023-01-03 at 1 59 30 PM

Given all this I'm leaning slightly in the direction of trying to use node:test but probably need to discuss further with anyone interested. Would love to know what others think/if anyone has experience with this stuff and can provide an informed perspective!

@gobengo
Copy link
Contributor

gobengo commented Jan 3, 2023

@travis in general I've been told (by @alanshaw iirc) that we should use ava for tests. It's a good middle ground that supports ESM.

I did some tinkering over break with node:test builtin. It's ok but IMO doesn't have as good a story around --watch or reporters as ava does.

@travis
Copy link
Member Author

travis commented Jan 6, 2023

this has been broken down into #222 and #223. keeping this around to track the higher level intent to add more testing but we can close it once the sub-issues are closed.

@travis travis removed their assignment Jan 6, 2023
@olizilla olizilla self-assigned this Jan 9, 2023
@olizilla
Copy link
Contributor

olizilla commented Jan 9, 2023

here is a nice example of reusing the vite preview server for a browser based playwright test from vitest.
https://github.com/vitest-dev/vitest/blob/main/examples/playwright/test/basic.test.ts

for integration tests, i think re-using the vite preview server would be a win, and using playwright to handle browsers for us has been the least worst option we've hit so far.

playwright-test is optional... we can use it's expect implementation where it helps us. it's adapted to keep checking a condition instead of failing immediately, to deal having to wait for a separate browser process to do the thing.

vitest is a wildcard, but might be a sensible choice to replace jest. vitest would reuse our vite config, and bring our dev and test set up closer together. I should caveat that i don't love chunky, global-meddling, test framewords like jest or vitest, but there is an argument for using something that is popular for frontend projects so we can point to a good example and catch any gotchas ourselves before other users do. Also noting that jest still being cjs only and somewhat stuck there if it wants to keep mocking means it may quickly fall out of favour.

@olizilla
Copy link
Contributor

olizilla commented Jan 9, 2023

We could use ava here to align with our other repos, and this example shows how we might integrate ava and playwright https://playwright.dev/docs/test-runners#ava

@olizilla
Copy link
Contributor

olizilla commented Jan 9, 2023

i'm exploring plain vanilla playwright integration testing for our examples in #238

yusefnapora added a commit that referenced this issue Jan 12, 2023
Based on the discussion in #150, I decided to try replacing ava with
vitest and found that it was super easy 😄 Much nicer out-of-the-box
experience than getting ava to play nice with typescript.

Any objections to tossing ava overboard? edit: once the build failure is
sorted out, that is 😐
@alanshaw
Copy link
Member

Now that #242 is merged can we consider this issue closed?

@travis
Copy link
Member Author

travis commented Jan 25, 2023

yep I think so!

@travis travis closed this as completed 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

No branches or pull requests

5 participants