Skip to content

Commit

Permalink
test: simplify coverage test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Feb 7, 2023
1 parent 570c639 commit 7342609
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 40 deletions.
2 changes: 1 addition & 1 deletion test/coverage-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@vitest/test-coverage",
"private": true,
"scripts": {
"test": "pnpm run test:c8 && pnpm run test:istanbul && pnpm run test:types",
"test": "pnpm test:c8 && pnpm test:istanbul && pnpm test:types",
"test:c8": "node ./testing.mjs --provider c8",
"test:istanbul": "node ./testing.mjs --provider istanbul",
"test:types": "vitest typecheck --run"
Expand Down
48 changes: 11 additions & 37 deletions test/coverage-test/testing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { startVitest } from 'vitest/node'
// Set this to true when intentionally updating the snapshots
const UPDATE_SNAPSHOTS = false

const provider = getArgument('--provider')
const provider = process.argv[1 + process.argv.indexOf('--provider')]

const configs = [
// Run test cases. Generates coverage report.
['test/', {
include: ['test/*.test.*'],
exclude: ['coverage-report-tests/**/*'],
coverage: { enabled: true },
}],

// Run tests for checking coverage report contents.
Expand All @@ -22,42 +23,15 @@ const configs = [
}],
]

runTests()
for (const threads of [true, false]) {
for (const [directory, config] of configs) {
await startVitest('test', [directory], {
...config,
update: UPDATE_SNAPSHOTS,
threads,
})

async function runTests() {
for (const threads of [true, false]) {
for (const [directory, config] of configs) {
await startVitest('test', [directory], {
run: true,
update: UPDATE_SNAPSHOTS,
...config,
threads,
coverage: {
include: ['src/**'],
provider,
...config.coverage,
},
})

if (process.exitCode)
process.exit()
}
if (process.exitCode)
process.exit()
}

process.exit(0)
}

function getArgument(name) {
const args = process.argv
const index = args.indexOf(name)

if (index === -1)
throw new Error(`Missing argument ${name}, received ${args}`)

const value = args[index + 1]

if (!value)
throw new Error(`Missing value of ${name}, received ${args}`)

return value
}
7 changes: 5 additions & 2 deletions test/coverage-test/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { resolve } from 'pathe'
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'

const provider = process.argv[1 + process.argv.indexOf('--provider')]

export default defineConfig({
plugins: [
vue(),
Expand All @@ -10,9 +12,10 @@ export default defineConfig({
MY_CONSTANT: '"my constant"',
},
test: {
reporters: 'verbose',
watch: false,
coverage: {
enabled: true,
provider: provider as any,
include: ['src/**'],
clean: true,
all: true,
reporter: ['html', 'text', 'lcov', 'json'],
Expand Down

0 comments on commit 7342609

Please sign in to comment.