Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix: isolate workers between envs and workspaces
- Loading branch information
1 parent
8dd5ea5
commit ed4e042
Showing
12 changed files
with
160 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* @vitest-environment happy-dom | ||
*/ | ||
|
||
import { expect, test } from 'vitest' | ||
|
||
test('Leaking globals not found', async () => { | ||
(globalThis as any).__leaking_from_happy_dom = 'leaking' | ||
expect((globalThis as any).__leaking_from_node).toBe(undefined) | ||
expect((globalThis as any).__leaking_from_jsdom).toBe(undefined) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* @vitest-environment jsdom | ||
*/ | ||
|
||
import { expect, test } from 'vitest' | ||
|
||
test('Leaking globals not found', async () => { | ||
(globalThis as any).__leaking_from_jsdom = 'leaking' | ||
expect((globalThis as any).__leaking_from_node).toBe(undefined) | ||
expect((globalThis as any).__leaking_from_happy_dom).toBe(undefined) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* @vitest-environment node | ||
*/ | ||
|
||
import { expect, test } from 'vitest' | ||
|
||
test('Leaking globals not found', async () => { | ||
(globalThis as any).__leaking_from_node = 'leaking' | ||
expect((globalThis as any).__leaking_from_jsdom).toBe(undefined) | ||
expect((globalThis as any).__leaking_from_happy_dom).toBe(undefined) | ||
}) |
7 changes: 7 additions & 0 deletions
7
test/env-mixed/fixtures/project/test/workspace-project.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
test('Leaking globals not found', async () => { | ||
expect((globalThis as any).__leaking_from_workspace_project).toBe(undefined) | ||
|
||
;(globalThis as any).__leaking_from_workspace_project = 'leaking' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: {}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { resolve } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { defineWorkspace } from 'vitest/config' | ||
|
||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = resolve(__filename, '..') | ||
|
||
export default defineWorkspace([ | ||
{ | ||
test: { | ||
name: 'Project #1', | ||
root: resolve(__dirname, './project'), | ||
}, | ||
}, | ||
{ | ||
test: { | ||
name: 'Project #2', | ||
root: resolve(__dirname, './project'), | ||
}, | ||
}, | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@vitest/test-env-mixed", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest" | ||
}, | ||
"devDependencies": { | ||
"happy-dom": "latest", | ||
"vite": "latest", | ||
"vitest": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { type UserConfig, expect, test } from 'vitest' | ||
|
||
import { runVitest } from '../../test-utils' | ||
|
||
const configs: UserConfig[] = [ | ||
{ isolate: false, singleThread: true }, | ||
{ isolate: false, singleThread: false }, | ||
{ isolate: false, threads: true, minThreads: 1, maxThreads: 1 }, | ||
{ isolate: false, threads: false }, | ||
] | ||
|
||
test.each(configs)('should isolate environments when %s', async (config) => { | ||
const { stderr, stdout } = await runVitest({ | ||
root: './fixtures', | ||
...config, | ||
}) | ||
|
||
expect(stderr).toBe('') | ||
|
||
expect(stdout).toContain('✓ test/node.test.ts') | ||
expect(stdout).toContain('✓ test/jsdom.test.ts') | ||
expect(stdout).toContain('✓ test/happy-dom.test.ts') | ||
expect(stdout).toContain('✓ test/workspace-project.test.ts') | ||
expect(stdout).toContain('Test Files 8 passed (8)') | ||
expect(stdout).toContain('Tests 8 passed (8)') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ['./test/**/*'], | ||
testTimeout: process.env.CI ? 30_000 : 10_000, | ||
chaiConfig: { | ||
truncateThreshold: 0, | ||
}, | ||
}, | ||
}) |