Skip to content

Commit

Permalink
test: pool variations
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Dec 9, 2024
1 parent 87c9a56 commit 3bb8f66
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 30 deletions.
75 changes: 45 additions & 30 deletions test/coverage-test/test/isolation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,56 @@ import type { WorkspaceSpec } from 'vitest/node'
import { expect, test } from 'vitest'
import { readCoverageMap, runVitest } from '../utils'

const pools = ['forks']

if (!process.env.COVERAGE_BROWSER) {
pools.push('threads')

const [major] = process.version.slice(1).split('.').map(num => Number(num))

if (major < 22) {
pools.push('vmForks', 'vmThreads')
}
}

for (const isolate of [true, false]) {
test(`{ isolate: ${isolate} }`, async () => {
await runVitest({
include: ['fixtures/test/isolation-*'],
setupFiles: ['fixtures/setup.isolation.ts'],
sequence: { sequencer: Sorter },

isolate,
fileParallelism: false,

coverage: {
all: false,
reporter: ['json', 'html'],
},

// @ts-expect-error -- merged in runVitest
browser: {
for (const pool of pools) {
test(`{ isolate: ${isolate}, pool: "${pool}" }`, async () => {
await runVitest({
include: ['fixtures/test/isolation-*'],
setupFiles: ['fixtures/setup.isolation.ts'],
sequence: { sequencer: Sorter },

pool,
isolate,
},
})
fileParallelism: false,

coverage: {
all: false,
reporter: ['json', 'html'],
},

const coverageMap = await readCoverageMap()
// @ts-expect-error -- merged in runVitest
browser: {
isolate,
},
})

const branches = coverageMap.fileCoverageFor('<process-cwd>/fixtures/src/branch.ts')
expect(branches.toSummary().lines.pct).toBe(100)
expect(branches.toSummary().statements.pct).toBe(100)
expect(branches.toSummary().functions.pct).toBe(100)
expect(branches.toSummary().branches.pct).toBe(100)
const coverageMap = await readCoverageMap()

const math = coverageMap.fileCoverageFor('<process-cwd>/fixtures/src/math.ts')
expect(math.toSummary().lines.pct).toBe(100)
expect(math.toSummary().statements.pct).toBe(100)
expect(math.toSummary().functions.pct).toBe(100)
expect(math.toSummary().branches.pct).toBe(100)
})
const branches = coverageMap.fileCoverageFor('<process-cwd>/fixtures/src/branch.ts')
expect(branches.toSummary().lines.pct).toBe(100)
expect(branches.toSummary().statements.pct).toBe(100)
expect(branches.toSummary().functions.pct).toBe(100)
expect(branches.toSummary().branches.pct).toBe(100)

const math = coverageMap.fileCoverageFor('<process-cwd>/fixtures/src/math.ts')
expect(math.toSummary().lines.pct).toBe(100)
expect(math.toSummary().statements.pct).toBe(100)
expect(math.toSummary().functions.pct).toBe(100)
expect(math.toSummary().branches.pct).toBe(100)
})
}
}

class Sorter {
Expand Down
3 changes: 3 additions & 0 deletions test/coverage-test/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
server: {
watch: null,
},
test: {
reporters: 'verbose',
isolate: false,
Expand Down

0 comments on commit 3bb8f66

Please sign in to comment.