Skip to content

Commit a3bef59

Browse files
authored
feat: print project name as a label (#6925)
1 parent 4d94b95 commit a3bef59

File tree

16 files changed

+46
-96
lines changed

16 files changed

+46
-96
lines changed

packages/vitest/LICENSE.md

-75
Original file line numberDiff line numberDiff line change
@@ -931,23 +931,6 @@ Repository: micromatch/micromatch
931931
932932
---------------------------------------
933933

934-
## mimic-fn
935-
License: MIT
936-
By: Sindre Sorhus
937-
Repository: sindresorhus/mimic-fn
938-
939-
> MIT License
940-
>
941-
> Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
942-
>
943-
> 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:
944-
>
945-
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
946-
>
947-
> 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.
948-
949-
---------------------------------------
950-
951934
## mlly
952935
License: MIT
953936
Repository: unjs/mlly
@@ -976,23 +959,6 @@ Repository: unjs/mlly
976959
977960
---------------------------------------
978961

979-
## onetime
980-
License: MIT
981-
By: Sindre Sorhus
982-
Repository: sindresorhus/onetime
983-
984-
> MIT License
985-
>
986-
> Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
987-
>
988-
> 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:
989-
>
990-
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
991-
>
992-
> 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.
993-
994-
---------------------------------------
995-
996962
## p-limit
997963
License: MIT
998964
By: Sindre Sorhus
@@ -1171,23 +1137,6 @@ Repository: privatenumber/resolve-pkg-maps
11711137
11721138
---------------------------------------
11731139

1174-
## restore-cursor
1175-
License: MIT
1176-
By: Sindre Sorhus
1177-
Repository: sindresorhus/restore-cursor
1178-
1179-
> MIT License
1180-
>
1181-
> Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
1182-
>
1183-
> 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:
1184-
>
1185-
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1186-
>
1187-
> 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.
1188-
1189-
---------------------------------------
1190-
11911140
## reusify
11921141
License: MIT
11931142
By: Matteo Collina
@@ -1245,30 +1194,6 @@ Repository: git://github.com/feross/run-parallel.git
12451194
12461195
---------------------------------------
12471196

1248-
## signal-exit
1249-
License: ISC
1250-
By: Ben Coe
1251-
Repository: https://github.com/tapjs/signal-exit.git
1252-
1253-
> The ISC License
1254-
>
1255-
> Copyright (c) 2015, Contributors
1256-
>
1257-
> Permission to use, copy, modify, and/or distribute this software
1258-
> for any purpose with or without fee is hereby granted, provided
1259-
> that the above copyright notice and this permission notice
1260-
> appear in all copies.
1261-
>
1262-
> THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1263-
> WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
1264-
> OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
1265-
> LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
1266-
> OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
1267-
> WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
1268-
> ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1269-
1270-
---------------------------------------
1271-
12721197
## sisteransi
12731198
License: MIT
12741199
By: Terkel Gjervig

packages/vitest/src/node/core.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class Vitest {
7878

7979
public packageInstaller: VitestPackageInstaller
8080

81+
/** TODO: rename to `_coreRootProject` */
8182
/** @internal */
8283
public coreWorkspaceProject!: TestProject
8384

@@ -93,7 +94,7 @@ export class Vitest {
9394
/** @deprecated use `_cachedSpecs` */
9495
projectTestFiles = this._cachedSpecs
9596

96-
/** @private */
97+
/** @internal */
9798
public _browserLastPort = defaultBrowserPort
9899

99100
/** @internal */

packages/vitest/src/node/logger.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,15 @@ export class Logger {
276276
+ '\nThis might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.',
277277
),
278278
)
279-
this.log(c.red(divider(c.bold(c.inverse(' Unhandled Errors ')))))
280-
this.log(errorMessage)
279+
this.error(c.red(divider(c.bold(c.inverse(' Unhandled Errors ')))))
280+
this.error(errorMessage)
281281
errors.forEach((err) => {
282282
this.printError(err, {
283283
fullStack: true,
284284
type: (err as ErrorWithDiff).type || 'Unhandled Error',
285285
})
286286
})
287-
this.log(c.red(divider()))
287+
this.error(c.red(divider()))
288288
}
289289

290290
printSourceTypeErrors(errors: TypeCheckError[]) {

packages/vitest/src/node/reporters/base.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,12 @@ export abstract class BaseReporter implements Reporter {
410410
const errorDivider = () => this.error(`${c.red(c.dim(divider(`[${current++}/${failedTotal}]`, undefined, 1)))}\n`)
411411

412412
if (failedSuites.length) {
413-
this.error(`${errorBanner(`Failed Suites ${failedSuites.length}`)}\n`)
413+
this.error(`\n${errorBanner(`Failed Suites ${failedSuites.length}`)}\n`)
414414
this.printTaskErrors(failedSuites, errorDivider)
415415
}
416416

417417
if (failedTests.length) {
418-
this.error(`${errorBanner(`Failed Tests ${failedTests.length}`)}\n`)
418+
this.error(`\n${errorBanner(`Failed Tests ${failedTests.length}`)}\n`)
419419
this.printTaskErrors(failedTests, errorDivider)
420420
}
421421

@@ -496,7 +496,7 @@ export abstract class BaseReporter implements Reporter {
496496
}
497497

498498
this.ctx.logger.error(
499-
`${c.red(c.bold(c.inverse(' FAIL ')))}${formatProjectName(projectName)} ${name}`,
499+
`${c.red(c.bold(c.inverse(' FAIL ')))} ${formatProjectName(projectName)}${name}`,
500500
)
501501
}
502502

packages/vitest/src/node/reporters/renderers/utils.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,16 @@ export function formatProjectName(name: string | undefined, suffix = ' ') {
239239
if (!name) {
240240
return ''
241241
}
242+
if (!c.isColorSupported) {
243+
return `|${name}|${suffix}`
244+
}
242245
const index = name
243246
.split('')
244247
.reduce((acc, v, idx) => acc + v.charCodeAt(0) + idx, 0)
245248

246-
const colors = [c.blue, c.yellow, c.cyan, c.green, c.magenta]
249+
const colors = [c.black, c.yellow, c.cyan, c.green, c.magenta]
247250

248-
return colors[index % colors.length](`|${name}|`) + suffix
251+
return c.inverse(colors[index % colors.length](` ${name} `)) + suffix
249252
}
250253

251254
export function withLabel(color: 'red' | 'green' | 'blue' | 'cyan' | 'yellow', label: string, message?: string) {

pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cli/test/__snapshots__/stacktraces.test.ts.snap

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`stacktrace filtering > filters stacktraces > stacktrace-filtering 1`] = `
4-
"⎯⎯ Failed Tests 1 ⎯⎯
4+
"
5+
⎯⎯ Failed Tests 1 ⎯⎯
56
67
FAIL error-with-stack.test.js > error in deps
78
Error: Something truly horrible has happened!
@@ -22,7 +23,8 @@ Error: Something truly horrible has happened!
2223
`;
2324

2425
exports[`stacktrace in vmThreads 1`] = `
25-
"⎯⎯ Failed Tests 1 ⎯⎯
26+
"
27+
⎯⎯ Failed Tests 1 ⎯⎯
2628
2729
FAIL error-with-stack.test.js > error in deps
2830
Error: Something truly horrible has happened!
@@ -44,7 +46,8 @@ Error: Something truly horrible has happened!
4446
`;
4547

4648
exports[`stacktrace should print error frame source file correctly > error-in-deps > error-in-deps 1`] = `
47-
"⎯⎯ Failed Tests 1 ⎯⎯
49+
"
50+
⎯⎯ Failed Tests 1 ⎯⎯
4851
4952
FAIL error-in-deps.test.js > error in deps
5053
ReferenceError: bar is not defined

test/cli/test/custom-pool.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { runVitest } from '../../test-utils'
44
test('can run custom pools with Vitest', async () => {
55
const vitest = await runVitest({
66
root: './fixtures/custom-pool',
7-
reporters: ['basic'],
7+
reporters: [['default', { isTTY: false }]],
88
})
99

1010
expect(vitest.stderr).toMatchInlineSnapshot(`

test/config/test/dangerously-ignore-unhandled-errors.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { expect, test } from 'vitest'
33
import { runVitest } from '../../test-utils'
44

55
test('{ dangerouslyIgnoreUnhandledErrors: true }', async () => {
6-
const { stderr, stdout, exitCode } = await runVitest({
6+
const { stderr, exitCode } = await runVitest({
77
root: 'fixtures/dangerously-ignore-unhandled-errors',
88
dangerouslyIgnoreUnhandledErrors: true,
99
})
1010

1111
expect(exitCode).toBe(0)
12-
expect(stdout).toMatch('Vitest caught 1 unhandled error during the test run')
12+
expect(stderr).toMatch('Vitest caught 1 unhandled error during the test run')
1313
expect(stderr).toMatch('Error: intentional unhandled error')
1414
})
1515

@@ -24,12 +24,12 @@ test('{ dangerouslyIgnoreUnhandledErrors: true } without reporter', async () =>
2424
})
2525

2626
test('{ dangerouslyIgnoreUnhandledErrors: false }', async () => {
27-
const { stderr, stdout, exitCode } = await runVitest({
27+
const { stderr, exitCode } = await runVitest({
2828
root: 'fixtures/dangerously-ignore-unhandled-errors',
2929
dangerouslyIgnoreUnhandledErrors: false,
3030
})
3131

3232
expect(exitCode).toBe(1)
33-
expect(stdout).toMatch('Vitest caught 1 unhandled error during the test run')
33+
expect(stderr).toMatch('Vitest caught 1 unhandled error during the test run')
3434
expect(stderr).toMatch('Error: intentional unhandled error')
3535
})

test/reporters/tests/indicator-position.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ test('should print correct indicator position', async () => {
1111
expect(code).toMatch(/\r\n/)
1212
expect(stderr).toBeTruthy()
1313
expect(stderr).toMatchInlineSnapshot(`
14-
"⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
14+
"
15+
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
1516
1617
FAIL indicator-position.test.js >
1718
AssertionError: expected 2 to be 3 // Object.is equality

test/reporters/tests/merge-reports.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test('merge reports', async () => {
3434
.replace(/Start at [\w\s:]+/, 'Start at <time>')
3535
const stderrArr = stderrDefault.split('\n')
3636
const stderrCheck = [
37-
...stderrArr.slice(3, 19),
37+
...stderrArr.slice(4, 19),
3838
...stderrArr.slice(21, -3),
3939
]
4040

test/test-utils/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ import { Readable, Writable } from 'node:stream'
88
import { fileURLToPath } from 'node:url'
99
import { dirname, resolve } from 'pathe'
1010
import { x } from 'tinyexec'
11+
import * as tinyrainbow from 'tinyrainbow'
1112
import { afterEach, onTestFinished, type WorkerGlobalState } from 'vitest'
1213
import { startVitest } from 'vitest/node'
1314
import { getCurrentTest } from 'vitest/suite'
1415
import { Cli } from './cli'
1516

17+
// override default colors to disable them in tests
18+
Object.assign(tinyrainbow.default, tinyrainbow.getDefaultColors())
19+
1620
interface VitestRunnerCLIOptions {
1721
std?: 'inherit'
1822
fails?: boolean
@@ -66,6 +70,10 @@ export async function runVitest(
6670
// "none" can be used to disable passing "reporter" option so that default value is used (it's not same as reporters: ["default"])
6771
...(reporters === 'none' ? {} : reporters ? { reporters } : { reporters: ['verbose'] }),
6872
...rest,
73+
env: {
74+
NO_COLOR: 'true',
75+
...rest.env,
76+
},
6977
}, {
7078
...viteOverrides,
7179
server: {

test/test-utils/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"devDependencies": {
1010
"tinyexec": "^0.3.0",
11+
"tinyrainbow": "^1.2.0",
1112
"vite": "latest",
1213
"vite-node": "workspace:*",
1314
"vitest": "workspace:*"

test/typescript/test/__snapshots__/runner.test.ts.snap

+5
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,15 @@ TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string,
9090
exports[`should fail > typechecks empty "include" but with tests 1`] = `
9191
"Testing types with tsc and vue-tsc is an experimental feature.
9292
Breaking changes might not follow SemVer, please pin Vitest's version when using it.
93+
⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯
94+
95+
Vitest caught 1 unhandled error during the test run.
96+
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
9397
9498
⎯⎯⎯⎯⎯⎯ Typecheck Error ⎯⎯⎯⎯⎯⎯⎯
9599
Error: error TS18003: No inputs were found in config file '<root>/tsconfig.vitest-temp.json'. Specified 'include' paths were '["src"]' and 'exclude' paths were '["**/dist/**"]'.
96100
101+
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
97102
98103
"
99104
`;

test/typescript/test/runner.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('ignoreSourceErrors', () => {
9292
const vitest = await runVitest({
9393
root: resolve(__dirname, '../fixtures/source-error'),
9494
})
95-
expect(vitest.stdout).toContain('Unhandled Errors')
95+
expect(vitest.stderr).toContain('Unhandled Errors')
9696
expect(vitest.stderr).toContain('Unhandled Source Error')
9797
expect(vitest.stderr).toContain('TypeCheckError: Cannot find name \'thisIsSourceError\'')
9898
})

test/watch/test/workspaces.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test("dynamic test case", () => {
2828

2929
async function startVitest() {
3030
const { vitest } = await runVitestCli(
31-
{ nodeOptions: { cwd: root, env: { TEST_WATCH: 'true' } } },
31+
{ nodeOptions: { cwd: root, env: { TEST_WATCH: 'true', NO_COLOR: 'true' } } },
3232
'--root',
3333
root,
3434
'--config',

0 commit comments

Comments
 (0)