-
-
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.
feat(coverage): add
allowExternal
option (#3894)
Co-authored-by: Ari Perkkiö <ari.perkkio@gmail.com>
- Loading branch information
1 parent
5704b34
commit c03faa2
Showing
12 changed files
with
134 additions
and
2 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
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
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
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
20 changes: 20 additions & 0 deletions
20
test/coverage-test/coverage-report-tests/allow-external.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,20 @@ | ||
import fs from 'node:fs' | ||
import { expect, test } from 'vitest' | ||
|
||
const allowExternal = import.meta.env.VITE_COVERAGE_ALLOW_EXTERNAL | ||
|
||
test.skipIf(!allowExternal)('{ allowExternal: true } includes files outside project root', async () => { | ||
expect(fs.existsSync('./coverage/test-utils/fixtures/math.ts.html')).toBe(true) | ||
|
||
// Files inside project root should always be included | ||
expect(fs.existsSync('./coverage/coverage-test/src/utils.ts.html')).toBe(true) | ||
}) | ||
|
||
test.skipIf(allowExternal)('{ allowExternal: false } excludes files outside project root', async () => { | ||
expect(fs.existsSync('./coverage/test-utils/fixtures/math.ts.html')).toBe(false) | ||
expect(fs.existsSync('./test-utils/fixtures/math.ts.html')).toBe(false) | ||
expect(fs.existsSync('./fixtures/math.ts.html')).toBe(false) | ||
|
||
// Files inside project root should always be included | ||
expect(fs.existsSync('./coverage/utils.ts.html')).toBe(true) | ||
}) |
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,12 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
import { multiply } from '../src/utils' | ||
import * as ExternalMath from '../../test-utils/fixtures/math' | ||
|
||
test('calling files outside project root', () => { | ||
expect(ExternalMath.sum(2, 3)).toBe(5) | ||
}) | ||
|
||
test('multiply - add some files to report', () => { | ||
expect(multiply(2, 3)).toBe(6) | ||
}) |
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
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,69 @@ | ||
import { startVitest } from 'vitest/node' | ||
|
||
/** @type {Record<string, Partial<import('vitest/config').UserConfig['test']>>[]} */ | ||
const testCases = [ | ||
{ | ||
testConfig: { | ||
name: 'allowExternal: true', | ||
include: ['option-tests/allow-external.test.ts'], | ||
coverage: { | ||
allowExternal: true, | ||
include: ['**/src/**', '**/test-utils/fixtures/**'], | ||
reporter: 'html', | ||
}, | ||
}, | ||
assertionConfig: { | ||
include: ['coverage-report-tests/allow-external.test.ts'], | ||
env: { VITE_COVERAGE_ALLOW_EXTERNAL: true }, | ||
}, | ||
}, | ||
{ | ||
testConfig: { | ||
name: 'allowExternal: false', | ||
include: ['option-tests/allow-external.test.ts'], | ||
coverage: { | ||
allowExternal: false, | ||
include: ['**/src/**', '**/test-utils/fixtures/**'], | ||
reporter: 'html', | ||
}, | ||
}, | ||
assertionConfig: { | ||
include: ['coverage-report-tests/allow-external.test.ts'], | ||
}, | ||
}, | ||
] | ||
|
||
for (const provider of ['v8', 'istanbul']) { | ||
for (const { testConfig, assertionConfig } of testCases) { | ||
// Run test case | ||
await startVitest('test', ['option-tests/'], { | ||
config: false, | ||
watch: false, | ||
...testConfig, | ||
name: `${provider} - ${testConfig.name}`, | ||
coverage: { | ||
enabled: true, | ||
clean: true, | ||
provider, | ||
...testConfig.coverage, | ||
}, | ||
}) | ||
|
||
checkExit() | ||
|
||
// Check generated coverage report | ||
await startVitest('test', ['coverage-report-tests'], { | ||
config: false, | ||
watch: false, | ||
...assertionConfig, | ||
name: `${provider} - assert ${testConfig.name}`, | ||
}) | ||
|
||
checkExit() | ||
} | ||
} | ||
|
||
function checkExit() { | ||
if (process.exitCode) | ||
process.exit(process.exitCode) | ||
} |
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 @@ | ||
export function sum(a: number, b: number) { | ||
return a + b | ||
} | ||
|
||
export function multiply(a: number, b: number) { | ||
return a * b | ||
} |