vitest-dev / vitest

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

cannot run tests without opening broken dev server #4052

Closed vollmerr closed 1 year ago

vollmerr commented 1 year ago

Describe the bug

After upgrading from vitest ^0.33.0 to ^0.34.3 when running any tests the dev server now opens, and in that dev server that is opened it fails to load the files.

Have tried setting the vite config to have test.open to false but still opens (which shows as default of true in the typedef file but false in https://vitest.dev/config/#open)

Reproduction

https://codesandbox.io/p/sandbox/gallant-ptolemy-fjnjwr

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900HK
    Memory: 14.30 GB / 31.68 GB
  Binaries:
    Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.2134.0), Chromium (116.0.1938.62)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @vitejs/plugin-react: ^4.0.4 => 4.0.4
    @vitest/coverage-c8: ^0.33.0 => 0.33.0
    @vitest/ui: ^0.34.3 => 0.34.3
    vite: ^4.4.9 => 4.4.9
    vitest: ^0.34.3 => 0.34.3

Used Package Manager

yarn

Validations

donkeykong91 commented 1 year ago

I'm having the same problem.

leonheess commented 1 year ago

Same issue here!! We are blocked from upgrading because of this.

jultabary commented 1 year ago

Same here !

CookedApps commented 1 year ago

Same here after upgrading from 0.34.2 to 0.34.3. We noticed that our CI pipelines kept failing because vitest always tries to open the browser (even tho the CI env variable is set). It also opens the browser every time on my local machine, despite setting various options to disable it.

Dunqing commented 1 year ago

I'm wondering if this problem is limited to Windows. i'm using macos and it doesn't happen.

donkeykong91 commented 1 year ago

I'm using Windows; though, when I run this though a pipeline, the same error happens because it tries to open a browser during the pipeline run. We use RedHat Linux images.

fh-igor-serko commented 1 year ago

Chiming in that this impacts me locally on MacOS as well as CI running Linux. Downgrading to either 0.34.2 or 0.33.0 solved the problem.

Here's a portion of my vite.config.ts. If I comment out server.open then vitest will not open a browser window. Something tells me vitest shouldn't be reading the server portion of the config, should it?

    ... snip ...
    server: {
        proxy: {
            "^/api": {
                target: "http://localhost:8080",
                changeOrigin: false,
                secure: false,
            },
        },
        strictPort: true,
        open: "http://localhost:8080",  // <- if I comment it out, then a window isn't opened on 0.34.3
    },
    test: {
        globals: true,
        environment: "jsdom",
        coverage: {
            reporter: ["text", "html"],
            exclude: [
                "node_modules/",
            ],
        },
    },
    ... snip ...
vollyimnetz commented 1 year ago

@fh-igor-serko thank you for investigating:

so a quick-and-dirty-fix for the old behaviour is:

//in vite.config.js
...
server: {
    port: 8080,
    open: process.env.NODE_ENV === 'test' ? false : true,
    ...
},
test: {
  ...
}

or in your case

open: process.env.NODE_ENV === 'test' ? false : 'http://localhost:8080',
Dunqing commented 1 year ago

Thanks, guys, I was able to successfully reproduce the issue, and I'm currently working on a solution. I'll be submitting a PR to fix the issue soon