Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(coverage): istanbul provider to work with JSDOM and process.env usage #3899

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exports[`custom json report 1`] = `
"<process-cwd>/src/importEnv.ts",
"<process-cwd>/src/index.mts",
"<process-cwd>/src/multi-suite.ts",
"<process-cwd>/src/process-env.ts",
"<process-cwd>/src/utils.ts",
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,54 @@ exports[`istanbul json report 1`] = `
},
},
},
"<process-cwd>/src/process-env.ts": {
"b": {},
"branchMap": {},
"f": {
"0": 1,
},
"fnMap": {
"0": {
"decl": {
"end": {
"column": 29,
"line": 1,
},
"start": {
"column": 16,
"line": 1,
},
},
"loc": {
"end": {
"column": null,
"line": 3,
},
"start": {
"column": 29,
"line": 1,
},
},
"name": "getNodeEnv",
},
},
"path": "<process-cwd>/src/process-env.ts",
"s": {
"0": 1,
},
"statementMap": {
"0": {
"end": {
"column": null,
"line": 2,
},
"start": {
"column": 2,
"line": 2,
},
},
},
},
"<process-cwd>/src/untested-file.ts": {
"b": {
"0": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3528,6 +3528,109 @@ exports[`v8 json report 1`] = `
},
},
},
"<process-cwd>/src/process-env.ts": {
"all": false,
"b": {
"0": [
1,
],
},
"branchMap": {
"0": {
"line": 1,
"loc": {
"end": {
"column": 1,
"line": 3,
},
"start": {
"column": 7,
"line": 1,
},
},
"locations": [
{
"end": {
"column": 1,
"line": 3,
},
"start": {
"column": 7,
"line": 1,
},
},
],
"type": "branch",
},
},
"f": {
"0": 1,
},
"fnMap": {
"0": {
"decl": {
"end": {
"column": 1,
"line": 3,
},
"start": {
"column": 7,
"line": 1,
},
},
"line": 1,
"loc": {
"end": {
"column": 1,
"line": 3,
},
"start": {
"column": 7,
"line": 1,
},
},
"name": "getNodeEnv",
},
},
"path": "<process-cwd>/src/process-env.ts",
"s": {
"0": 1,
"1": 1,
"2": 1,
},
"statementMap": {
"0": {
"end": {
"column": 30,
"line": 1,
},
"start": {
"column": 0,
"line": 1,
},
},
"1": {
"end": {
"column": 29,
"line": 2,
},
"start": {
"column": 0,
"line": 2,
},
},
"2": {
"end": {
"column": 1,
"line": 3,
},
"start": {
"column": 0,
"line": 3,
},
},
},
},
"<process-cwd>/src/untested-file.ts": {
"all": true,
"b": {
Expand Down
10 changes: 10 additions & 0 deletions test/coverage-test/coverage-report-tests/istanbul.report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Istanbul coverage provider specific test cases
*/

import { resolve } from 'node:path'
import { readFileSync } from 'node:fs'
import { expect, test } from 'vitest'
import { readCoverageJson } from './utils'

Expand Down Expand Up @@ -50,3 +52,11 @@ test('tests with multiple suites are covered', async () => {
1: 1,
})
})

test('vite transforms should not show on coverage report', async () => {
const filePath = resolve('./coverage/src/process-env.ts.html')
const htmlContent = readFileSync(filePath, 'utf-8')

// Actual source code
expect(htmlContent).toContain('process.env.NODE_ENV')
})
3 changes: 3 additions & 0 deletions test/coverage-test/src/process-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getNodeEnv() {
return process.env.NODE_ENV
}
8 changes: 8 additions & 0 deletions test/coverage-test/test/jsdom.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @vitest-environment jsdom

import { expect, test } from 'vitest'
import { getNodeEnv } from '../src/process-env'

test('process.env works', () => {
expect(getNodeEnv()).toBe('test')
})
Loading