Skip to content

Commit 1ba14a2

Browse files
authored
test: fix static-collect on rolldown (#9456)
1 parent de8a3a4 commit 1ba14a2

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/vitest/src/node/ast-collect.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ function createFileTask(
338338
file,
339339
tasks: [],
340340
mode,
341+
each: definition.dynamic,
341342
name: definition.name,
342343
fullName: createTaskName([latestSuite.fullName, definition.name]),
343344
fullTestName: createTaskName([latestSuite.fullTestName, definition.name]),
@@ -357,6 +358,7 @@ function createFileTask(
357358
id: '',
358359
suite: latestSuite,
359360
file,
361+
each: definition.dynamic,
360362
mode,
361363
context: {} as any, // not used on the server
362364
name: definition.name,

test/cli/test/static-collect.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CliOptions, TestCase, TestModule, TestSuite } from 'vitest/node'
22
import { expect, test } from 'vitest'
3-
import { createVitest } from 'vitest/node'
3+
import { createVitest, rolldownVersion } from 'vitest/node'
44

55
test('correctly collects a simple test', async () => {
66
const testModule = await collectTests(`
@@ -575,6 +575,7 @@ test('collects tests with each modifier', async () => {
575575
"each tests": {
576576
"barTest with each %i": {
577577
"dynamic": true,
578+
"each": true,
578579
"errors": [],
579580
"fullName": "each tests > barTest with each %i",
580581
"id": "-1732721377_0_2-dynamic",
@@ -584,6 +585,7 @@ test('collects tests with each modifier', async () => {
584585
},
585586
"test with each %i": {
586587
"dynamic": true,
588+
"each": true,
587589
"errors": [],
588590
"fullName": "each tests > test with each %i",
589591
"id": "-1732721377_0_0-dynamic",
@@ -593,6 +595,7 @@ test('collects tests with each modifier', async () => {
593595
},
594596
"testFoo with each %i": {
595597
"dynamic": true,
598+
"each": true,
596599
"errors": [],
597600
"fullName": "each tests > testFoo with each %i",
598601
"id": "-1732721377_0_1-dynamic",
@@ -812,15 +815,22 @@ function testTree(module: TestModule | TestSuite, tree: any = {}) {
812815
}
813816

814817
function testItem(testCase: TestCase) {
818+
let location: string | undefined
819+
if (testCase.location) {
820+
// rolldown's column is moved by 1 when using test.each/test.for
821+
const column = rolldownVersion && testCase.options.each
822+
? testCase.location.column - 1
823+
: testCase.location.column
824+
location = `${testCase.location.line}:${column}`
825+
}
815826
return {
816827
id: testCase.id,
817-
location: testCase.location
818-
? `${testCase.location.line}:${testCase.location.column}`
819-
: undefined,
828+
location,
820829
mode: testCase.options.mode,
821830
fullName: testCase.fullName,
822831
state: testCase.result().state,
823832
errors: testCase.result().errors || [],
824833
...(testCase.task.dynamic ? { dynamic: true } : {}),
834+
...(testCase.options.each ? { each: true } : {}),
825835
}
826836
}

0 commit comments

Comments
 (0)