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

feat: improve "isCI" check #2705

Merged
merged 2 commits into from Jan 21, 2023
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
1 change: 1 addition & 0 deletions packages/vitest/package.json
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
@@ -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 @@ -55,8 +56,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
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
@@ -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
@@ -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
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.