Skip to content

Commit

Permalink
chore: coverage remove restart vitest (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho committed Mar 22, 2022
1 parent c9b49b7 commit 10e072b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
11 changes: 8 additions & 3 deletions packages/vitest/src/node/cli-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ export async function startVitest(cliFilters: string[], options: CliOptions, vit

if (!process.env.NODE_V8_COVERAGE) {
process.env.NODE_V8_COVERAGE = ctx.config.coverage.tempDirectory
const { exitCode } = await execa(process.argv0, process.argv.slice(1), { stdio: 'inherit', reject: false })
process.exitCode = exitCode
return false
// thread enable test will exec in thread
// so don't need to restarting Vitest
if (!ctx.config.threads) {
await ctx.server.close()
const { exitCode } = await execa(process.argv0, process.argv.slice(1), { stdio: 'inherit', reject: false })
process.exitCode = exitCode
return false
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/coverage-test/coverage-test/coverage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import fs from 'fs'
import { resolve } from 'pathe'
import { expect, test } from 'vitest'

test('coverage', async() => {
const coveragePath = resolve('./coverage/tmp/')
const stat = fs.statSync(coveragePath)
expect(stat.isDirectory()).toBe(true)
const files = fs.readdirSync(coveragePath)
expect(files.length > 0).toBe(true)
})
8 changes: 6 additions & 2 deletions test/coverage-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
"name": "@vitest/test-coverage",
"private": true,
"scripts": {
"test": "vitest",
"coverage": "vitest run --coverage"
"test": "npm run test:thread && npm run test:nothread",
"coverage": "vitest run --coverage",
"coverage:thread": "cross-env THREAD=true vitest run --coverage",
"coverage-test": "vitest -c vitest.config-coverage.ts run",
"test:thread": "npm run coverage:thread && npm run coverage-test",
"test:nothread": "npm run coverage && npm run coverage-test"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.2.4",
Expand Down
9 changes: 9 additions & 0 deletions test/coverage-test/vitest.config-coverage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'vite'

export default defineConfig({
test: {
include: [
'./coverage-test/*.test.ts',
],
},
})
7 changes: 7 additions & 0 deletions test/coverage-test/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ export default defineConfig({
MY_CONSTANT: '"my constant"',
},
test: {
threads: !!process.env.THREAD,
include: [
'test/*.test.ts',
],
exclude: [
'coverage-test/*.test.ts',
],
},
})

0 comments on commit 10e072b

Please sign in to comment.