diff --git a/packages/vitest/package.json b/packages/vitest/package.json index 18d4988fed4d..b4a089469476 100644 --- a/packages/vitest/package.json +++ b/packages/vitest/package.json @@ -113,6 +113,7 @@ "acorn-walk": "^8.2.0", "cac": "^6.7.14", "chai": "^4.3.7", + "ci-info": "^3.7.1", "debug": "^4.3.4", "local-pkg": "^0.4.2", "picocolors": "^1.0.0", diff --git a/packages/vitest/src/defaults.ts b/packages/vitest/src/defaults.ts index 5aef9bc4bdaf..c3f618f19c82 100644 --- a/packages/vitest/src/defaults.ts +++ b/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}.config.*'] @@ -55,8 +56,8 @@ export const fakeTimersDefaults = { } as NonNullable const config = { - allowOnly: !process.env.CI, - watch: !process.env.CI, + allowOnly: !isCI, + watch: !isCI, globals: false, environment: 'node' as const, threads: true, diff --git a/packages/vitest/src/node/config.ts b/packages/vitest/src/node/config.ts index 0d7b4f24f9ec..7a30a16d66d3 100644 --- a/packages/vitest/src/node/config.ts +++ b/packages/vitest/src/node/config.ts @@ -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' @@ -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' diff --git a/packages/vitest/src/node/reporters/base.ts b/packages/vitest/src/node/reporters/base.ts index 0127f594cadd..2905ed96c5d9 100644 --- a/packages/vitest/src/node/reporters/base.ts +++ b/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' @@ -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() diff --git a/packages/vitest/src/utils/env.ts b/packages/vitest/src/utils/env.ts index 87c1c22667d2..f0e252ff35d6 100644 --- a/packages/vitest/src/utils/env.ts +++ b/packages/vitest/src/utils/env.ts @@ -1,2 +1,3 @@ export const isNode = typeof process < 'u' && typeof process.stdout < 'u' && !process.versions?.deno && !globalThis.window export const isBrowser = typeof window !== 'undefined' +export { isCI } from 'ci-info' diff --git a/packages/vitest/src/utils/index.ts b/packages/vitest/src/utils/index.ts index 21f3d40b7889..73365d759e5a 100644 --- a/packages/vitest/src/utils/index.ts +++ b/packages/vitest/src/utils/index.ts @@ -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' @@ -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`)) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9d074c36b87e..4674b81ff02f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -843,6 +843,7 @@ importers: cac: ^6.7.14 chai: ^4.3.7 chai-subset: ^1.6.0 + ci-info: ^3.7.1 cli-truncate: ^3.1.0 debug: ^4.3.4 diff: ^5.1.0 @@ -887,6 +888,7 @@ importers: acorn-walk: 8.2.0 cac: 6.7.14 chai: 4.3.7 + ci-info: 3.7.1 debug: 4.3.4 local-pkg: 0.4.2 picocolors: 1.0.0 @@ -10419,6 +10421,11 @@ packages: engines: {node: '>=8'} dev: true + /ci-info/3.7.1: + resolution: {integrity: sha512-4jYS4MOAaCIStSRwiuxc4B8MYhIe676yO1sYGzARnjXkWpmzZMMYxY6zu8WYWDhSuth5zhrQ1rhNSibyyvv4/w==} + engines: {node: '>=8'} + dev: false + /cipher-base/1.0.4: resolution: {integrity: sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==} dependencies: