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

cannot run tests without opening broken dev server #4052

Closed
6 tasks done
vollmerr opened this issue Aug 30, 2023 · 9 comments · Fixed by #4095
Closed
6 tasks done

cannot run tests without opening broken dev server #4052

vollmerr opened this issue Aug 30, 2023 · 9 comments · Fixed by #4095

Comments

@vollmerr
Copy link

vollmerr commented Aug 30, 2023

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
Copy link

I'm having the same problem.

@leonheess
Copy link

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

@jultabary
Copy link

Same here !

@CookedApps
Copy link

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
Copy link
Member

Dunqing commented Sep 7, 2023

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

@donkeykong91
Copy link

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
Copy link

fh-igor-serko commented Sep 7, 2023

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
Copy link

vollyimnetz commented Sep 7, 2023

@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
Copy link
Member

Dunqing commented Sep 7, 2023

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
8 participants