From 8cab9601bb077132187c34f5bc1b8d94c271ba49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Tue, 14 Jan 2025 08:47:32 +0200 Subject: [PATCH] fix: colors on `forks` pool (#7090) --- packages/browser/package.json | 2 +- packages/coverage-istanbul/package.json | 2 +- packages/coverage-v8/package.json | 2 +- packages/expect/package.json | 2 +- packages/pretty-format/package.json | 2 +- packages/ui/package.json | 2 +- packages/utils/package.json | 2 +- packages/vite-node/package.json | 2 +- packages/vitest/package.json | 2 +- packages/vitest/src/node/pool.ts | 2 + pnpm-lock.yaml | 50 ++++++++++++------------- test/config/test/console-color.test.ts | 33 ++++++++++++++++ test/core/package.json | 2 +- test/test-utils/package.json | 2 +- 14 files changed, 71 insertions(+), 36 deletions(-) diff --git a/packages/browser/package.json b/packages/browser/package.json index cf7e73dc0cbf..80bd8ffb7ee7 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -94,7 +94,7 @@ "magic-string": "^0.30.17", "msw": "^2.7.0", "sirv": "^3.0.0", - "tinyrainbow": "^1.2.0", + "tinyrainbow": "^2.0.0", "ws": "^8.18.0" }, "devDependencies": { diff --git a/packages/coverage-istanbul/package.json b/packages/coverage-istanbul/package.json index c398653d81f3..38187cf0ce99 100644 --- a/packages/coverage-istanbul/package.json +++ b/packages/coverage-istanbul/package.json @@ -53,7 +53,7 @@ "istanbul-reports": "^3.1.7", "magicast": "^0.3.5", "test-exclude": "^7.0.1", - "tinyrainbow": "^1.2.0" + "tinyrainbow": "^2.0.0" }, "devDependencies": { "@types/debug": "^4.1.12", diff --git a/packages/coverage-v8/package.json b/packages/coverage-v8/package.json index cd6d984dbcfc..1317160304e5 100644 --- a/packages/coverage-v8/package.json +++ b/packages/coverage-v8/package.json @@ -65,7 +65,7 @@ "magicast": "^0.3.5", "std-env": "^3.8.0", "test-exclude": "^7.0.1", - "tinyrainbow": "^1.2.0" + "tinyrainbow": "^2.0.0" }, "devDependencies": { "@types/debug": "^4.1.12", diff --git a/packages/expect/package.json b/packages/expect/package.json index 9eb13a57727a..d60d8f524715 100644 --- a/packages/expect/package.json +++ b/packages/expect/package.json @@ -37,7 +37,7 @@ "@vitest/spy": "workspace:*", "@vitest/utils": "workspace:*", "chai": "^5.1.2", - "tinyrainbow": "^1.2.0" + "tinyrainbow": "^2.0.0" }, "devDependencies": { "@types/chai": "4.3.6", diff --git a/packages/pretty-format/package.json b/packages/pretty-format/package.json index 844354157b2f..0b86ac82969e 100644 --- a/packages/pretty-format/package.json +++ b/packages/pretty-format/package.json @@ -34,7 +34,7 @@ "dev": "rollup -c --watch" }, "dependencies": { - "tinyrainbow": "^1.2.0" + "tinyrainbow": "^2.0.0" }, "devDependencies": { "@types/react-is": "^19.0.0", diff --git a/packages/ui/package.json b/packages/ui/package.json index b2f769dd9577..7bc2532e5da8 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -53,7 +53,7 @@ "pathe": "^2.0.0", "sirv": "^3.0.0", "tinyglobby": "^0.2.10", - "tinyrainbow": "^1.2.0" + "tinyrainbow": "^2.0.0" }, "devDependencies": { "@faker-js/faker": "^9.3.0", diff --git a/packages/utils/package.json b/packages/utils/package.json index b3588da28a4b..9754817bf0cc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -66,7 +66,7 @@ "dependencies": { "@vitest/pretty-format": "workspace:*", "loupe": "^3.1.2", - "tinyrainbow": "^1.2.0" + "tinyrainbow": "^2.0.0" }, "devDependencies": { "@jridgewell/trace-mapping": "^0.3.25", diff --git a/packages/vite-node/package.json b/packages/vite-node/package.json index 7b2adbb58dac..da48b1570a1a 100644 --- a/packages/vite-node/package.json +++ b/packages/vite-node/package.json @@ -91,6 +91,6 @@ "devDependencies": { "@jridgewell/trace-mapping": "^0.3.25", "@types/debug": "^4.1.12", - "tinyrainbow": "^1.2.0" + "tinyrainbow": "^2.0.0" } } diff --git a/packages/vitest/package.json b/packages/vitest/package.json index 04d0263f6248..e87153d76f67 100644 --- a/packages/vitest/package.json +++ b/packages/vitest/package.json @@ -166,7 +166,7 @@ "tinybench": "^2.9.0", "tinyexec": "^0.3.2", "tinypool": "^1.0.2", - "tinyrainbow": "^1.2.0", + "tinyrainbow": "^2.0.0", "vite": "^5.0.0 || ^6.0.0", "vite-node": "workspace:*", "why-is-node-running": "^2.3.0" diff --git a/packages/vitest/src/node/pool.ts b/packages/vitest/src/node/pool.ts index 7cb70a5c3317..620596a56db6 100644 --- a/packages/vitest/src/node/pool.ts +++ b/packages/vitest/src/node/pool.ts @@ -3,6 +3,7 @@ import type { Vitest } from './core' import type { TestProject } from './project' import type { TestSpecification } from './spec' import type { BuiltinPool, Pool } from './types/pool-options' +import { isatty } from 'node:tty' import mm from 'micromatch' import { isWindows } from '../utils/env' import { createForksPool } from './pools/forks' @@ -124,6 +125,7 @@ export function createPool(ctx: Vitest): ProcessPool { VITEST: 'true', NODE_ENV: process.env.NODE_ENV || 'test', VITEST_MODE: ctx.config.watch ? 'WATCH' : 'RUN', + FORCE_TTY: isatty(1) ? 'true' : '', ...process.env, ...ctx.config.env, }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index da7516933714..b6b0e1d9d21a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -373,8 +373,8 @@ importers: specifier: ^3.0.0 version: 3.0.0 tinyrainbow: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.0 ws: specifier: ^8.18.0 version: 8.18.0 @@ -461,8 +461,8 @@ importers: specifier: ^7.0.1 version: 7.0.1 tinyrainbow: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.0 devDependencies: '@types/debug': specifier: ^4.1.12 @@ -528,8 +528,8 @@ importers: specifier: ^7.0.1 version: 7.0.1 tinyrainbow: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.0 devDependencies: '@types/debug': specifier: ^4.1.12 @@ -577,8 +577,8 @@ importers: specifier: ^5.1.2 version: 5.1.2 tinyrainbow: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.0 devDependencies: '@types/chai': specifier: 4.3.6 @@ -624,8 +624,8 @@ importers: packages/pretty-format: dependencies: tinyrainbow: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.0 devDependencies: '@types/react-is': specifier: ^19.0.0 @@ -695,8 +695,8 @@ importers: specifier: ^0.2.10 version: 0.2.10 tinyrainbow: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.0 vitest: specifier: workspace:* version: link:../vitest @@ -801,8 +801,8 @@ importers: specifier: ^3.1.2 version: 3.1.2 tinyrainbow: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.0 devDependencies: '@jridgewell/trace-mapping': specifier: ^0.3.25 @@ -842,8 +842,8 @@ importers: specifier: ^4.1.12 version: 4.1.12 tinyrainbow: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.0 packages/vitest: dependencies: @@ -902,8 +902,8 @@ importers: specifier: ^1.0.2 version: 1.0.2 tinyrainbow: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.0 vite: specifier: ^5.4.0 version: 5.4.0(@types/node@22.10.2)(terser@5.36.0) @@ -1193,8 +1193,8 @@ importers: specifier: ^11.6.16 version: 11.6.16 tinyrainbow: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.0 tinyspy: specifier: ^1.0.2 version: 1.0.2 @@ -1355,8 +1355,8 @@ importers: specifier: ^0.3.2 version: 0.3.2 tinyrainbow: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.0 + version: 2.0.0 vite: specifier: ^5.4.0 version: 5.4.0(@types/node@22.10.2)(terser@5.36.0) @@ -8845,8 +8845,8 @@ packages: resolution: {integrity: sha512-al6n+QEANGFOMf/dmUMsuS5/r9B06uwlyNjZZql/zv8J7ybHCgoihBNORZCY2mzUuAnomQa2JdhyHKzZxPCrFA==} engines: {node: ^18.0.0 || >=20.0.0} - tinyrainbow@1.2.0: - resolution: {integrity: sha512-weEDEq7Z5eTHPDh4xjX789+fHfF+P8boiFB+0vbWzpbnbsEr/GRaohi/uMKxg8RZMXnl1ItAi/IUHWMsjDV7kQ==} + tinyrainbow@2.0.0: + resolution: {integrity: sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==} engines: {node: '>=14.0.0'} tinyspy@1.0.2: @@ -18471,7 +18471,7 @@ snapshots: tinypool@1.0.2: {} - tinyrainbow@1.2.0: {} + tinyrainbow@2.0.0: {} tinyspy@1.0.2: {} diff --git a/test/config/test/console-color.test.ts b/test/config/test/console-color.test.ts index e139f69aff6d..98f4188b6b07 100644 --- a/test/config/test/console-color.test.ts +++ b/test/config/test/console-color.test.ts @@ -1,4 +1,5 @@ import { expect, test } from 'vitest' +import { isWindows } from '../../../packages/vite-node/src/utils' import { runVitest } from '../../test-utils' test('with color', async () => { @@ -29,3 +30,35 @@ test('without color', async () => { expect(stdout).toContain('true\n') expect(stdout).not.toContain('\x1B[33mtrue\x1B[39m\n') }) + +test.skipIf(isWindows)('without color, forks pool in non-TTY parent', async () => { + const { stdout } = await runVitest({ + root: 'fixtures/console-color', + env: { + CI: undefined, + FORCE_COLOR: undefined, + NO_COLOR: undefined, + GITHUB_ACTIONS: undefined, + + // Overrides current process's value, since we are running Vitest in Vitest here + FORCE_TTY: undefined, + }, + }, undefined, undefined, undefined, { preserveAnsi: true }) + + expect(stdout).toContain('true\n') + expect(stdout).not.toContain('\x1B[33mtrue\x1B[39m\n') +}) + +test('with color, forks pool in TTY parent', async () => { + const { stdout } = await runVitest({ + root: 'fixtures/console-color', + env: { + CI: undefined, + FORCE_COLOR: undefined, + NO_COLOR: undefined, + GITHUB_ACTIONS: undefined, + }, + }, undefined, undefined, undefined, { preserveAnsi: true }) + + expect(stdout).toContain('\x1B[33mtrue\x1B[39m\n') +}) diff --git a/test/core/package.json b/test/core/package.json index c112f6a9042b..a9e779b78700 100644 --- a/test/core/package.json +++ b/test/core/package.json @@ -30,7 +30,7 @@ "react": "^18.3.1", "react-19": "npm:react@19.0.0-rc-b01722d5-20241114", "sweetalert2": "^11.6.16", - "tinyrainbow": "^1.2.0", + "tinyrainbow": "^2.0.0", "tinyspy": "^1.0.2", "url": "^0.11.0", "vite-node": "workspace:*", diff --git a/test/test-utils/package.json b/test/test-utils/package.json index c543444b6c3f..83ea6c79cad2 100644 --- a/test/test-utils/package.json +++ b/test/test-utils/package.json @@ -8,7 +8,7 @@ }, "devDependencies": { "tinyexec": "^0.3.2", - "tinyrainbow": "^1.2.0", + "tinyrainbow": "^2.0.0", "vite": "latest", "vite-node": "workspace:*", "vitest": "workspace:*"