javascript

package
v0.1.157 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package javascript runs and parses test output for JS/TS test runners — vitest, jest, playwright. Produces the SOTA structured runtimev0.TestResponse the codefly platform expects (see proto/codefly/services/runtime/v0/runtime.proto).

Three parsers, two schemas:

  • ParseJestVitestJSON — vitest and jest emit nearly-identical JSON (vitest copied jest's reporter shape). One parser handles both. `--reporter=json` (vitest) or `--json` (jest); both produce the same envelope.

  • ParsePlaywrightJSON — playwright emits its own shape with nested suites + per-test retry results. `--reporter=json`.

Output retention rule (load-bearing): same as the python+go runners. PASSED + SKIPPED cases get empty captured_output; FAILED + ERRORED cases carry failure detail up to the per-case cap. JS test runners' JSON envelopes already follow this pattern — failureMessages array is empty for passed tests, populated for failed.

All parsers feed StructuredTestRun, the same convertible-to-proto type the python and go parsers use. ToProtoResponse(runner, suiteName, duration) returns runtimev0.TestResponse with both the structured tree and the legacy flat fields populated.

Index

Constants

View Source
const MaxCapturedOutputBytesPerCase = 32 * 1024

MaxCapturedOutputBytesPerCase mirrors the Go-runner + python-runner caps. Vitest/jest's `failureMessages[]` are typically a few KB (assertion message + Node stack trace); 32KiB allows fairly deep stacks without bloating the response.

Variables

This section is empty.

Functions

This section is empty.

Types

type LegacyTestSummary

type LegacyTestSummary struct {
	Run      int32
	Passed   int32
	Failed   int32
	Skipped  int32
	Coverage float32
	Failures []string
}

LegacyTestSummary returns the flat shape pre-overhaul callers used. Computed from the structured tree — single source of truth.

func (*LegacyTestSummary) SummaryLine

func (s *LegacyTestSummary) SummaryLine() string

SummaryLine returns "N passed, M failed, K skipped" — used by agent log lines.

type StructuredCase

type StructuredCase struct {
	Name      string
	FullName  string
	State     runtimev0.TestCaseState
	Duration  time.Duration
	File      string
	Line      int32
	Output    string
	Truncated bool
	Failure   *StructuredFailure
	// Retries is non-empty when the runner re-ran this case
	// (playwright `retries`). The case's top-level State reflects
	// the FINAL attempt; per-attempt detail lives here.
	Retries []*StructuredRetry
}

StructuredCase mirrors the python+go shape. Adds Retries for playwright's repeated-attempts-on-the-same-test feature.

type StructuredFailure

type StructuredFailure struct {
	Message string
	Detail  string
	Kind    runtimev0.TestFailureKind
}

StructuredFailure: same shape as the python parser's.

type StructuredRetry

type StructuredRetry struct {
	Attempt  int32
	State    runtimev0.TestCaseState
	Duration time.Duration
	Failure  *StructuredFailure
}

StructuredRetry is one attempt of a flaky test.

type StructuredSuite

type StructuredSuite struct {
	// Name is typically the file path; vitest/jest use absolute
	// paths in their JSON.
	Name     string
	File     string
	Duration time.Duration
	Cases    []*StructuredCase
}

StructuredSuite is one source-file's worth of cases.

type StructuredTestRun

type StructuredTestRun struct {
	// Suites — one per source file. Vitest/jest emit one
	// `testResults` entry per file; playwright nests differently
	// but we flatten to file-level for proto consistency.
	Suites []*StructuredSuite

	// CoveragePct is scraped from the runner's coverage summary
	// (vitest --coverage prints `All files | NN.NN%`; jest's
	// --coverage prints similar). 0 when not requested.
	CoveragePct float32
	// contains filtered or unexported fields
}

StructuredTestRun is the JS-side equivalent of the per-runner structured test types in core/runners/golang and core/runners/python. Building one is the parser's job; converting to proto is shared.

func ParseJestVitestJSON

func ParseJestVitestJSON(rawJSON string, coverage float32) *StructuredTestRun

ParseJestVitestJSON parses the JSON envelope vitest/jest produce and returns a StructuredTestRun. Empty raw, malformed JSON, or envelope-with-no-suites all surface as an empty run — the caller uses the runErr to decide if the runner crashed.

coverage is scraped separately from the runner's terminal output (the JSON's `coverageMap` carries per-file marks but not the summary percentage); pass coverage as 0 when not measured.

func ParsePlaywrightJSON

func ParsePlaywrightJSON(rawJSON string) *StructuredTestRun

ParsePlaywrightJSON parses Playwright's `--reporter=json` output and returns a StructuredTestRun. Coverage is not modeled — Playwright doesn't emit coverage in its standard JSON; users running coverage typically wrap with c8 or v8-coverage which produce separate artifacts.

func (*StructuredTestRun) LegacyTestSummary

func (r *StructuredTestRun) LegacyTestSummary() *LegacyTestSummary

LegacyTestSummary builds the flat summary from the structured tree.

func (*StructuredTestRun) ToProtoResponse

func (r *StructuredTestRun) ToProtoResponse(runner, suiteName string, duration time.Duration) *runtimev0.TestResponse

ToProtoResponse constructs the runtimev0.TestResponse with both structured (preferred) and legacy fields populated.

runner is "vitest" | "jest" | "playwright"; suiteName echoes TestRequest.suite. duration is the wall-clock for the whole run.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL