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

Tests using different environments should always be isolated #3659

Closed
6 tasks done
AriPerkkio opened this issue Jun 25, 2023 · 1 comment · Fixed by #3715
Closed
6 tasks done

Tests using different environments should always be isolated #3659

AriPerkkio opened this issue Jun 25, 2023 · 1 comment · Fixed by #3715

Comments

@AriPerkkio
Copy link
Member

Describe the bug

When threads are enabled and there are multiple test environments used by the test cases, there should be no multiple test environments used in a single thread. Instead the test cases should be grouped by environment and run in separate threads.

It's already intended in code but it's not working:

// always run environments isolated between each other
for (const env of envs) {

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-ihs847?file=vite.config.ts

import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    singleThread: true,
    isolate: false,
  },
});
/**
 * @vitest-environment jsdom
 */

import { test, expect } from 'vitest';

test('Node globals not found', async () => {
  globalThis.__leaking_from_jsdom = 'leaking';
  expect(globalThis.__leaking_from_node).toBe(undefined);
});
/**
 * @vitest-environment node
 */

import { test, expect } from 'vitest';

test('jsdom globals not found', async () => {
  globalThis.__leaking_from_node = 'leaking';
  expect(globalThis.__leaking_from_jsdom).toBe(undefined);
});

System Info

Stackblitz

Used Package Manager

npm

Validations

@AriPerkkio AriPerkkio added the bug label Jun 25, 2023
@stackblitz
Copy link

stackblitz bot commented Jun 25, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

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

Successfully merging a pull request may close this issue.

1 participant