-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(coverage): workspaces c8 source maps
- Loading branch information
1 parent
cbfd2c5
commit 8aacdaf
Showing
7 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
test/workspaces/coverage-report-tests/check-coverage.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { existsSync, readFileSync } from 'node:fs' | ||
import { normalize } from 'node:path' | ||
import { expect, test } from 'vitest' | ||
import libCoverage from 'istanbul-lib-coverage' | ||
import { resolve } from 'pathe' | ||
|
||
test('coverage exists', () => { | ||
expect(existsSync('./coverage')).toBe(true) | ||
expect(existsSync('./coverage/index.html')).toBe(true) | ||
}) | ||
|
||
test('file coverage summary matches', () => { | ||
const coverageJson = JSON.parse(readFileSync('./coverage/coverage-final.json', 'utf-8')) | ||
const coverageMap = libCoverage.createCoverageMap(coverageJson) | ||
const fileCoverage = coverageMap.fileCoverageFor(normalize(resolve('./src/math.ts'))) | ||
|
||
// There should be 1 uncovered branch and 1 uncovered function. See math.ts. | ||
expect(fileCoverage.toSummary()).toMatchInlineSnapshot(` | ||
{ | ||
"branches": { | ||
"covered": 3, | ||
"pct": 75, | ||
"skipped": 0, | ||
"total": 4, | ||
}, | ||
"functions": { | ||
"covered": 2, | ||
"pct": 66.66, | ||
"skipped": 0, | ||
"total": 3, | ||
}, | ||
"lines": { | ||
"covered": 7, | ||
"pct": 50, | ||
"skipped": 0, | ||
"total": 14, | ||
}, | ||
"statements": { | ||
"covered": 7, | ||
"pct": 50, | ||
"skipped": 0, | ||
"total": 14, | ||
}, | ||
} | ||
`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ['./check-coverage.test.ts'], | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
/* eslint-disable unused-imports/no-unused-vars */ | ||
export function sum(a: number, b: number) { | ||
if (a === 3 && b === 4) { | ||
// This should be uncovered | ||
return 7 | ||
} | ||
|
||
return a + b | ||
} | ||
|
||
function uncoveredFunction() { | ||
// This should be uncovered | ||
return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters