diff --git a/packages/vitest/src/node/reporters/json.ts b/packages/vitest/src/node/reporters/json.ts index 00c24888a572..d21b8520f050 100644 --- a/packages/vitest/src/node/reporters/json.ts +++ b/packages/vitest/src/node/reporters/json.ts @@ -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 })) diff --git a/test/reporters/package.json b/test/reporters/package.json index 1e7e0516113c..cff1348b5e26 100644 --- a/test/reporters/package.json +++ b/test/reporters/package.json @@ -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", diff --git a/test/reporters/tests/__snapshots__/json.test.ts.snap b/test/reporters/tests/__snapshots__/json.test.ts.snap index db3d630ef28a..e7742f6e3b23 100644 --- a/test/reporters/tests/__snapshots__/json.test.ts.snap +++ b/test/reporters/tests/__snapshots__/json.test.ts.snap @@ -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": { diff --git a/test/reporters/tests/__snapshots__/reporters.spec.ts.snap b/test/reporters/tests/__snapshots__/reporters.spec.ts.snap index 2c9d2d79a805..aead587ef802 100644 --- a/test/reporters/tests/__snapshots__/reporters.spec.ts.snap +++ b/test/reporters/tests/__snapshots__/reporters.spec.ts.snap @@ -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/tinypool@0.1.1/node_modules/tinypool/dist/esm/worker.js:96:20", ], "fullName": "suite inner suite Math.sqrt()", "location": { @@ -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/tinypool@0.1.1/node_modules/tinypool/dist/esm/worker.js:96:20", ], "fullName": "suite inner suite Math.sqrt()", "location": { @@ -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/tinypool@0.1.1/node_modules/tinypool/dist/esm/worker.js:96:20" ], "location": { "line": 8, @@ -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/tinypool@0.1.1/node_modules/tinypool/dist/esm/worker.js:96:20" ], "location": { "line": 8, @@ -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/tinypool@0.1.1/node_modules/tinypool/dist/esm/worker.js:96:20" ], "location": { "line": 8, @@ -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/tinypool@0.1.1/node_modules/tinypool/dist/esm/worker.js:96:20" ], "location": { "line": 8,