Skip to content

Commit

Permalink
fix(coverage): esbuild to preserve legal comments for ignore hints
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Dec 12, 2022
1 parent affb9ea commit fef8aa4
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/vitest/src/node/plugins/index.ts
Expand Up @@ -92,6 +92,9 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
const config: ViteConfig = {
esbuild: {
sourcemap: 'external',

// Enables using ignore hint for coverage providers with @preserve keyword
legalComments: 'inline',
},
resolve: {
// by default Vite resolves `module` field, which not always a native ESM module
Expand Down
Expand Up @@ -2272,6 +2272,8 @@ exports[`c8 json report 1`] = `
"f": {
"0": 1,
"1": 1,
"10": 0,
"11": 0,
"2": 2,
"3": 2,
"4": 0,
Expand Down Expand Up @@ -2330,6 +2332,54 @@ exports[`c8 json report 1`] = `
},
"name": "get",
},
"10": {
"decl": {
"end": {
"column": 1,
"line": 29,
},
"start": {
"column": 7,
"line": 27,
},
},
"line": 27,
"loc": {
"end": {
"column": 1,
"line": 29,
},
"start": {
"column": 7,
"line": 27,
},
},
"name": "unusedFunction",
},
"11": {
"decl": {
"end": {
"column": 1,
"line": 29,
},
"start": {
"column": 0,
"line": 29,
},
},
"line": 29,
"loc": {
"end": {
"column": 1,
"line": 29,
},
"start": {
"column": 0,
"line": 29,
},
},
"name": "get",
},
"2": {
"decl": {
"end": {
Expand Down Expand Up @@ -2542,6 +2592,11 @@ exports[`c8 json report 1`] = `
"21": 0,
"22": 0,
"23": 0,
"24": 1,
"25": 1,
"26": 1,
"27": 0,
"28": 0,
"3": 1,
"4": 1,
"5": 2,
Expand Down Expand Up @@ -2721,6 +2776,56 @@ exports[`c8 json report 1`] = `
"line": 24,
},
},
"24": {
"end": {
"column": 0,
"line": 25,
},
"start": {
"column": 0,
"line": 25,
},
},
"25": {
"end": {
"column": 39,
"line": 26,
},
"start": {
"column": 0,
"line": 26,
},
},
"26": {
"end": {
"column": 34,
"line": 27,
},
"start": {
"column": 0,
"line": 27,
},
},
"27": {
"end": {
"column": 73,
"line": 28,
},
"start": {
"column": 0,
"line": 28,
},
},
"28": {
"end": {
"column": 1,
"line": 29,
},
"start": {
"column": 0,
"line": 29,
},
},
"3": {
"end": {
"column": 0,
Expand Down
5 changes: 5 additions & 0 deletions test/coverage-test/src/utils.ts
Expand Up @@ -22,3 +22,8 @@ export function run() {
// this should not be covered
divide(1, 1)
}

/* istanbul ignore next -- @preserve */
export function unusedFunction() {
return 'This function is not used, but excluded from istanbul coverage'
}

0 comments on commit fef8aa4

Please sign in to comment.