Skip to content

fix(vitest): show beforeAll/afterAll errors in junit reporter#4819

Merged
sheremet-va merged 1 commit intovitest-dev:mainfrom
hi-ogawa:fix-junit-suite-errors
Dec 31, 2023
Merged

fix(vitest): show beforeAll/afterAll errors in junit reporter#4819
sheremet-va merged 1 commit intovitest-dev:mainfrom
hi-ogawa:fix-junit-suite-errors

Conversation

@hi-ogawa
Copy link
Copy Markdown
Collaborator

@hi-ogawa hi-ogawa commented Dec 29, 2023

Description

Closes #4516

This PR is an alternative of #4799 to surface beforeAll/afterAll errors in junit reporter.

This approach might not be the most sound one since it "mutates" test counts when beforeAll/afterAll failed, but this will ensure such suite-level errors will be recorded in the report.

The idea came from how default reporters shows "Failed Suites" separately from "Failed Tests":

const failedSuites = suites.filter(i => i.result?.errors)
const failedTests = tests.filter(i => i.result?.state === 'fail')
const failedTotal = countTestErrors(failedSuites) + countTestErrors(failedTests)
let current = 1
const errorDivider = () => logger.error(`${c.red(c.dim(divider(`[${current++}/${failedTotal}]`, undefined, 1)))}\n`)
if (failedSuites.length) {
logger.error(c.red(divider(c.bold(c.inverse(` Failed Suites ${failedSuites.length} `)))))
logger.error()
await this.printTaskErrors(failedSuites, errorDivider)
}

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JUNIT reporter doesn't mark test as failed if the beforeAll throws error

2 participants