-
-
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
reportOnFailure
option
- Loading branch information
1 parent
56b9927
commit f8de8f8
Showing
9 changed files
with
82 additions
and
32 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,44 +1,44 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`should fails > .dot-folder/dot-test.test.ts > .dot-folder/dot-test.test.ts 1`] = `"AssertionError: expected true to be false // Object.is equality"`; | ||
exports[`should fail .dot-folder/dot-test.test.ts > .dot-folder/dot-test.test.ts 1`] = `"AssertionError: expected true to be false // Object.is equality"`; | ||
|
||
exports[`should fails > each-timeout.test.ts > each-timeout.test.ts 1`] = `"Error: Test timed out in 10ms."`; | ||
exports[`should fail each-timeout.test.ts > each-timeout.test.ts 1`] = `"Error: Test timed out in 10ms."`; | ||
|
||
exports[`should fails > empty.test.ts > empty.test.ts 1`] = `"Error: No test suite found in file <rootDir>/empty.test.ts"`; | ||
exports[`should fail empty.test.ts > empty.test.ts 1`] = `"Error: No test suite found in file <rootDir>/empty.test.ts"`; | ||
exports[`should fails > expect.test.ts > expect.test.ts 1`] = `"AssertionError: expected 2 to deeply equal 3"`; | ||
exports[`should fail expect.test.ts > expect.test.ts 1`] = `"AssertionError: expected 2 to deeply equal 3"`; | ||
exports[`should fails > hook-timeout.test.ts > hook-timeout.test.ts 1`] = `"Error: Hook timed out in 10ms."`; | ||
exports[`should fail hook-timeout.test.ts > hook-timeout.test.ts 1`] = `"Error: Hook timed out in 10ms."`; | ||
exports[`should fails > hooks-called.test.ts > hooks-called.test.ts 1`] = ` | ||
exports[`should fail hooks-called.test.ts > hooks-called.test.ts 1`] = ` | ||
"Error: after all | ||
Error: before all" | ||
`; | ||
exports[`should fails > inline-snapshop-inside-each.test.ts > inline-snapshop-inside-each.test.ts 1`] = ` | ||
exports[`should fail inline-snapshop-inside-each.test.ts > inline-snapshop-inside-each.test.ts 1`] = ` | ||
"Error: InlineSnapshot cannot be used inside of test.each or describe.each | ||
Error: InlineSnapshot cannot be used inside of test.each or describe.each | ||
Error: InlineSnapshot cannot be used inside of test.each or describe.each | ||
Error: InlineSnapshot cannot be used inside of test.each or describe.each | ||
Error: InlineSnapshot cannot be used inside of test.each or describe.each" | ||
`; | ||
exports[`should fails > mock-import-proxy-module.test.ts > mock-import-proxy-module.test.ts 1`] = `"Error: There are some problems in resolving the mocks API."`; | ||
exports[`should fail mock-import-proxy-module.test.ts > mock-import-proxy-module.test.ts 1`] = `"Error: There are some problems in resolving the mocks API."`; | ||
exports[`should fails > nested-suite.test.ts > nested-suite.test.ts 1`] = `"AssertionError: expected true to be false // Object.is equality"`; | ||
exports[`should fail nested-suite.test.ts > nested-suite.test.ts 1`] = `"AssertionError: expected true to be false // Object.is equality"`; | ||
exports[`should fails > primitive-error.test.ts > primitive-error.test.ts 1`] = `"Unknown Error: 42"`; | ||
exports[`should fail primitive-error.test.ts > primitive-error.test.ts 1`] = `"Unknown Error: 42"`; | ||
exports[`should fails > stall.test.ts > stall.test.ts 1`] = ` | ||
exports[`should fail stall.test.ts > stall.test.ts 1`] = ` | ||
"TypeError: failure | ||
TypeError: failure | ||
TypeError: failure | ||
TypeError: failure" | ||
`; | ||
exports[`should fails > test-timeout.test.ts > test-timeout.test.ts 1`] = `"Error: Test timed out in 10ms."`; | ||
exports[`should fail test-timeout.test.ts > test-timeout.test.ts 1`] = `"Error: Test timed out in 10ms."`; | ||
exports[`should fails > unhandled.test.ts > unhandled.test.ts 1`] = ` | ||
exports[`should fail unhandled.test.ts > unhandled.test.ts 1`] = ` | ||
"Error: some error | ||
Error: Uncaught [Error: some error]" | ||
`; |
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,25 +1,49 @@ | ||
import { resolve } from 'pathe' | ||
import fg from 'fast-glob' | ||
import { describe, expect, it } from 'vitest' | ||
import { expect, it } from 'vitest' | ||
|
||
import { runVitest } from '../../test-utils' | ||
|
||
describe('should fails', async () => { | ||
const root = resolve(__dirname, '../fixtures') | ||
const files = await fg('**/*.test.ts', { cwd: root, dot: true }) | ||
|
||
for (const file of files) { | ||
it(file, async () => { | ||
const { stderr } = await runVitest({ root }, [file]) | ||
|
||
expect(stderr).toBeTruthy() | ||
const msg = String(stderr) | ||
.split(/\n/g) | ||
.reverse() | ||
.filter(i => i.includes('Error: ') && !i.includes('Command failed') && !i.includes('stackStr') && !i.includes('at runTest')) | ||
.map(i => i.trim().replace(root, '<rootDir>'), | ||
).join('\n') | ||
expect(msg).toMatchSnapshot(file) | ||
}, 30_000) | ||
} | ||
const root = resolve(__dirname, '../fixtures') | ||
const files = await fg('**/*.test.ts', { cwd: root, dot: true }) | ||
|
||
it.each(files)('should fail %s', async (file) => { | ||
const { stderr } = await runVitest({ root }, [file]) | ||
|
||
expect(stderr).toBeTruthy() | ||
const msg = String(stderr) | ||
.split(/\n/g) | ||
.reverse() | ||
.filter(i => i.includes('Error: ') && !i.includes('Command failed') && !i.includes('stackStr') && !i.includes('at runTest')) | ||
.map(i => i.trim().replace(root, '<rootDir>'), | ||
).join('\n') | ||
expect(msg).toMatchSnapshot(file) | ||
}, 30_000) | ||
|
||
it('should report coverage when "coverag.reportOnFailure: true" and tests fail', async () => { | ||
const { stdout } = await runVitest({ | ||
root, | ||
coverage: { | ||
enabled: true, | ||
provider: 'istanbul', | ||
reportOnFailure: true, | ||
reporter: ['text'], | ||
}, | ||
}, [files[0]]) | ||
|
||
expect(stdout).toMatch('Coverage report from istanbul') | ||
}) | ||
|
||
it('should not report coverage when "coverag.reportOnFailure: false" and tests fail', async () => { | ||
const { stdout } = await runVitest({ | ||
root, | ||
coverage: { | ||
enabled: true, | ||
provider: 'istanbul', | ||
reportOnFailure: false, | ||
reporter: ['text'], | ||
}, | ||
}, [files[0]]) | ||
|
||
expect(stdout).not.toMatch('Coverage report from istanbul') | ||
}) |