-
-
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 (#3226)
- Loading branch information
1 parent
8d4606e
commit efce3b4
Showing
7 changed files
with
57 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.
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
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. | ||
const { branches, functions } = fileCoverage.toSummary() | ||
|
||
expect(branches.total - branches.covered).toBe(1) | ||
expect(functions.total - functions.covered).toBe(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
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