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

Vitest VSCode v1.10.2 does not respect environment set in vite config #574

Closed
4 tasks done
pdanpdan opened this issue Jan 21, 2025 · 1 comment
Closed
4 tasks done

Comments

@pdanpdan
Copy link

Describe the bug

Vitest plugin tries to execute with node (default) environment for non 'src/**/*.node.test.ts' test files.

If the environment is specified in the test file with // @vitest-environment happy-dom then all works as expected.

Vitest CLI runs as expected.

Reproduction

The project uses pnpm on node v20, linux, latest VSCode insiders, vitest 3.0.2.

Repo: https://github.com/pdanpdan/smartvui

/vitest.workspace.ts

import { defineWorkspace } from 'vitest/config';

export default defineWorkspace([
  './lib/vite.esm.config.ts',
]);

/lib/vite.esm.config.ts

import type { UserConfig } from 'vite';

export default defineConfig({
  test: {
    workspace: [
      {
        extends: true,
        test: {
          include: [ 'src/**/*.test.ts' ],
          exclude: [ 'src/**/*.node.test.ts' ],
          environment: 'happy-dom',
        },
      },

      {
        extends: true,
        test: {
          include: [ 'src/**/*.node.test.ts' ],
          environment: 'node',
        },
      },
    ],
    reporters: [ 'default', 'html' ],
    outputFile: {
      json: './coverage/json/index.json',
      html: './coverage/html/index.html',
    },
    coverage: {
      enabled: true,
      reporter: [ 'html', 'text' ],
      reportsDirectory: './coverage/',

      include: [ 'src/**/*.{ts,vue}' ],
      exclude: [ 'src/test_utils/**', 'src/**/*.test.ts', 'src/**/*.d.ts' ],
    },
  },
} as UserConfig);

Output

[INFO 10:22:03 AM] [v1.10.2] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 10:22:03 AM] [API] Running Vitest v3.0.2 (smartvui/vitest.workspace.ts) with "node  /home/pdan/.vscode-insiders/extensions/vitest.explorer-1.10.2/dist/worker.js"
[INFO 10:22:03 AM] [Worker] �[?25l
[INFO 10:22:05 AM] [API] Watching /home/pdan/Work/PDan/smartvui/vitest.workspace.ts
[INFO 10:22:05 AM] [VSCODE] Watching smartvui with pattern **/*
[INFO 10:22:16 AM] [API] Collecting tests: lib/src/composables/usePlatform/usePlatform.test.ts [@pdanpdan/smartvui]
[10:22:16 AM] Not starting the runner because tests are being collected for lib/src/composables/usePlatform/usePlatform.test.ts
[10:22:17 AM] There is no test run for "usePlatform.test.ts [@pdanpdan/smartvui]"
[10:22:17 AM] No test run to finish for lib/src/composables/usePlatform/usePlatform.test.ts
[10:22:17 AM] [VSCODE] Ignoring file: node_modules/.vite/results.json
[10:22:26 AM] [VSCODE] Ignoring file: node_modules/.vue-global-types/vue_3.3_false.d.ts
[10:22:26 AM] [VSCODE] Ignoring file: lib/node_modules/.vue-global-types/vue_3.5_false.d.ts
[10:22:26 AM] [VSCODE] Ignoring file: node_modules/.vue-global-types/vue_3.3_false.d.ts
[10:22:31 AM] Initiating deferred test run
[INFO 10:22:31 AM] Running 1 file(s) with name pattern: ^\s?usePlatform \[browser\] should keep SSR values on mount$
[10:22:31 AM] The runner is starting because tests lib/src/composables/usePlatform/usePlatform.test.ts were started due to a file change
[10:22:31 AM] Enqueuing "should keep SSR values on mount"
[10:22:31 AM] No task result for "usePlatform.test.ts [@pdanpdan/smartvui]", ignoring
[10:22:31 AM] No task result for "usePlatform [browser]", ignoring
[10:22:31 AM] Enqueuing "should keep SSR values on mount" because it was just collected
[10:22:31 AM] Ignore "should add listener on mount" during collection
[10:22:31 AM] Ignore "should use browser values after mount" during collection
[10:22:31 AM] Ignore "should change values when mediaQuery changes" during collection
[10:22:31 AM] Ignore "should change values based on userAgent" during collection
[10:22:31 AM] Ignore "should remove listener on unmount" during collection
[10:22:31 AM] Ignore "should not warn if installed" during collection
[10:22:31 AM] Ignore "should warn if not installed" during collection
[10:22:31 AM] No errors found for "usePlatform.test.ts [@pdanpdan/smartvui]"
[10:22:31 AM] No errors found for "usePlatform [browser]"
[10:22:31 AM] Marking "should keep SSR values on mount" as failed with 1 errors
[10:22:31 AM] Ending test run lib/src/composables/usePlatform/usePlatform.test.ts
[10:22:31 AM] [VSCODE] Ignoring file: node_modules/.vite/results.json
[10:23:45 AM] [VSCODE] Ignoring file: .git/FETCH_HEAD
[10:23:46 AM] [VSCODE] Ignoring file: lib/src/composables/usePlatform/usePlatform.test.ts.git
[10:23:46 AM] [VSCODE] Ignoring file: .git/FETCH_HEAD
[10:23:47 AM] [VSCODE] Ignoring file: lib/src/composables/usePlatform/usePlatform.test.ts.git
[INFO 10:23:50 AM] [API] Collecting tests: lib/src/composables/usePlatform/usePlatform.node.test.ts [@pdanpdan/smartvui]
[10:23:50 AM] Not starting the runner because tests are being collected for lib/src/composables/usePlatform/usePlatform.node.test.ts
[10:23:50 AM] There is no test run for "usePlatform.node.test.ts [@pdanpdan/smartvui]"
[10:23:50 AM] No test run to finish for lib/src/composables/usePlatform/usePlatform.node.test.ts
[10:23:51 AM] [VSCODE] Ignoring file: node_modules/.vite/results.json
[INFO 10:24:14 AM] [API] Collecting tests: lib/src/utils/utils.test.ts [@pdanpdan/smartvui]
[10:24:14 AM] Not starting the runner because tests are being collected for lib/src/utils/utils.test.ts
[10:24:14 AM] There is no test run for "utils.test.ts [@pdanpdan/smartvui]"
[10:24:14 AM] No test run to finish for lib/src/utils/utils.test.ts
[10:24:14 AM] [VSCODE] Ignoring file: node_modules/.vite/results.json
[INFO 10:26:38 AM] [API] Collecting tests: lib/src/composables/useColorTheme/useColorTheme.node.test.ts [@pdanpdan/smartvui]
[10:26:38 AM] Not starting the runner because tests are being collected for lib/src/composables/useColorTheme/useColorTheme.node.test.ts
[10:26:39 AM] There is no test run for "useColorTheme.node.test.ts [@pdanpdan/smartvui]"
[10:26:39 AM] No test run to finish for lib/src/composables/useColorTheme/useColorTheme.node.test.ts
[10:26:39 AM] [VSCODE] Ignoring file: node_modules/.vite/results.json
[10:26:47 AM] [VSCODE] Ignoring file: .git/FETCH_HEAD
[10:26:48 AM] [VSCODE] Ignoring file: lib/src/composables/usePlatform/usePlatform.test.ts.git
[10:26:48 AM] [VSCODE] Ignoring file: lib/src/composables/usePlatform/usePlatform.node.test.ts.git
[10:26:48 AM] [VSCODE] Ignoring file: lib/src/utils/utils.test.ts.git
[10:26:48 AM] [VSCODE] Ignoring file: lib/vite.esm.config.ts.git
[10:26:48 AM] [VSCODE] Ignoring file: lib/src/composables/useColorTheme/useColorTheme.node.test.ts.git
[10:26:48 AM] [VSCODE] Ignoring file: .git/FETCH_HEAD
[10:26:49 AM] [VSCODE] Ignoring file: lib/src/composables/usePlatform/usePlatform.test.ts.git
[10:26:49 AM] [VSCODE] Ignoring file: lib/src/composables/usePlatform/usePlatform.node.test.ts.git
[10:26:49 AM] [VSCODE] Ignoring file: lib/src/utils/utils.test.ts.git
[10:26:49 AM] [VSCODE] Ignoring file: lib/vite.esm.config.ts.git
[10:26:49 AM] [VSCODE] Ignoring file: lib/src/composables/useColorTheme/useColorTheme.node.test.ts.git
[INFO 10:27:30 AM] [API] Collecting tests: lib/src/composables/useScreen/useScreen.node.test.ts [@pdanpdan/smartvui]
[10:27:30 AM] Not starting the runner because tests are being collected for lib/src/composables/useScreen/useScreen.node.test.ts
[10:27:31 AM] There is no test run for "useScreen.node.test.ts [@pdanpdan/smartvui]"
[10:27:31 AM] No test run to finish for lib/src/composables/useScreen/useScreen.node.test.ts
[10:27:31 AM] [VSCODE] Ignoring file: node_modules/.vite/results.json
[INFO 10:27:35 AM] [API] Collecting tests: lib/src/composables/useScreen/useScreen.test.ts [@pdanpdan/smartvui]
[10:27:35 AM] Not starting the runner because tests are being collected for lib/src/composables/useScreen/useScreen.test.ts
[10:27:36 AM] There is no test run for "useScreen.test.ts [@pdanpdan/smartvui]"
[10:27:36 AM] No test run to finish for lib/src/composables/useScreen/useScreen.test.ts
[10:27:36 AM] [VSCODE] Ignoring file: node_modules/.vite/results.json
[INFO 10:28:13 AM] [API] Collecting tests: lib/src/composables/usePrefersDark/usePrefersDark.node.test.ts [@pdanpdan/smartvui]
[10:28:13 AM] Not starting the runner because tests are being collected for lib/src/composables/usePrefersDark/usePrefersDark.node.test.ts
[10:28:13 AM] There is no test run for "usePrefersDark.node.test.ts [@pdanpdan/smartvui]"
[10:28:13 AM] No test run to finish for lib/src/composables/usePrefersDark/usePrefersDark.node.test.ts
[10:28:13 AM] [VSCODE] Ignoring file: node_modules/.vite/results.json
[INFO 10:28:16 AM] [API] Collecting tests: lib/src/composables/useRender/useRender.node.test.ts [@pdanpdan/smartvui]
[10:28:16 AM] Not starting the runner because tests are being collected for lib/src/composables/useRender/useRender.node.test.ts
[10:28:17 AM] There is no test run for "useRender.node.test.ts [@pdanpdan/smartvui]"
[10:28:17 AM] No test run to finish for lib/src/composables/useRender/useRender.node.test.ts
[10:28:17 AM] [VSCODE] Ignoring file: node_modules/.vite/results.json
[INFO 10:28:19 AM] [API] Collecting tests: lib/src/composables/useRender/useRender.test.ts [@pdanpdan/smartvui]
[10:28:19 AM] Not starting the runner because tests are being collected for lib/src/composables/useRender/useRender.test.ts
[Error 10:28:20 AM] Error in /home/pdan/Work/PDan/smartvui/lib/src/composables/useRender/useRender.test.ts ReferenceError: document is not defined
    at /home/pdan/Work/PDan/smartvui/lib/src/composables/useRender/useRender.test.ts:12:36
    at file:///home/pdan/Work/PDan/smartvui/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:547:43
    at runWithSuite (file:///home/pdan/Work/PDan/smartvui/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:31:9)
    at Object.collect (file:///home/pdan/Work/PDan/smartvui/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:547:13)
    at Object.collect (file:///home/pdan/Work/PDan/smartvui/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:551:57)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at collectTests (file:///home/pdan/Work/PDan/smartvui/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:910:28)
    at startTests (file:///home/pdan/Work/PDan/smartvui/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/index.js:1363:17)
    at file:///home/pdan/Work/PDan/smartvui/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected]_lightningcss@1._trnudnvldpj6bpfboutyykjhte/node_modules/vitest/dist/chunks/runBaseTests.Ba8jtu6O.js:129:11
    at withEnv (file:///home/pdan/Work/PDan/smartvui/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected][email protected]_lightningcss@1._trnudnvldpj6bpfboutyykjhte/node_modules/vitest/dist/chunks/runBaseTests.Ba8jtu6O.js:92:5)
[10:28:20 AM] There is no test run for "useRender.test.ts [@pdanpdan/smartvui]"
[10:28:20 AM] No test run to finish for lib/src/composables/useRender/useRender.test.ts

Extension Version

1.10.2

Vitest Version

3.0.2

Validations

@pdanpdan pdanpdan changed the title Vitest VSCode v1.10.2 does not respect environment settings for tests Vitest VSCode v1.10.2 does not respect environment set in vite config Jan 21, 2025
@sheremet-va
Copy link
Member

This is the same as vitest-dev/vitest#7325

The extension runs the root workspace, Vitest doesn't support nested workspaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants