Skip to content

Commit

Permalink
test: add test case for vitest-dev#3131
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed May 9, 2023
1 parent 51b0b30 commit 07092c4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/config/package.json
Expand Up @@ -2,7 +2,7 @@
"name": "@vitest/test-config",
"private": true,
"scripts": {
"test": "vitest run test/**"
"test": "vitest run"
},
"devDependencies": {
"execa": "^7.0.0",
Expand Down
14 changes: 14 additions & 0 deletions test/config/test/failures.test.ts
@@ -1,4 +1,5 @@
import { expect, test } from 'vitest'
import { version } from 'vitest/package.json'

import { runVitest } from './utils'

Expand Down Expand Up @@ -57,3 +58,16 @@ test('boolean browser flag without dot notation, with more dot notation options'
expect(error).toMatch('Error: A boolean argument "--browser" was used with dot notation arguments "--browser.name".')
expect(error).toMatch('Please specify the "--browser" argument with dot notation as well: "--browser.enabled"')
})

test('version number is printed when coverage provider fails to load', async () => {
const { error, output } = await runVitest('run', [
'--coverage.enabled',
'--coverage.provider',
'custom',
'--coverage.customProviderModule',
'./non-existing-module.ts',
])

expect(output).toMatch(`RUN v${version}`)
expect(error).toMatch('Error: Failed to load custom CoverageProviderModule from ./non-existing-module.ts')
})
10 changes: 6 additions & 4 deletions test/config/test/utils.ts
Expand Up @@ -4,15 +4,17 @@ import stripAnsi from 'strip-ansi'
export async function runVitest(mode: 'run' | 'watch', cliArguments: string[]) {
const subprocess = execa('vitest', [mode, 'fixtures/test/', ...cliArguments])
let error = ''
let output = ''

subprocess.stdout?.on('data', (data) => {
output += stripAnsi(data.toString())
})

subprocess.stderr?.on('data', (data) => {
error += stripAnsi(data.toString())

// Sometimes on Windows CI execa doesn't exit properly. Force exit when stderr is caught.
subprocess.kill()
})

await new Promise(resolve => subprocess.on('exit', resolve))

return { error }
return { output, error }
}
1 change: 1 addition & 0 deletions test/config/vitest.config.ts
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
include: ['test/**.test.ts'],
testTimeout: 60_000,
chaiConfig: {
truncateThreshold: 999,
Expand Down

0 comments on commit 07092c4

Please sign in to comment.