vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
12.72k stars 1.15k forks source link

Feature request: setup file #28

Closed wtchnm closed 2 years ago

wtchnm commented 2 years ago

Hey! Thanks for the great work so far! Loving it! I'm trying to use vitest in my toy project and I'm missing something like setupFilesAfterEnv so much 😢 I will be happy to make a PR if you can provide me with some guidance.

DannyFeliz commented 2 years ago

I guess you're talking about the vitest.config.ts file

See: Configuration

wtchnm commented 2 years ago

Unfortunately not, as I need to access the test context in this file. It is usually used to polyfill some APIs that JSDOM doesn't support like matchMedia. Example: https://github.com/wtchnm/Vitamin/blob/d548f619bfbb8924063b51891c22cc1978c81bc8/src/setupTests.ts#L8

Aslemammad commented 2 years ago

Yep, I see what you want! something like this: https://github.com/pmndrs/jotai/blob/main/package.json#L130

Aslemammad commented 2 years ago

I suggest you see how jest consumes the setup files, and then you can your time on the PR after @antfu's big rewrite. https://github.com/facebook/jest/search?q=setupFiles

wtchnm commented 2 years ago

Thanks @Aslemammad!

wtchnm commented 2 years ago

Thanks @antfu!