diff --git a/test/config/package.json b/test/config/package.json index 2bde0e50bbe7..56c95551587d 100644 --- a/test/config/package.json +++ b/test/config/package.json @@ -2,7 +2,7 @@ "name": "@vitest/test-config", "private": true, "scripts": { - "test": "vitest run test/**" + "test": "vitest run" }, "devDependencies": { "execa": "^7.0.0", diff --git a/test/config/test/failures.test.ts b/test/config/test/failures.test.ts index 5abde7b08cb7..0dcfcd0f9032 100644 --- a/test/config/test/failures.test.ts +++ b/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' @@ -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') +}) diff --git a/test/config/test/utils.ts b/test/config/test/utils.ts index 51e8b4922494..1dc0ccabd2e5 100644 --- a/test/config/test/utils.ts +++ b/test/config/test/utils.ts @@ -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 } } diff --git a/test/config/vitest.config.ts b/test/config/vitest.config.ts index a3f5c3ce3f00..8d362f825f92 100644 --- a/test/config/vitest.config.ts +++ b/test/config/vitest.config.ts @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config' export default defineConfig({ test: { + include: ['test/**.test.ts'], testTimeout: 60_000, chaiConfig: { truncateThreshold: 999,