Skip to content

Commit 5a69e43

Browse files
authored
fix(typecheck): add env var to hide experimental warning (#11840)
1 parent 7a38449 commit 5a69e43

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎docs/config/typecheck.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ Options for configuring [typechecking](/guide/testing-types) test environment.
1515

1616
Enable typechecking alongside your regular tests.
1717

18+
::: tip
19+
When typechecking is enabled, Vitest prints a warning that this is an experimental feature. Set the `VITEST_DISABLE_EXPERIMENTAL_LOG` environment variable to hide it:
20+
21+
```bash
22+
VITEST_DISABLE_EXPERIMENTAL_LOG=true vitest --typecheck
23+
```
24+
:::
25+
1826
## typecheck.only {#typecheck-only}
1927

2028
- **Type:** `boolean`

‎packages/vitest/src/node/config/resolveConfig.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,11 @@ export function resolveTestConfig(
868868
resolved.typecheck ??= {} as any
869869
resolved.typecheck.enabled ??= false
870870

871-
if (resolved.typecheck.enabled && !warnedTypeCheck) {
871+
if (
872+
resolved.typecheck.enabled &&
873+
!warnedTypeCheck &&
874+
!process.env.VITEST_DISABLE_EXPERIMENTAL_LOG
875+
) {
872876
warnedTypeCheck = true
873877
logger.console.warn(
874878
c.yellow(

‎test/typescript/test/runner.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { resolve } from 'pathe'
22
import { glob } from 'tinyglobby'
33
import { describe, expect, it } from 'vitest'
4-
import { runVitest } from '../../test-utils'
4+
import { runVitest, runVitestCli } from '../../test-utils'
55

66
describe('should fail', async () => {
77
const root = resolve(import.meta.dirname, '../failing')
@@ -117,6 +117,26 @@ describe('ignoreSourceErrors', () => {
117117
})
118118
})
119119

120+
describe('experimental warning', () => {
121+
const root = resolve(import.meta.dirname, '../fixtures/dynamic-title')
122+
const warning = 'Testing types with tsc and vue-tsc is an experimental feature.'
123+
124+
it('is printed by default', async () => {
125+
const { stderr } = await runVitestCli('--root', root, '--run')
126+
expect(stderr).toContain(warning)
127+
})
128+
129+
it('is hidden with VITEST_DISABLE_EXPERIMENTAL_LOG', async () => {
130+
const { stderr } = await runVitestCli(
131+
{ nodeOptions: { env: { VITEST_DISABLE_EXPERIMENTAL_LOG: 'true' } } },
132+
'--root',
133+
root,
134+
'--run',
135+
)
136+
expect(stderr).not.toContain(warning)
137+
})
138+
})
139+
120140
describe('when the title is dynamic', () => {
121141
it('works correctly', async () => {
122142
const vitest = await runVitest({

0 commit comments

Comments
 (0)