Skip to content

Commit

Permalink
feat: improve "isCI" check (#2705)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Jan 21, 2023
1 parent 703aab4 commit e64570d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"local-pkg": "^0.4.2",
"picocolors": "^1.0.0",
"source-map": "^0.6.1",
"std-env": "^3.3.1",
"strip-literal": "^1.0.0",
"tinybench": "^2.3.1",
"tinypool": "^0.3.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/vitest/src/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BenchmarkUserOptions, ResolvedCoverageOptions, UserConfig } from './types'
import { isCI } from './utils/env'

export const defaultInclude = ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
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.*']
Expand Down Expand Up @@ -53,8 +54,8 @@ export const fakeTimersDefaults = {
} as NonNullable<UserConfig['fakeTimers']>

const config = {
allowOnly: !process.env.CI,
watch: !process.env.CI,
allowOnly: !isCI,
watch: !isCI,
globals: false,
environment: 'node' as const,
threads: true,
Expand Down
5 changes: 2 additions & 3 deletions packages/vitest/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ResolvedConfig as ResolvedViteConfig } from 'vite'
import type { ApiConfig, ResolvedConfig, UserConfig, VitestRunMode } from '../types'
import { defaultPort } from '../constants'
import { benchmarkConfigDefaults, configDefaults } from '../defaults'
import { toArray } from '../utils'
import { isCI, toArray } from '../utils'
import { VitestCache } from './cache'
import { BaseSequencer } from './sequencers/BaseSequencer'
import { RandomSequencer } from './sequencers/RandomSequencer'
Expand Down Expand Up @@ -139,11 +139,10 @@ export function resolveConfig(
: new RegExp(resolved.testNamePattern)
: undefined

const CI = !!process.env.CI
const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT
resolved.snapshotOptions = {
snapshotFormat: resolved.snapshotFormat || {},
updateSnapshot: CI && !UPDATE_SNAPSHOT
updateSnapshot: isCI && !UPDATE_SNAPSHOT
? 'none'
: UPDATE_SNAPSHOT
? 'all'
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/reporters/base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { performance } from 'perf_hooks'
import c from 'picocolors'
import type { ErrorWithDiff, File, Reporter, Task, TaskResultPack, UserConsoleLog } from '../../types'
import { clearInterval, getFullName, getSuites, getTests, hasFailed, hasFailedSnapshot, isNode, relativePath, setInterval } from '../../utils'
import { clearInterval, getFullName, getSuites, getTests, hasFailed, hasFailedSnapshot, isCI, isNode, relativePath, setInterval } from '../../utils'
import type { Vitest } from '../../node'
import { F_RIGHT } from '../../utils/figures'
import { countTestErrors, divider, formatProjectName, formatTimeString, getStateString, getStateSymbol, pointer, renderSnapshotSummary } from './renderers/utils'
Expand All @@ -20,7 +20,7 @@ export abstract class BaseReporter implements Reporter {
start = 0
end = 0
watchFilters?: string[]
isTTY = isNode && process.stdout?.isTTY && !process.env.CI
isTTY = isNode && process.stdout?.isTTY && !isCI
ctx: Vitest = undefined!

private _filesInWatchMode = new Map<string, number>()
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/utils/env.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const isNode: boolean = typeof process < 'u' && typeof process.stdout < 'u' && !process.versions?.deno && !globalThis.window
export const isBrowser: boolean = typeof window !== 'undefined'
export { isCI } from 'std-env'
4 changes: 2 additions & 2 deletions packages/vitest/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Suite, Task } from '../types'
import { EXIT_CODE_RESTART } from '../constants'
import { getWorkerState } from '../utils'
import { getNames } from './tasks'
import { isBrowser, isNode } from './env'
import { isBrowser, isCI, isNode } from './env'

export * from './graph'
export * from './tasks'
Expand Down Expand Up @@ -83,7 +83,7 @@ export async function ensurePackageInstalled(
if (isPackageExists(dependency, { paths: [root] }))
return true

const promptInstall = !process.env.CI && process.stdout.isTTY
const promptInstall = !isCI && process.stdout.isTTY

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

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

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

0 comments on commit e64570d

Please sign in to comment.