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

fix: move Vitest.setServer to post configureServer hook to enable import analysis for workspace config loading #6584

Merged
merged 5 commits into from
Oct 1, 2024

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Sep 27, 2024

Description

As @sheremet-va suggested in #6519 (comment), this moves two configureServer hooks to order: "post". Reviewing with "Hide whitespace" is recommended.

This technically works, but I have an uneasy feeling that this is fragile. Alternatively I'm thinking we can load vitest.workspace.ts using a fresh vite server instance similar to how astro loads config https://github.com/withastro/astro/blob/2594eb088d53a98181ac820243bcb1a765856ecf/packages/astro/src/core/config/vite-load.ts#L55-L65. This would ensure a well-determined (though restrictive) behavior of config loading.

That said, simply moving to order: "post" might good enough, so I think we can try this first.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Sep 27, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2dafae0
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/66f64c3ae4c1a800087e5534
😎 Deploy Preview https://deploy-preview-6584--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hi-ogawa hi-ogawa marked this pull request as ready for review September 27, 2024 06:55
@hi-ogawa
Copy link
Contributor Author

/ecosystem-ci run

@vitest-ecosystem-ci
Copy link

vitest-ecosystem-ci bot commented Sep 27, 2024

📝 Ran ecosystem CI: Open

suite result
aria-live-capture ✅ success
nuxt ❌ failure
nuxt-test-utils ✅ success
elk ✅ success
effect ✅ success
zustand ✅ success
vue ✅ success
vite ✅ success
vitest-vscode ❌ failure
vitest-sonar-reporter ✅ success
vitest-github-actions-reporter ✅ success
vitest-browser-simple ✅ success
vitest-browser-examples ✅ success
vitest-coverage-large ✅ success
vitest-reporters-large ✅ success
vitest-benchmark-large ✅ success

Comment on lines +236 to +239
configureServer: {
// runs after vite:import-analysis as it relies on `server` instance on Vite 5
order: 'post',
async handler(server) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I also tried moving it to "post middleware" hook like below, but it turns out Vite doesn't await returned promise so it didn't work https://github.com/vitejs/vite/blob/95020ab49e12d143262859e095025cf02423c1d9/packages/vite/src/node/server/index.ts#L881-L884

{
  configureServer(server) {
    return async () => {
      await ctx.setServer(options, server, userConfig)
      ...
    }
  }
}

@sheremet-va sheremet-va merged commit e7f3521 into vitest-dev:main Oct 1, 2024
14 of 16 checks passed
@hi-ogawa hi-ogawa deleted the fix-vitest-set-server-post branch October 2, 2024 00:20
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Oct 2, 2024
##### [v2.1.2](https://github.com/vitest-dev/vitest/releases/tag/v2.1.2)

#####    🐞 Bug Fixes

-   Move `Vitest.setServer` to post `configureServer` hook to enable import analysis for workspace config loading  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6584 [<samp>(e7f35)</samp>](vitest-dev/vitest@e7f35214)
-   **benchmark**:
    -   Clear `BenchmarkResult.samples` array to reduce memory usage  -  by [@hi-ogawa](https://github.com/hi-ogawa) and [@AriPerkkio](https://github.com/AriPerkkio) in vitest-dev/vitest#6541 [<samp>(a6407)</samp>](vitest-dev/vitest@a6407afc)
-   **browser**:
    -   Fix dynamic import inside worker  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6569 [<samp>(ea2d4)</samp>](vitest-dev/vitest@ea2d429b)
    -   Fix browser mock factory event race condition  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6530 [<samp>(f131f)</samp>](vitest-dev/vitest@f131f93b)
    -   Serve ui assets as static  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6564 [<samp>(adcda)</samp>](vitest-dev/vitest@adcdaee8)
    -   Update solidjs testing library lib  -  by [@CamilleTeruel](https://github.com/CamilleTeruel) in vitest-dev/vitest#6548 [<samp>(91442)</samp>](vitest-dev/vitest@91442dfc)
    -   Use `data:` protocol on preview provider file upload  -  by [@userquin](https://github.com/userquin) in vitest-dev/vitest#6501 [<samp>(e9821)</samp>](vitest-dev/vitest@e9821f70)
    -   Fix base for client script  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6510 [<samp>(f9528)</samp>](vitest-dev/vitest@f952874e)
    -   Throw an error if "@vitest/browser/context" is imported outside of the browser mode  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6570 [<samp>(383f1)</samp>](vitest-dev/vitest@383f1791)
-   **coverage**:
    -   Remove empty coverage folder on test failure too  -  by [@AriPerkkio](https://github.com/AriPerkkio) in vitest-dev/vitest#6547 [<samp>(1371c)</samp>](vitest-dev/vitest@1371ca6a)
    -   Include `*.astro` by default  -  by [@AriPerkkio](https://github.com/AriPerkkio) in vitest-dev/vitest#6565 [<samp>(f8ff7)</samp>](vitest-dev/vitest@f8ff76a9)
    -   `cleanOnRerun: false` to invalidate previous results  -  by [@AriPerkkio](https://github.com/AriPerkkio) in vitest-dev/vitest#6592 [<samp>(88bde)</samp>](vitest-dev/vitest@88bde99c)
-   **expect**:
    -   Fix `toBeDefined` with `expect.poll`  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6562 [<samp>(f7da6)</samp>](vitest-dev/vitest@f7da6199)
-   **runner**:
    -   Mark tests as skipped when `beforeAll` failed  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6524 [<samp>(fb797)</samp>](vitest-dev/vitest@fb79792d)
    -   Support fixture parsing of lowered async syntax  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6531 [<samp>(b553c)</samp>](vitest-dev/vitest@b553c7d6)
    -   Fix fixture parsing of lowered async syntax for non arrow functions  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6575 [<samp>(3de00)</samp>](vitest-dev/vitest@3de00ab6)
    -   Guard test hook callback  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6604 [<samp>(14971)</samp>](vitest-dev/vitest@1497134e)
    -   Run `onTestFinished` and `onTestFailed` during `retry` and `repeats`  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6609 [<samp>(c5e29)</samp>](vitest-dev/vitest@c5e29098)
-   **ui**:
    -   List tests on ui when `--standalone`  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6577 [<samp>(d0bf8)</samp>](vitest-dev/vitest@d0bf89d3)
-   **vite-node**:
    -   Fix esm false-detection inside comment  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6506 [<samp>(91f85)</samp>](vitest-dev/vitest@91f85997)
-   **vitest**:
    -   Install dependencies with the same version when prompted  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6611 [<samp>(ed8b7)</samp>](vitest-dev/vitest@ed8b7c08)
    -   Make env.SSR consistent between different pools  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6616 [<samp>(8a8d3)</samp>](vitest-dev/vitest@8a8d3f03)
    -   Don't start a websocket server if api is disabled  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6617 [<samp>(82140)</samp>](vitest-dev/vitest@821400b8)
-   **workspace**:
    -   Fix glob pattern detection  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6502 [<samp>(7727c)</samp>](vitest-dev/vitest@7727ca87)
    -   Ignore DS_Store by default  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6571 [<samp>(d2a86)</samp>](vitest-dev/vitest@d2a86ff5)

#####     [View changes on GitHub](vitest-dev/vitest@v2.1.1...v2.1.2)
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

Successfully merging this pull request may close these issues.

import statements within vitest.workspace can't import .ts files using the .js extension
2 participants