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

Invalid config from browser creator #7403

Open
6 tasks done
nickserv opened this issue Feb 1, 2025 · 5 comments
Open
6 tasks done

Invalid config from browser creator #7403

nickserv opened this issue Feb 1, 2025 · 5 comments
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome

Comments

@nickserv
Copy link
Contributor

nickserv commented Feb 1, 2025

Describe the bug

I was confused when trying to use vitest init browser because it writes a nonexistent test.browser.configs config option, producing an invalid config. It seems like this should be test.browser.instances, though the documentation and TypeScript types are correct.

Reproduction

Run vitest init browser with any options, then view the generated config.

Config patch

--- vitest.bad.config.js
+++ vitest.bad.config.js
@@ -1,9 +1,9 @@
 import { defineConfig } from "vitest/config";
 
 export default defineConfig({
        test: {
                browser: {
-                       configs: [],
+                       instances: [],
                },
        },
 });

Engineering note

There should probably be an end-to-end, smoke, or type test that asserts generated configs are valid.

System Info

System:
    OS: macOS 12.7.6
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    Memory: 190.06 MB / 8.00 GB
    Shell: 3.7.1 - /usr/local/bin/fish
  Binaries:
    Node: 23.6.0 - /usr/local/bin/node
    npm: 11.1.0 - /usr/local/bin/npm
    pnpm: 9.11.0 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 132.0.6834.160
    Safari: 17.6
  npmPackages:
    @vitest/browser: ^3.0.4 => 3.0.4 
    playwright: ^1.50.1 => 1.50.1

Used Package Manager

npm

Validations

@AriPerkkio
Copy link
Member

const workspaceContent = [
`import { defineWorkspace } from 'vitest/config'`,
'',
'export default defineWorkspace([',
' // If you want to keep running your existing tests in Node.js, uncomment the next line.',
` // '${relativeRoot}',`,
` {`,
` extends: '${relativeRoot}',`,
` test: {`,
` browser: {`,
` enabled: true,`,
` provider: '${options.provider}',`,
options.provider !== 'preview' && ` // ${getProviderDocsLink(options.provider)}`,
` configs: [`,
...options.browsers.map(browser => ` { browser: '${browser}' },`),
` ],`,
` },`,
` },`,
` },`,
`])`,
'',
].filter(c => typeof c === 'string').join('\n')

const configContent = [
`import { defineConfig } from 'vitest/config'`,
options.frameworkPlugin ? frameworkImport : null,
``,
'export default defineConfig({',
options.frameworkPlugin ? ` plugins: [${options.framework}()],` : null,
` test: {`,
` browser: {`,
` enabled: true,`,
` provider: '${options.provider}',`,
options.provider !== 'preview' && ` // ${getProviderDocsLink(options.provider)}`,
` configs: [`,
...options.browsers.map(browser => ` { browser: '${browser}' },`),
` ],`,
` },`,
` },`,
`})`,
'',
].filter(t => typeof t === 'string').join('\n')

@AriPerkkio AriPerkkio added pr welcome feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Feb 1, 2025
@nickserv
Copy link
Contributor Author

nickserv commented Feb 1, 2025

Thanks, I read the source but forgot to include links. Is all that's needed a replacement of configs with instances here?

@AriPerkkio
Copy link
Member

Yes, that should be all. But if you want to add the tests mentioned in Engineering note in your message, feel free to do so.

@nickserv
Copy link
Contributor Author

nickserv commented Feb 2, 2025

I can't promise I'll have time to implement tests, but if you (or other maintainers) have any preferences among the types of tests I listed, I'm interested. FWIW I know the Vite community tends to prefer E2E tests, and that would probably be the most robust option.

@AriPerkkio
Copy link
Member

We prefer e2e-tests too. In these test cases we are running Vitest either via CLI bin or using the Vitest's Node API. For this bug we should add test case to test/cli/test/, that is somewhat similar as:

test('run mode does not get stuck when TTY', async () => {
const { vitest } = await runVitestCli('--root', 'fixtures/tty')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome
Projects
None yet
Development

No branches or pull requests

2 participants