diff --git a/packages/vitest/LICENSE.md b/packages/vitest/LICENSE.md index 375bf139ecfe..fc3e3663e65d 100644 --- a/packages/vitest/LICENSE.md +++ b/packages/vitest/LICENSE.md @@ -931,23 +931,6 @@ Repository: micromatch/micromatch --------------------------------------- -## mimic-fn -License: MIT -By: Sindre Sorhus -Repository: sindresorhus/mimic-fn - -> MIT License -> -> Copyright (c) Sindre Sorhus (sindresorhus.com) -> -> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -> -> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -> -> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ---------------------------------------- - ## mlly License: MIT Repository: unjs/mlly @@ -976,23 +959,6 @@ Repository: unjs/mlly --------------------------------------- -## onetime -License: MIT -By: Sindre Sorhus -Repository: sindresorhus/onetime - -> MIT License -> -> Copyright (c) Sindre Sorhus (https://sindresorhus.com) -> -> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -> -> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -> -> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ---------------------------------------- - ## p-limit License: MIT By: Sindre Sorhus @@ -1171,23 +1137,6 @@ Repository: privatenumber/resolve-pkg-maps --------------------------------------- -## restore-cursor -License: MIT -By: Sindre Sorhus -Repository: sindresorhus/restore-cursor - -> MIT License -> -> Copyright (c) Sindre Sorhus (https://sindresorhus.com) -> -> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -> -> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -> -> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ---------------------------------------- - ## reusify License: MIT By: Matteo Collina @@ -1245,30 +1194,6 @@ Repository: git://github.com/feross/run-parallel.git --------------------------------------- -## signal-exit -License: ISC -By: Ben Coe -Repository: https://github.com/tapjs/signal-exit.git - -> The ISC License -> -> Copyright (c) 2015, Contributors -> -> Permission to use, copy, modify, and/or distribute this software -> for any purpose with or without fee is hereby granted, provided -> that the above copyright notice and this permission notice -> appear in all copies. -> -> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES -> OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE -> LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES -> OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -> WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -> ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - ---------------------------------------- - ## sisteransi License: MIT By: Terkel Gjervig diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 0a90e0d9ddac..c7b84a1e3ce2 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -78,6 +78,7 @@ export class Vitest { public packageInstaller: VitestPackageInstaller + /** TODO: rename to `_coreRootProject` */ /** @internal */ public coreWorkspaceProject!: TestProject @@ -93,7 +94,7 @@ export class Vitest { /** @deprecated use `_cachedSpecs` */ projectTestFiles = this._cachedSpecs - /** @private */ + /** @internal */ public _browserLastPort = defaultBrowserPort /** @internal */ diff --git a/packages/vitest/src/node/logger.ts b/packages/vitest/src/node/logger.ts index fd3ec64292e9..490b774be044 100644 --- a/packages/vitest/src/node/logger.ts +++ b/packages/vitest/src/node/logger.ts @@ -276,15 +276,15 @@ export class Logger { + '\nThis might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.', ), ) - this.log(c.red(divider(c.bold(c.inverse(' Unhandled Errors '))))) - this.log(errorMessage) + this.error(c.red(divider(c.bold(c.inverse(' Unhandled Errors '))))) + this.error(errorMessage) errors.forEach((err) => { this.printError(err, { fullStack: true, type: (err as ErrorWithDiff).type || 'Unhandled Error', }) }) - this.log(c.red(divider())) + this.error(c.red(divider())) } printSourceTypeErrors(errors: TypeCheckError[]) { diff --git a/packages/vitest/src/node/reporters/base.ts b/packages/vitest/src/node/reporters/base.ts index 1f4cf9edbf7c..10664b7fcad2 100644 --- a/packages/vitest/src/node/reporters/base.ts +++ b/packages/vitest/src/node/reporters/base.ts @@ -410,12 +410,12 @@ export abstract class BaseReporter implements Reporter { const errorDivider = () => this.error(`${c.red(c.dim(divider(`[${current++}/${failedTotal}]`, undefined, 1)))}\n`) if (failedSuites.length) { - this.error(`${errorBanner(`Failed Suites ${failedSuites.length}`)}\n`) + this.error(`\n${errorBanner(`Failed Suites ${failedSuites.length}`)}\n`) this.printTaskErrors(failedSuites, errorDivider) } if (failedTests.length) { - this.error(`${errorBanner(`Failed Tests ${failedTests.length}`)}\n`) + this.error(`\n${errorBanner(`Failed Tests ${failedTests.length}`)}\n`) this.printTaskErrors(failedTests, errorDivider) } @@ -496,7 +496,7 @@ export abstract class BaseReporter implements Reporter { } this.ctx.logger.error( - `${c.red(c.bold(c.inverse(' FAIL ')))}${formatProjectName(projectName)} ${name}`, + `${c.red(c.bold(c.inverse(' FAIL ')))} ${formatProjectName(projectName)}${name}`, ) } diff --git a/packages/vitest/src/node/reporters/renderers/utils.ts b/packages/vitest/src/node/reporters/renderers/utils.ts index 2f3b4b9a6b6d..9aa777a08d84 100644 --- a/packages/vitest/src/node/reporters/renderers/utils.ts +++ b/packages/vitest/src/node/reporters/renderers/utils.ts @@ -239,13 +239,16 @@ export function formatProjectName(name: string | undefined, suffix = ' ') { if (!name) { return '' } + if (!c.isColorSupported) { + return `|${name}|${suffix}` + } const index = name .split('') .reduce((acc, v, idx) => acc + v.charCodeAt(0) + idx, 0) - const colors = [c.blue, c.yellow, c.cyan, c.green, c.magenta] + const colors = [c.black, c.yellow, c.cyan, c.green, c.magenta] - return colors[index % colors.length](`|${name}|`) + suffix + return c.inverse(colors[index % colors.length](` ${name} `)) + suffix } export function withLabel(color: 'red' | 'green' | 'blue' | 'cyan' | 'yellow', label: string, message?: string) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ebb58c22f3be..ad0abb2df2ec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1342,6 +1342,9 @@ importers: tinyexec: specifier: ^0.3.0 version: 0.3.0 + tinyrainbow: + specifier: ^1.2.0 + version: 1.2.0 vite: specifier: ^5.4.0 version: 5.4.0(@types/node@22.9.0)(terser@5.36.0) diff --git a/test/cli/test/__snapshots__/stacktraces.test.ts.snap b/test/cli/test/__snapshots__/stacktraces.test.ts.snap index 2303389c1af2..455db99fadb1 100644 --- a/test/cli/test/__snapshots__/stacktraces.test.ts.snap +++ b/test/cli/test/__snapshots__/stacktraces.test.ts.snap @@ -1,7 +1,8 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`stacktrace filtering > filters stacktraces > stacktrace-filtering 1`] = ` -"⎯⎯ Failed Tests 1 ⎯⎯ +" +⎯⎯ Failed Tests 1 ⎯⎯ FAIL error-with-stack.test.js > error in deps Error: Something truly horrible has happened! @@ -22,7 +23,8 @@ Error: Something truly horrible has happened! `; exports[`stacktrace in vmThreads 1`] = ` -"⎯⎯ Failed Tests 1 ⎯⎯ +" +⎯⎯ Failed Tests 1 ⎯⎯ FAIL error-with-stack.test.js > error in deps Error: Something truly horrible has happened! @@ -44,7 +46,8 @@ Error: Something truly horrible has happened! `; exports[`stacktrace should print error frame source file correctly > error-in-deps > error-in-deps 1`] = ` -"⎯⎯ Failed Tests 1 ⎯⎯ +" +⎯⎯ Failed Tests 1 ⎯⎯ FAIL error-in-deps.test.js > error in deps ReferenceError: bar is not defined diff --git a/test/cli/test/custom-pool.test.ts b/test/cli/test/custom-pool.test.ts index 719cf974c442..10cb7fb14971 100644 --- a/test/cli/test/custom-pool.test.ts +++ b/test/cli/test/custom-pool.test.ts @@ -4,7 +4,7 @@ import { runVitest } from '../../test-utils' test('can run custom pools with Vitest', async () => { const vitest = await runVitest({ root: './fixtures/custom-pool', - reporters: ['basic'], + reporters: [['default', { isTTY: false }]], }) expect(vitest.stderr).toMatchInlineSnapshot(` diff --git a/test/config/test/dangerously-ignore-unhandled-errors.test.ts b/test/config/test/dangerously-ignore-unhandled-errors.test.ts index f0880dab7a42..ba723496e091 100644 --- a/test/config/test/dangerously-ignore-unhandled-errors.test.ts +++ b/test/config/test/dangerously-ignore-unhandled-errors.test.ts @@ -3,13 +3,13 @@ import { expect, test } from 'vitest' import { runVitest } from '../../test-utils' test('{ dangerouslyIgnoreUnhandledErrors: true }', async () => { - const { stderr, stdout, exitCode } = await runVitest({ + const { stderr, exitCode } = await runVitest({ root: 'fixtures/dangerously-ignore-unhandled-errors', dangerouslyIgnoreUnhandledErrors: true, }) expect(exitCode).toBe(0) - expect(stdout).toMatch('Vitest caught 1 unhandled error during the test run') + expect(stderr).toMatch('Vitest caught 1 unhandled error during the test run') expect(stderr).toMatch('Error: intentional unhandled error') }) @@ -24,12 +24,12 @@ test('{ dangerouslyIgnoreUnhandledErrors: true } without reporter', async () => }) test('{ dangerouslyIgnoreUnhandledErrors: false }', async () => { - const { stderr, stdout, exitCode } = await runVitest({ + const { stderr, exitCode } = await runVitest({ root: 'fixtures/dangerously-ignore-unhandled-errors', dangerouslyIgnoreUnhandledErrors: false, }) expect(exitCode).toBe(1) - expect(stdout).toMatch('Vitest caught 1 unhandled error during the test run') + expect(stderr).toMatch('Vitest caught 1 unhandled error during the test run') expect(stderr).toMatch('Error: intentional unhandled error') }) diff --git a/test/reporters/tests/indicator-position.test.ts b/test/reporters/tests/indicator-position.test.ts index cec7629cb4c2..b695232b950c 100644 --- a/test/reporters/tests/indicator-position.test.ts +++ b/test/reporters/tests/indicator-position.test.ts @@ -11,7 +11,8 @@ test('should print correct indicator position', async () => { expect(code).toMatch(/\r\n/) expect(stderr).toBeTruthy() expect(stderr).toMatchInlineSnapshot(` - "⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯ + " + ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯ FAIL indicator-position.test.js > AssertionError: expected 2 to be 3 // Object.is equality diff --git a/test/reporters/tests/merge-reports.test.ts b/test/reporters/tests/merge-reports.test.ts index c868b4955dd8..df5fcd885e4e 100644 --- a/test/reporters/tests/merge-reports.test.ts +++ b/test/reporters/tests/merge-reports.test.ts @@ -34,7 +34,7 @@ test('merge reports', async () => { .replace(/Start at [\w\s:]+/, 'Start at