Skip to content

Commit

Permalink
test: istanbul coverage provider
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Aug 4, 2022
1 parent 7a48fa8 commit 87987d5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import { resolve } from 'pathe'
import { expect, test } from 'vitest'

test('coverage', async () => {
test('coverage c8', async () => {
const coveragePath = resolve('./coverage/tmp/')
const stat = fs.statSync(coveragePath)
expect(stat.isDirectory()).toBe(true)
Expand Down
24 changes: 24 additions & 0 deletions test/coverage-test/coverage-test/coverage.istanbul.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fs from 'fs'
import { resolve } from 'pathe'
import { expect, test } from 'vitest'

test('istanbul html report', async () => {
const coveragePath = resolve('./coverage')
const files = fs.readdirSync(coveragePath)

expect(files).toContain('index.html')
expect(files).toContain('index.ts.html')
expect(files).toContain('Hello.vue.html')
})

test('istanbul lcov report', async () => {
const coveragePath = resolve('./coverage')
const files = fs.readdirSync(coveragePath)

expect(files).toContain('lcov.info')

const lcovReport = resolve('./coverage/lcov-report')
const lcovReportFiles = fs.readdirSync(lcovReport)

expect(lcovReportFiles).toContain('index.html')
})
19 changes: 13 additions & 6 deletions test/coverage-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
"name": "@vitest/test-coverage",
"private": true,
"scripts": {
"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"
"test": "npm run test:c8 && npm run test:istanbul",
"test:c8": "npm run test:thread:c8 && npm run test:nothread:c8",
"coverage:c8": "vitest run --coverage.provider c8",
"coverage:thread:c8": "cross-env THREAD=true vitest run --coverage.provider c8",
"coverage-test:c8": "vitest -c vitest.config-c8-coverage.ts run",
"test:thread:c8": "npm run coverage:thread:c8 && npm run coverage-test:c8",
"test:nothread:c8": "npm run coverage:c8 && npm run coverage-test:c8",
"test:istanbul": "npm run test:thread:istanbul && npm run test:nothread:istanbul",
"coverage:istanbul": "vitest run --coverage.provider istanbul",
"coverage:thread:istanbul": "cross-env THREAD=true vitest run --coverage.provider istanbul",
"coverage-test:istanbul": "vitest -c vitest.config-istanbul-coverage.ts run",
"test:thread:istanbul": "npm run coverage:thread:istanbul && npm run coverage-test:istanbul",
"test:nothread:istanbul": "npm run coverage:istanbul && npm run coverage-test:istanbul"
},
"devDependencies": {
"@vitejs/plugin-vue": "^3.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from 'vite'
export default defineConfig({
test: {
include: [
'./coverage-test/*.test.ts',
'./coverage-test/*.c8.test.ts',
],
},
})
9 changes: 9 additions & 0 deletions test/coverage-test/vitest.config-istanbul-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/*.istanbul.test.ts',
],
},
})
5 changes: 5 additions & 0 deletions test/coverage-test/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ export default defineConfig({
exclude: [
'coverage-test/*.test.ts',
],
coverage: {
enabled: true,
clean: true,
reporter: ['html', 'text', 'lcov'],
},
},
})

0 comments on commit 87987d5

Please sign in to comment.