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

Rerun setupFiles in watch mode #2614

Closed
4 tasks done
Maxim-Mazurok opened this issue Jan 5, 2023 · 6 comments · Fixed by #2625
Closed
4 tasks done

Rerun setupFiles in watch mode #2614

Maxim-Mazurok opened this issue Jan 5, 2023 · 6 comments · Fixed by #2625

Comments

@Maxim-Mazurok
Copy link
Contributor

Clear and concise description of the problem

I'm mocking http requests using msw and as suggested in vitest docs I'm putting my handlers in setup files.
While running vitest in watch mode I want to edit handlers and to have these changes applied before rerun of tests. However changes to setup files aren't being picked up in watch mode even if I forcefully rerun all tests. I need to restart vitest for changes to apply.

Suggested solution

Rerun all setupFiles in watch mode, or add an option to do that on a per-file basis.

Alternative

An alternative is probably using something like nodemon and then run vitest --run, but it probably isn't really worth the trouble, hopefully, I won't have to make many changes to mocked API once it's done.

Additional context

No response

Validations

@mysteryven
Copy link
Contributor

I won't have to make many changes to mocked API once it's done

The setupFiles will be run before each test file and not changes often, what about trigger server restart when setupFiles content changed just like config file, is it a good implementation ?

@Maxim-Mazurok
Copy link
Contributor Author

I won't have to make many changes to mocked API once it's done

The setupFiles will be run before each test file and not changes often, what about trigger server restart when setupFiles content changed just like config file, is it a good implementation ?

This does sound better to me. I don't expect these files to change as much as the actual tests during active development, so rerunning them every time might be a bit of a waste, so your suggested optimisation does sound good to me.

@sheremet-va
Copy link
Member

I think we can just add setupFiles to forceRerunTriggers. it will rerun every test, when file changes.

@mysteryven
Copy link
Contributor

I think we can just add setupFiles to forceRerunTriggers. it will rerun every test, when file changes.

Great! Thanks for your advice, I will try to solve it.

@Maxim-Mazurok
Copy link
Contributor Author

it will rerun every test, when file changes.

I'm not sure this will help... As I've mentioned in OP even when I rerun all the tests forcefully by pressing a - changes in setup files aren't picked up. Maybe this rerun isn't being forceful enough tho, not sure about the inner workings.

@mysteryven
Copy link
Contributor

mysteryven commented Jan 7, 2023

Aha, I am not really make sure, but I test it in this demo, I get the same result with you, the globalThis.a didn't change as expected when I change it in watch mode. I will read codes tomorrow or the day after tomorrow to get the exact reason.

sheremet-va pushed a commit that referenced this issue Jan 16, 2023
Co-authored-by: Vladimir Sheremet <sleuths.slews0s@icloud.com>
fix #2614
docschina-bot pushed a commit to vitest-dev/docs-cn that referenced this issue Jan 16, 2023
Co-authored-by: Vladimir Sheremet <sleuths.slews0s@icloud.com>
fix vitest-dev/vitest#2614
sheremet-va pushed a commit to sheremet-va/vitest that referenced this issue Jan 18, 2023
Co-authored-by: Vladimir Sheremet <sleuths.slews0s@icloud.com>
fix vitest-dev#2614
@github-actions github-actions bot locked and limited conversation to collaborators Jun 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants