@omgqa/reporter-sdk
v0.1.0
Published
Shared JUnit-XML builder + ingestion client for OMGQA test reporters (Jest/Vitest, Cypress, …).
Maintainers
Readme
@omgqa/reporter-sdk
Shared building blocks for OMGQA test reporters. It is the seed factored out of the
@omgqa/cypress-reporter inline helpers, so every JS reporter
(Jest/Vitest, Cypress, …) produces an identical wire format and shares retry/error behaviour.
It gives you two things:
- A Surefire-style JUnit document builder (
buildJUnitXml) with strict XML escaping. OmgqaClient— an HTTP client that publishes a run to the OMGQA ingestion API, with retry on transient failures and clear, status-carrying errors.
Install
npm install --save-dev @omgqa/reporter-sdkRequires Node >= 18 (uses the global fetch).
Quick start
const { OmgqaClient } = require('@omgqa/reporter-sdk');
const client = new OmgqaClient({
baseUrl: process.env.OMGQA_URL, // e.g. https://api.omgqa.app
apiKey: process.env.OMGQA_API_KEY, // omg_... (Agent role: testruns:write + findings:create)
projectId: process.env.OMGQA_PROJECT_ID,
mode: 'import', // 'import' (default, single call) or 'api'
ci: { branch: 'main', commit: 'abc123', environment: 'ci' },
});
// Normalized results: outcome is one of 'Passed' | 'Failed' | 'Skipped'.
const summary = await client.publish([
{ name: 'adds numbers', suite: 'math', outcome: 'Passed', durationMs: 12 },
{ name: 'breaks', suite: 'math', outcome: 'Failed', errorMessage: 'Expected 1\n at math.test.js:7' },
{ name: 'pending', suite: 'math', outcome: 'Skipped' },
]);
// summary -> { stored, failures, findingsCreated, findingsReopened, ... }Or build the client from environment variables (returns null when unconfigured, so reporters can
fail soft):
const { clientFromEnv } = require('@omgqa/reporter-sdk');
const client = clientFromEnv({ suiteName: 'jest' });
if (client) {
await client.publish(results);
}The normalized result shape
Every reporter maps its native results into this shape before calling the SDK:
| Field | Type | Notes |
| --- | --- | --- |
| name | string (required) | Full test name → <testcase name> |
| outcome | 'Passed' \| 'Failed' \| 'Skipped' (required) | |
| suite | string? | Logical suite/describe → classname (falls back to file, then tests) |
| file | string? | Source file |
| durationMs | number? | Wall-clock ms (rendered as seconds) |
| errorMessage | string? | Failure message + stack (Failed only) |
Modes
mode: 'import' (default) renders the results as a JUnit document and makes one call:
| Step | Call |
| --- | --- |
| Import run | POST /api/v1/projects/{projectId}/test-runs/import?format=junit |
CI context (branch, commit, environment, ciUrl) is appended as query params.
mode: 'api' uses the granular endpoints and sends native OMGQA outcomes:
| Step | Call |
| --- | --- |
| Create run | POST /api/v1/projects/{projectId}/test-runs |
| Register results (bulk, idempotent) | POST /api/v1/test-runs/{runId}/results |
| Complete run | POST /api/v1/test-runs/{runId}/complete |
Auth in both modes: Authorization: Bearer omg_….
Reliability
- Retry: network errors and
429/5xxresponses are retried (default 3 attempts) with exponential backoff (retryBaseMs * 2^n).4xx(other than 429) is not retried. - Timeout: each request is aborted after
timeoutMs(default 30s). - Errors: failures throw an
OmgqaErrorcarrying.statusand a trimmed.body.
API
| Export | Purpose |
| --- | --- |
| OmgqaClient | The ingestion client (.publish(results), .isConfigured()). |
| OmgqaError | Error with .status / .body. |
| buildJUnitXml(results, { suiteName }) | Render normalized results as JUnit XML. |
| xmlEscape(value) / stripInvalidXmlChars(value) | XML helpers. |
| clientFromEnv(overrides, env) | Build a client from env vars (or null). |
| ciFromEnv(env) | Read CI context (GitHub Actions defaults). |
| logSummary(logger, summary) | Print the standard one-line summary. |
| OUTCOME | { Passed, Failed, Skipped }. |
Tests
node --testCovers the JUnit builder (escaping, failure/skip rendering, classname fallbacks, empty list) and the client (request shaping, CI query params, api-mode flow, retry/backoff, non-retryable 4xx).
