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

add type exports to the JSON reporter #5068

Closed
4 tasks done
david-morris opened this issue Jan 29, 2024 · 1 comment · Fixed by #5081
Closed
4 tasks done

add type exports to the JSON reporter #5068

david-morris opened this issue Jan 29, 2024 · 1 comment · Fixed by #5081
Labels
enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@david-morris
Copy link

david-morris commented Jan 29, 2024

Clear and concise description of the problem

I want to summarize json vitest output in my CI using typescript. I want to import types for IDE functionality and the ability to type-check my summary script.

Suggested solution

Export the existing types so that they could be imported from "vitest/reporters".

Alternative

Factor a helper out of logTasks method of JsonReporter so that we can use indexed types for the JSON contents

Additional context

This change would make it possible to type-check for any changes to the json format affecting an automated system reading that json output.

Keep in mind that there's no "vitest/reporters/json" because of the build step.

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Jan 30, 2024

Exposing the type sounds like a nice addition to me.

For the time being, I think you can manually copy-paste types from here since these types are self-contained:

type Status = 'passed' | 'failed' | 'skipped' | 'pending' | 'todo' | 'disabled'
type Milliseconds = number
interface Callsite { line: number; column: number }
const StatusMap: Record<TaskState, Status> = {
fail: 'failed',
only: 'pending',
pass: 'passed',
run: 'pending',
skip: 'skipped',
todo: 'todo',
}
interface FormattedAssertionResult {
ancestorTitles: Array<string>
fullName: string
status: Status
title: string
duration?: Milliseconds | null
failureMessages: Array<string>
location?: Callsite | null
}
interface FormattedTestResult {
message: string
name: string
status: 'failed' | 'passed'
startTime: number
endTime: number
assertionResults: Array<FormattedAssertionResult>
// summary: string
// coverage: unknown
}
interface FormattedTestResults {
numFailedTests: number
numFailedTestSuites: number
numPassedTests: number
numPassedTestSuites: number
numPendingTests: number
numPendingTestSuites: number
numTodoTests: number
numTotalTests: number
numTotalTestSuites: number
startTime: number
success: boolean
testResults: Array<FormattedTestResult>
// coverageMap?: CoverageMap | null | undefined
// numRuntimeErrorTestSuites: number
// snapshot: SnapshotSummary
// wasInterrupted: boolean
}

Example https://stackblitz.com/edit/vitest-dev-vitest-6eyewm?file=example.ts

@hi-ogawa hi-ogawa added enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) labels Jan 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
2 participants