mui / pigment-css

Pigment CSS is a zero-runtime CSS-in-JS library that extracts the colocated styles to their own CSS files at build time.
MIT License
396 stars 19 forks source link

[core] Migrate test runner to vitest #71

Open brijeshb42 opened 1 month ago

brijeshb42 commented 1 month ago

Note that the class names for the generated css have changed because earlier, the root directory was considered from repo root, but now, it considers the package directory as the root. And classname generation depends on this path.

oliviertassinari commented 1 month ago

What's the motivation for this change?

Janpot commented 3 weeks ago

For historic reasons Toolpad ended up using vitest instead of mocha for its unit tests. Current Toolpad could benefit from some of the test infra of core and maybe we'll try again to switch, but I have to admit, it's a lot less painful compared to karma+babel+mocha. Can't explain the the motivation for this change, but I can share my experience with vitest:

pros:

cons:

oliviertassinari commented 3 weeks ago

How do we run the tests in a real browser with vitest? As I understand things:

Now https://github.com/emotion-js/emotion/, https://github.com/callstack/linaria/, https://github.com/styled-components/styled-components/, seem to run tests with jest (and maybe jsdom) only.

https://vitest.dev/guide/browser.html + https://vitest.dev/guide/improving-performance.html, oh maybe could solve two pain points 🤔

cons: no babel means potentially testing differently compiled code.

We should transpile the source to be close to production, but I guess this won't be an issue.

const: can't reuse mui test utils

We should be able to reproduce equivalent utils.

Janpot commented 3 weeks ago

How do we run the tests in a real browser with vitest?

Yep, they're adding a browser mode. Granted, it's not declared stable yet, but I made it work today in Toolpad in relatively short time. It was that or move to mocha+karma. I gave it a quick shot, and it's quite delightful, still not supporting the full functionality of the node.js runner, but certainly seems to be usable for us.

We should transpile the source to be close to production, but I guess this won't be an issue.

vitest transpiles the code for you, with vite. It's a trade-off I'm personally willing to make. I think it could make sense to try and cover this use-case with a few integration tests instead. Fewer tests, but closer to actual production code.