Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make json reporter easier to extend #7103

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/vitest/src/node/reporters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class JsonReporter implements Reporter {
this.start = Date.now()
}

protected async logTasks(files: File[], coverageMap?: CoverageMap | null) {
protected async logTasks(files: File[], coverageMap?: CoverageMap | null): Promise<JsonTestResults> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logTasks no longer logs tasks. Should we change a name?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah... it generates the logs, it just leaves writing up to the caller.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the name then

const suites = getSuites(files)
const numTotalTestSuites = suites.length
const tests = getTests(files)
Expand Down Expand Up @@ -176,7 +176,7 @@ export class JsonReporter implements Reporter {
})
}

const result: JsonTestResults = {
return {
numTotalTestSuites,
numPassedTestSuites,
numFailedTestSuites,
Expand All @@ -192,12 +192,11 @@ export class JsonReporter implements Reporter {
testResults,
coverageMap,
}

await this.writeReport(JSON.stringify(result))
}

async onFinished(files = this.ctx.state.getFiles(), _errors: unknown[] = [], coverageMap?: unknown) {
await this.logTasks(files, coverageMap as CoverageMap)
const results = await this.logTasks(files, coverageMap as CoverageMap)
await this.writeReport(JSON.stringify(results))
}

/**
Expand Down
Loading