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

globalSetup executed twice with --ui #679

Closed
6 tasks done
dominikg opened this issue Feb 4, 2022 · 2 comments
Closed
6 tasks done

globalSetup executed twice with --ui #679

dominikg opened this issue Feb 4, 2022 · 2 comments

Comments

@dominikg
Copy link
Contributor

dominikg commented Feb 4, 2022

Describe the bug

If you add a globalSetup file and run vitest --ui the setup function is executed twice

Reproduction

https://stackblitz.com/edit/node-arkh2h?devtoolsheight=33&file=globalSetup.ts

run npm run test observe 'globalSetup' is logged twice

System Info

Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.2/bin/yarn
    npm: 8.3.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
  Browsers:
    Chrome: 97.0.4692.71
    Firefox: 96.0
  npmPackages:
    vitest: workspace:* => 0.2.7

Used Package Manager

pnpm

Validations

@dominikg
Copy link
Contributor Author

dominikg commented Feb 4, 2022

it looks like vite patches httpServer.listen https://github.com/vitejs/vite/blob/3311686bbcc12481495374c58cd1bc054d2429b8/packages/vite/src/node/server/index.ts#L579

to call buildStart, and vitest calls buildStart explicitly here https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/create.ts#L26 and then if --ui is set httpServer.listen is called by https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/create.ts#L29

i'm not really sure why vitest is calling buildStart manually, my gut feeling is that this should be handled by vite internally.

cc @antfu

@patak-dev
Copy link
Member

buildStart is needed before calling other hooks as some plugins are using this hook to initialize caches (the hook is also called when re-building in build watch mode so it is a good place to place this code instead of when constructing the plugin).

I think we should avoid the manual call to buildStart if --ui is enabled.

@antfu antfu closed this as completed in bae876d Feb 5, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants