Skip to content

Commit

Permalink
test: update json reporter test
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 6, 2024
1 parent 89c7e80 commit 44d3649
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 13 additions & 3 deletions test/reporters/tests/__snapshots__/json.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ exports[`json reporter > generates correct report 1`] = `
{
"ancestorTitles": [],
"failureMessages": [
"expected 2 to deeply equal 1",
"AssertionError: expected 2 to deeply equal 1
at <root>/test/reporters/fixtures/json-fail.test.ts:8:13
at file://<root>/packages/runner/dist/index.js:135:14
at file://<root>/packages/runner/dist/index.js:60:26
at runTest (file://<root>/packages/runner/dist/index.js:767:17)
at runSuite (file://<root>/packages/runner/dist/index.js:895:15)
at runFiles (file://<root>/packages/runner/dist/index.js:944:5)
at startTests (file://<root>/packages/runner/dist/index.js:953:3)
at file://<root>/packages/vitest/src/runtime/runBaseTests.ts:43:7
at withEnv (file://<root>/packages/vitest/src/runtime/setup-node.ts:80:5)
at run (file://<root>/packages/vitest/src/runtime/runBaseTests.ts:29:9)",
],
"fullName": "should fail",
"location": {
"column": 13,
"line": 8,
"column": 1,
"line": 5,
},
"status": "failed",
"title": "should fail",
Expand Down
5 changes: 4 additions & 1 deletion test/reporters/tests/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { runVitest } from '../../test-utils'

describe('json reporter', async () => {
const root = resolve(__dirname, '../fixtures')
const projectRoot = resolve(__dirname, '../../..')

it('generates correct report', async () => {
const { stdout } = await runVitest({ reporters: 'json', root }, ['json-fail'])
const { stdout } = await runVitest({ reporters: 'json', root, includeTaskLocation: true }, ['json-fail'])

const data = JSON.parse(stdout)

Expand All @@ -24,6 +25,8 @@ describe('json reporter', async () => {

const result = failedTest.assertionResults[0]
delete result.duration
const rootRegexp = new RegExp(projectRoot, 'g')
result.failureMessages = result.failureMessages.map((m: string) => m.replace(rootRegexp, '<root>'))
expect(result).toMatchSnapshot()
}, 40000)

Expand Down

0 comments on commit 44d3649

Please sign in to comment.