Skip to content

Commit e64570d

Browse files
authoredJan 21, 2023
feat: improve "isCI" check (#2705)
1 parent 703aab4 commit e64570d

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed
 

‎packages/vitest/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"local-pkg": "^0.4.2",
118118
"picocolors": "^1.0.0",
119119
"source-map": "^0.6.1",
120+
"std-env": "^3.3.1",
120121
"strip-literal": "^1.0.0",
121122
"tinybench": "^2.3.1",
122123
"tinypool": "^0.3.0",

‎packages/vitest/src/defaults.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { BenchmarkUserOptions, ResolvedCoverageOptions, UserConfig } from './types'
2+
import { isCI } from './utils/env'
23

34
export const defaultInclude = ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
45
export const defaultExclude = ['**/node_modules/**', '**/dist/**', '**/cypress/**', '**/.{idea,git,cache,output,temp}/**', '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*']
@@ -53,8 +54,8 @@ export const fakeTimersDefaults = {
5354
} as NonNullable<UserConfig['fakeTimers']>
5455

5556
const config = {
56-
allowOnly: !process.env.CI,
57-
watch: !process.env.CI,
57+
allowOnly: !isCI,
58+
watch: !isCI,
5859
globals: false,
5960
environment: 'node' as const,
6061
threads: true,

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { ResolvedConfig as ResolvedViteConfig } from 'vite'
66
import type { ApiConfig, ResolvedConfig, UserConfig, VitestRunMode } from '../types'
77
import { defaultPort } from '../constants'
88
import { benchmarkConfigDefaults, configDefaults } from '../defaults'
9-
import { toArray } from '../utils'
9+
import { isCI, toArray } from '../utils'
1010
import { VitestCache } from './cache'
1111
import { BaseSequencer } from './sequencers/BaseSequencer'
1212
import { RandomSequencer } from './sequencers/RandomSequencer'
@@ -139,11 +139,10 @@ export function resolveConfig(
139139
: new RegExp(resolved.testNamePattern)
140140
: undefined
141141

142-
const CI = !!process.env.CI
143142
const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT
144143
resolved.snapshotOptions = {
145144
snapshotFormat: resolved.snapshotFormat || {},
146-
updateSnapshot: CI && !UPDATE_SNAPSHOT
145+
updateSnapshot: isCI && !UPDATE_SNAPSHOT
147146
? 'none'
148147
: UPDATE_SNAPSHOT
149148
? 'all'

‎packages/vitest/src/node/reporters/base.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { performance } from 'perf_hooks'
22
import c from 'picocolors'
33
import type { ErrorWithDiff, File, Reporter, Task, TaskResultPack, UserConsoleLog } from '../../types'
4-
import { clearInterval, getFullName, getSuites, getTests, hasFailed, hasFailedSnapshot, isNode, relativePath, setInterval } from '../../utils'
4+
import { clearInterval, getFullName, getSuites, getTests, hasFailed, hasFailedSnapshot, isCI, isNode, relativePath, setInterval } from '../../utils'
55
import type { Vitest } from '../../node'
66
import { F_RIGHT } from '../../utils/figures'
77
import { countTestErrors, divider, formatProjectName, formatTimeString, getStateString, getStateSymbol, pointer, renderSnapshotSummary } from './renderers/utils'
@@ -20,7 +20,7 @@ export abstract class BaseReporter implements Reporter {
2020
start = 0
2121
end = 0
2222
watchFilters?: string[]
23-
isTTY = isNode && process.stdout?.isTTY && !process.env.CI
23+
isTTY = isNode && process.stdout?.isTTY && !isCI
2424
ctx: Vitest = undefined!
2525

2626
private _filesInWatchMode = new Map<string, number>()

‎packages/vitest/src/utils/env.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const isNode: boolean = typeof process < 'u' && typeof process.stdout < 'u' && !process.versions?.deno && !globalThis.window
22
export const isBrowser: boolean = typeof window !== 'undefined'
3+
export { isCI } from 'std-env'

‎packages/vitest/src/utils/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { Suite, Task } from '../types'
77
import { EXIT_CODE_RESTART } from '../constants'
88
import { getWorkerState } from '../utils'
99
import { getNames } from './tasks'
10-
import { isBrowser, isNode } from './env'
10+
import { isBrowser, isCI, isNode } from './env'
1111

1212
export * from './graph'
1313
export * from './tasks'
@@ -83,7 +83,7 @@ export async function ensurePackageInstalled(
8383
if (isPackageExists(dependency, { paths: [root] }))
8484
return true
8585

86-
const promptInstall = !process.env.CI && process.stdout.isTTY
86+
const promptInstall = !isCI && process.stdout.isTTY
8787

8888
process.stderr.write(c.red(`${c.inverse(c.red(' MISSING DEP '))} Can not find dependency '${dependency}'\n\n`))
8989

‎pnpm-lock.yaml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.