Skip to content

Commit 15e0af9

Browse files
authored
feat: support non-ascii characters in for/each title placeholders (#10773)
1 parent 75ed9ea commit 15e0af9

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎packages/vitest/src/runtime/runner/suite.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ function formatTitle(template: string, items: any[], idx: number) {
10191019

10201020
const isObjectItem = isObject(items[0])
10211021
function formatAttribute(s: string) {
1022-
return s.replace(/\$([$\w.]+)/g, (_, key: string) => {
1022+
return s.replace(/\$([$\p{ID_Continue}.]+)/gu, (_, key: string) => {
10231023
const isArrayKey = /^\d+$/.test(key)
10241024
if (!isObjectItem && !isArrayKey) {
10251025
return `$${key}`
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { runInlineTests } from '#test-utils'
2+
import { expect, test } from 'vitest'
3+
4+
test('formatting of non-ascii placeholders in test.each', async () => {
5+
const { stderr, ctx } = await runInlineTests({
6+
'basic.test.js': `
7+
test.each\`
8+
时间戳 | 结果
9+
\${1} | \${5}
10+
\${2} | \${10}
11+
\`('returns $结果 given $时间戳', ({ 结果, 时间戳 }) => {
12+
expect(结果).toBeGreaterThan(时间戳)
13+
})
14+
`,
15+
'vitest.config.js': {
16+
test: {
17+
globals: true,
18+
},
19+
},
20+
})
21+
22+
expect(stderr).toBe('')
23+
expect(ctx?.state.getTestModules()[0].children.array()).toStrictEqual(
24+
[
25+
expect.objectContaining({ name: 'returns 5 given 1' }),
26+
expect.objectContaining({ name: 'returns 10 given 2' }),
27+
],
28+
)
29+
})

‎test/unit/test/each.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ ${{ val: 3 }} | ${'b'} | ${'3b'}
225225
expect(a.val + b).toBe(expected)
226226
})
227227

228+
test.each`
229+
ω | Σ
230+
${1} | ${5}
231+
${2} | ${10}
232+
`('returns true when $ω is < $Σ', ({ ω, Σ }) => {
233+
expect(Σ).toBeGreaterThan(ω)
234+
})
235+
228236
test.each`
229237
a | b | expected
230238
${true} | ${true} | ${true}

0 commit comments

Comments
 (0)
Sponsor
SponsoredKunjungi sekarang
Promo