Skip to content

Commit 23a7ee8

Browse files
Merge pull request #125 from buildkite/te-4879-vitest-collector-fails-to-write-report-because-of-undefined
Allow location to be optional in Vitest reporter
2 parents f948395 + 6095479 commit 23a7ee8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

e2e/vitest.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ describe('examples/vitest', () => {
127127
})
128128
}, 10000) // 10s timeout
129129

130+
test('it handles no location being present', (done) => {
131+
exec('npm test -- --includeTaskLocation false', { cwd, env }, (error, stdout, stderr) => {
132+
expect(stdout).toMatch(/.*Test Engine Sending: ({.*})/m);
133+
134+
const jsonMatch = stdout.match(/.*Test Engine Sending: ({.*})/m)
135+
const json = JSON.parse(jsonMatch[1])["data"]
136+
137+
// Uncomment to view the JSON
138+
// console.log(json)
139+
140+
expect(json).toHaveProperty("data[0].location", null)
141+
expect(json).toHaveProperty("data[1].location", null)
142+
143+
done()
144+
})
145+
}, 10000) // 10s timeout
146+
130147
describe('when test is pass but upload fails', () => {
131148
beforeAll(() => {
132149
// This will cause the upload to fail

vitest/reporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class VitestBuildkiteTestEngineReporter extends JsonReporter {
3939
id: id,
4040
scope: assertionResult.ancestorTitles.join(' ').trim(),
4141
name: assertionResult.title,
42-
location: prefixedTestPath
42+
location: (prefixedTestPath && assertionResult.location)
4343
? `${prefixedTestPath}:${assertionResult.location.line}`
4444
: null,
4545
file_name: prefixedTestPath,

0 commit comments

Comments
 (0)