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: config errors not visible #2995

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/vitest/src/node/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export async function printError(error: unknown, ctx: Vitest, options: PrintErro
} as any
}

// Error may have occured even before the configuration was resolved
if (!ctx.config)
return printErrorMessage(e, ctx.logger)

const stacks = parseErrorStacktrace(e, fullStack)

const nearest = error instanceof TypeCheckError
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
(await import('../../api/setup')).setup(ctx)
}
catch (err) {
ctx.logger.printError(err, true)
await ctx.logger.printError(err, true)
process.exit(1)
}

Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/config/fixtures/test/example.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, test } from 'vitest'

test('it works', () => {
expect(true).toBe(true)
})
13 changes: 13 additions & 0 deletions test/config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@vitest/test-config",
"private": true,
"scripts": {
"test": "vitest run test/**"
},
"devDependencies": {
"execa": "^7.0.0",
"strip-ansi": "^7.0.1",
"vite": "latest",
"vitest": "workspace:*"
}
}
21 changes: 21 additions & 0 deletions test/config/test/failures.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect, test } from 'vitest'

import { runVitest } from './utils'

test('shard cannot be used with watch mode', async () => {
const { error } = await runVitest('watch', ['--shard', '1/2'])

expect(error).toMatch('Error: You cannot use --shard option with enabled watch')
})

test('shard must be positive number', async () => {
const { error } = await runVitest('run', ['--shard', '"-1"'])

expect(error).toMatch('Error: --shard <count> must be a positive number')
})

test('shard index must be smaller than count', async () => {
const { error } = await runVitest('run', ['--shard', '2/1'])

expect(error).toMatch('Error: --shard <index> must be a positive number less then <count>')
})
15 changes: 15 additions & 0 deletions test/config/test/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { execa } from 'execa'
import stripAnsi from 'strip-ansi'

export async function runVitest(mode: 'run' | 'watch', cliArguments: string[]) {
const subprocess = execa('vitest', [mode, 'fixtures/test/', ...cliArguments])
let error = ''

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

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

return { error }
}