Skip to content

Commit

Permalink
fix: match jest json output by providing full stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
bard committed Jan 1, 2024
1 parent 09646f1 commit ad08c1f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class JsonReporter implements Reporter {
status: StatusMap[t.result?.state || t.mode] || 'skipped',
title: t.name,
duration: t.result?.duration,
failureMessages: t.result?.errors?.map(e => e.message) || [],
failureMessages: t.result?.errors?.map(e => e.stack) || [],
location: await this.getFailureLocation(t),
} as FormattedAssertionResult
}))
Expand Down
3 changes: 2 additions & 1 deletion test/reporters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"type": "module",
"private": true,
"scripts": {
"test": "NO_COLOR=1 vitest run"
"test": "NO_COLOR=1 vitest run",
"test:watch": "vitest"
},
"devDependencies": {
"flatted": "^3.2.9",
Expand Down
12 changes: 11 additions & 1 deletion test/reporters/tests/__snapshots__/json.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ exports[`json reporter > generates correct report 1`] = `
"",
],
"failureMessages": [
"expected 2 to deeply equal 1",
"AssertionError: expected 2 to deeply equal 1
at /home/bard/projects/vitest/test/reporters/fixtures/json-fail.test.ts:8:13
at file:///home/bard/projects/vitest/packages/runner/dist/index.js:127:14
at file:///home/bard/projects/vitest/packages/runner/dist/index.js:59:26
at runTest (file:///home/bard/projects/vitest/packages/runner/dist/index.js:671:17)
at runSuite (file:///home/bard/projects/vitest/packages/runner/dist/index.js:789:15)
at runFiles (file:///home/bard/projects/vitest/packages/runner/dist/index.js:838:5)
at startTests (file:///home/bard/projects/vitest/packages/runner/dist/index.js:847:3)
at file:///home/bard/projects/vitest/packages/vitest/dist/entry.js:112:7
at withEnv (file:///home/bard/projects/vitest/packages/vitest/dist/entry.js:79:5)
at run (file:///home/bard/projects/vitest/packages/vitest/dist/entry.js:101:3)",
],
"fullName": " should fail",
"location": {
Expand Down
32 changes: 26 additions & 6 deletions test/reporters/tests/__snapshots__/reporters.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,17 @@ exports[`json reporter (no outputFile entry) 1`] = `
],
"duration": 1.4422860145568848,
"failureMessages": [
"expected 2.23606797749979 to equal 2",
"AssertionError: expected 2.23606797749979 to equal 2
at /vitest/test/core/test/basic.test.ts:8:32
at /vitest/packages/vitest/dist/vi-ac0504aa.js:73:26
at runTest (/vitest/packages/vitest/dist/entry.js:1689:40)
at async runSuite (/vitest/packages/vitest/dist/entry.js:1741:13)
at async runSuites (/vitest/packages/vitest/dist/entry.js:1769:5)
at async startTests (/vitest/packages/vitest/dist/entry.js:1774:3)
at async /vitest/packages/vitest/dist/entry.js:1798:7
at async withEnv (/vitest/packages/vitest/dist/entry.js:1481:5)
at async run (/vitest/packages/vitest/dist/entry.js:1797:5)
at async file:///vitest/node_modules/.pnpm/[email protected]/node_modules/tinypool/dist/esm/worker.js:96:20",
],
"fullName": "suite inner suite Math.sqrt()",
"location": {
Expand Down Expand Up @@ -402,7 +412,17 @@ exports[`json reporter 1`] = `
],
"duration": 1.4422860145568848,
"failureMessages": [
"expected 2.23606797749979 to equal 2",
"AssertionError: expected 2.23606797749979 to equal 2
at /vitest/test/core/test/basic.test.ts:8:32
at /vitest/packages/vitest/dist/vi-ac0504aa.js:73:26
at runTest (/vitest/packages/vitest/dist/entry.js:1689:40)
at async runSuite (/vitest/packages/vitest/dist/entry.js:1741:13)
at async runSuites (/vitest/packages/vitest/dist/entry.js:1769:5)
at async startTests (/vitest/packages/vitest/dist/entry.js:1774:3)
at async /vitest/packages/vitest/dist/entry.js:1798:7
at async withEnv (/vitest/packages/vitest/dist/entry.js:1481:5)
at async run (/vitest/packages/vitest/dist/entry.js:1797:5)
at async file:///vitest/node_modules/.pnpm/[email protected]/node_modules/tinypool/dist/esm/worker.js:96:20",
],
"fullName": "suite inner suite Math.sqrt()",
"location": {
Expand Down Expand Up @@ -532,7 +552,7 @@ exports[`json reporter with outputFile 2`] = `
"title": "Math.sqrt()",
"duration": 1.4422860145568848,
"failureMessages": [
"expected 2.23606797749979 to equal 2"
"AssertionError: expected 2.23606797749979 to equal 2\\n at /vitest/test/core/test/basic.test.ts:8:32\\n at /vitest/packages/vitest/dist/vi-ac0504aa.js:73:26\\n at runTest (/vitest/packages/vitest/dist/entry.js:1689:40)\\n at async runSuite (/vitest/packages/vitest/dist/entry.js:1741:13)\\n at async runSuites (/vitest/packages/vitest/dist/entry.js:1769:5)\\n at async startTests (/vitest/packages/vitest/dist/entry.js:1774:3)\\n at async /vitest/packages/vitest/dist/entry.js:1798:7\\n at async withEnv (/vitest/packages/vitest/dist/entry.js:1481:5)\\n at async run (/vitest/packages/vitest/dist/entry.js:1797:5)\\n at async file:///vitest/node_modules/.pnpm/[email protected]/node_modules/tinypool/dist/esm/worker.js:96:20"
],
"location": {
"line": 8,
Expand Down Expand Up @@ -659,7 +679,7 @@ exports[`json reporter with outputFile in non-existing directory 2`] = `
"title": "Math.sqrt()",
"duration": 1.4422860145568848,
"failureMessages": [
"expected 2.23606797749979 to equal 2"
"AssertionError: expected 2.23606797749979 to equal 2\\n at /vitest/test/core/test/basic.test.ts:8:32\\n at /vitest/packages/vitest/dist/vi-ac0504aa.js:73:26\\n at runTest (/vitest/packages/vitest/dist/entry.js:1689:40)\\n at async runSuite (/vitest/packages/vitest/dist/entry.js:1741:13)\\n at async runSuites (/vitest/packages/vitest/dist/entry.js:1769:5)\\n at async startTests (/vitest/packages/vitest/dist/entry.js:1774:3)\\n at async /vitest/packages/vitest/dist/entry.js:1798:7\\n at async withEnv (/vitest/packages/vitest/dist/entry.js:1481:5)\\n at async run (/vitest/packages/vitest/dist/entry.js:1797:5)\\n at async file:///vitest/node_modules/.pnpm/[email protected]/node_modules/tinypool/dist/esm/worker.js:96:20"
],
"location": {
"line": 8,
Expand Down Expand Up @@ -786,7 +806,7 @@ exports[`json reporter with outputFile object 2`] = `
"title": "Math.sqrt()",
"duration": 1.4422860145568848,
"failureMessages": [
"expected 2.23606797749979 to equal 2"
"AssertionError: expected 2.23606797749979 to equal 2\\n at /vitest/test/core/test/basic.test.ts:8:32\\n at /vitest/packages/vitest/dist/vi-ac0504aa.js:73:26\\n at runTest (/vitest/packages/vitest/dist/entry.js:1689:40)\\n at async runSuite (/vitest/packages/vitest/dist/entry.js:1741:13)\\n at async runSuites (/vitest/packages/vitest/dist/entry.js:1769:5)\\n at async startTests (/vitest/packages/vitest/dist/entry.js:1774:3)\\n at async /vitest/packages/vitest/dist/entry.js:1798:7\\n at async withEnv (/vitest/packages/vitest/dist/entry.js:1481:5)\\n at async run (/vitest/packages/vitest/dist/entry.js:1797:5)\\n at async file:///vitest/node_modules/.pnpm/[email protected]/node_modules/tinypool/dist/esm/worker.js:96:20"
],
"location": {
"line": 8,
Expand Down Expand Up @@ -913,7 +933,7 @@ exports[`json reporter with outputFile object in non-existing directory 2`] = `
"title": "Math.sqrt()",
"duration": 1.4422860145568848,
"failureMessages": [
"expected 2.23606797749979 to equal 2"
"AssertionError: expected 2.23606797749979 to equal 2\\n at /vitest/test/core/test/basic.test.ts:8:32\\n at /vitest/packages/vitest/dist/vi-ac0504aa.js:73:26\\n at runTest (/vitest/packages/vitest/dist/entry.js:1689:40)\\n at async runSuite (/vitest/packages/vitest/dist/entry.js:1741:13)\\n at async runSuites (/vitest/packages/vitest/dist/entry.js:1769:5)\\n at async startTests (/vitest/packages/vitest/dist/entry.js:1774:3)\\n at async /vitest/packages/vitest/dist/entry.js:1798:7\\n at async withEnv (/vitest/packages/vitest/dist/entry.js:1481:5)\\n at async run (/vitest/packages/vitest/dist/entry.js:1797:5)\\n at async file:///vitest/node_modules/.pnpm/[email protected]/node_modules/tinypool/dist/esm/worker.js:96:20"
],
"location": {
"line": 8,
Expand Down

0 comments on commit ad08c1f

Please sign in to comment.