Skip to content

Commit

Permalink
test: failing test cases for vitest-dev#3659
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Jul 1, 2023
1 parent 893e90b commit 7d8413a
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/env-mixed/fixtures/test/happy-dom.test.ts
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)
})
11 changes: 11 additions & 0 deletions test/env-mixed/fixtures/test/jsdom.test.ts
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)
})
11 changes: 11 additions & 0 deletions test/env-mixed/fixtures/test/node.test.ts
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)
})
12 changes: 12 additions & 0 deletions test/env-mixed/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@vitest/test-run",
"private": true,
"scripts": {
"test": "vitest"
},
"devDependencies": {
"happy-dom": "latest",
"vite": "latest",
"vitest": "workspace:*"
}
}
26 changes: 26 additions & 0 deletions test/env-mixed/test/mixed-environments.test.ts
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 { exitCode, stderr, stdout } = await runVitest({
root: './fixtures',
...config,
})

expect(stderr).toBe('')
expect(exitCode).toBe(0)

expect(stdout).toContain('✓ test/node.test.ts > Leaking globals not found')
expect(stdout).toContain('✓ test/happy-dom.test.ts > Leaking globals not found')
expect(stdout).toContain('✓ test/jsdom.test.ts > Leaking globals not found')
expect(stdout).toContain('Test Files 3 passed (3)')
expect(stdout).toContain('Tests 3 passed (3)')
})
7 changes: 7 additions & 0 deletions test/env-mixed/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
include: ['./test/**/*'],
},
})

0 comments on commit 7d8413a

Please sign in to comment.