Skip to content
Draft
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Keep invalid JSON fixtures unformatted for parser tests
src/tests/fixtures/allure/parser/malformed-result.json
AGENTS.md
1 change: 1 addition & 0 deletions AGENTS.md
12 changes: 8 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# CLAUDE.md

Note: `AGENTS.md` is a symlink to this file for tooling that looks for that filename.

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

QAS CLI (`qas-cli`) is a Node.js CLI tool for uploading test automation results (JUnit XML / Playwright JSON) to [QA Sphere](https://qasphere.com/). It matches test case markers (e.g., `PRJ-123`) in report files to QA Sphere test cases, creates or reuses test runs, and uploads results with optional attachments.
QAS CLI (`qas-cli`) is a Node.js CLI tool for uploading test automation results (JUnit XML / Playwright JSON / Allure) to [QA Sphere](https://qasphere.com/). It matches test case markers (e.g., `PRJ-123`) in report files to QA Sphere test cases, creates or reuses test runs, and uploads results with optional attachments.

## Commands

Expand All @@ -29,15 +31,15 @@ Node.js compatibility tests: `cd mnode-test && ./docker-test.sh` (requires Docke
### Entry Point & CLI Framework

- `src/bin/qasphere.ts` — Entry point (`#!/usr/bin/env node`). Validates Node version, delegates to `run()`.
- `src/commands/main.ts` — Yargs setup. Registers two commands (`junit-upload`, `playwright-json-upload`) as instances of the same `ResultUploadCommandModule` class.
- `src/commands/main.ts` — Yargs setup. Registers three commands (`junit-upload`, `playwright-json-upload`, `allure-upload`) as instances of the same `ResultUploadCommandModule` class.
- `src/commands/resultUpload.ts` — `ResultUploadCommandModule` defines CLI options shared by both commands. Loads env vars, then delegates to `ResultUploadCommandHandler`.

### Core Upload Pipeline (src/utils/result-upload/)

The upload flow has two stages handled by two classes:

1. **`ResultUploadCommandHandler`** — Orchestrates the overall flow:
- Parses report files using the appropriate parser (JUnit XML or Playwright JSON)
- Parses report files using the appropriate parser (JUnit XML, Playwright JSON, or Allure)
- Detects project code from test case names (or from `--run-url`)
- Creates a new test run (or reuses an existing one if title conflicts)
- Delegates actual result uploading to `ResultUploader`
Expand All @@ -51,6 +53,7 @@ The upload flow has two stages handled by two classes:

- `junitXmlParser.ts` — Parses JUnit XML via `xml2js` + Zod validation. Extracts attachments from `[[ATTACHMENT|path]]` markers in system-out/failure/error/skipped elements.
- `playwrightJsonParser.ts` — Parses Playwright JSON report. Supports two test case linking methods: (1) test annotations with `type: "test case"` and URL description, (2) marker in test name. Handles nested suites recursively.
- `allureParser.ts` — Parses Allure results directories (Allure 2 JSON). Supports status mapping, attachments, and TMS link-based test case markers.
- `types.ts` — Shared `TestCaseResult` and `Attachment` interfaces used by both parsers.

### API Layer (src/api/)
Expand All @@ -72,9 +75,10 @@ Composable fetch wrappers using higher-order functions:

Tests use **Vitest** with **MSW** (Mock Service Worker) for API mocking. Test files are in `src/tests/`:

- `result-upload.spec.ts` — Integration tests for the full upload flow (both JUnit and Playwright), with MSW intercepting all API calls
- `result-upload.spec.ts` — Integration tests for the full upload flow (JUnit, Playwright, Allure), with MSW intercepting all API calls
- `junit-xml-parsing.spec.ts` — Unit tests for JUnit XML parser
- `playwright-json-parsing.spec.ts` — Unit tests for Playwright JSON parser
- `allure-parsing.spec.ts` — Unit tests for Allure results parser
- `template-string-processing.spec.ts` — Unit tests for run name template processing

Test fixtures live in `src/tests/fixtures/` (XML files, JSON files, and mock test case data).
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/commands/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Required variables: ${qasEnvs.join(', ')}
)
.command(new ResultUploadCommandModule('junit-upload'))
.command(new ResultUploadCommandModule('playwright-json-upload'))
.command(new ResultUploadCommandModule('allure-upload'))
.demandCommand(1, '')
.help('h')
.alias('h', 'help')
Expand Down
45 changes: 28 additions & 17 deletions src/commands/resultUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import {
const commandTypeDisplayStrings: Record<UploadCommandType, string> = {
'junit-upload': 'JUnit XML',
'playwright-json-upload': 'Playwright JSON',
'allure-upload': 'Allure',
}

const commandTypeFileExtensions: Record<UploadCommandType, string> = {
'junit-upload': 'xml',
'playwright-json-upload': 'json',
'allure-upload': '',
}

export class ResultUploadCommandModule implements CommandModule<unknown, ResultUploadCommandArgs> {
Expand All @@ -25,6 +27,9 @@ export class ResultUploadCommandModule implements CommandModule<unknown, ResultU
}

get describe() {
if (this.type === 'allure-upload') {
return `Upload ${commandTypeDisplayStrings[this.type]} results directories to a new or existing test run`
}
return `Upload ${commandTypeDisplayStrings[this.type]} files to a new or existing test run`
}

Expand Down Expand Up @@ -82,40 +87,38 @@ export class ResultUploadCommandModule implements CommandModule<unknown, ResultU
},
})

argv.positional('files', {
describe:
this.type === 'allure-upload'
? 'Allure results directory paths'
: 'Report file paths to upload',
type: 'string',
})

const examplePath = getExamplePath(this.type)

argv.example(
`$0 ${this.type} -r https://qas.eu1.qasphere.com/project/P1/run/23 ./test-results.${
commandTypeFileExtensions[this.type]
}`,
`$0 ${this.type} -r https://qas.eu1.qasphere.com/project/P1/run/23 ${examplePath}`,
'Upload results to existing run ID 23 of project P1'
)

argv.example(
`$0 ${this.type} ./test-results.${commandTypeFileExtensions[this.type]}`,
`$0 ${this.type} ${examplePath}`,
'Create a new test run with default name template and upload results. Project code is detected from test case markers in the results'
)

argv.example(
`$0 ${this.type} --project-code P1 --run-name "v1.4.4-rc5" ./test-results.${
commandTypeFileExtensions[this.type]
}`,
`$0 ${this.type} --project-code P1 --run-name "v1.4.4-rc5" ${examplePath}`,
'Create a new test run with name template without any placeholders and upload results'
)

argv.example(
`$0 ${
this.type
} --project-code P1 --run-name "CI Build {env:BUILD_NUMBER} - {YYYY}-{MM}-{DD}" ./test-results.${
commandTypeFileExtensions[this.type]
}`,
`$0 ${this.type} --project-code P1 --run-name "CI Build {env:BUILD_NUMBER} - {YYYY}-{MM}-{DD}" ${examplePath}`,
'Create a new test run with name template using environment variable and date placeholders and upload results'
)

argv.example(
`$0 ${
this.type
} --project-code P1 --run-name "Nightly Tests {YYYY}/{MM}/{DD} {HH}:{mm}" --create-tcases ./test-results.${
commandTypeFileExtensions[this.type]
}`,
`$0 ${this.type} --project-code P1 --run-name "Nightly Tests {YYYY}/{MM}/{DD} {HH}:{mm}" --create-tcases ${examplePath}`,
'Create a new test run with name template using date and time placeholders and create test cases for results without valid markers and upload results'
)

Expand Down Expand Up @@ -170,3 +173,11 @@ ${chalk.bold('Run name template placeholders:')}
await handler.handle()
}
}

const getExamplePath = (type: UploadCommandType) => {
const extension = commandTypeFileExtensions[type]
if (!extension) {
return './allure-results'
}
return `./test-results.${extension}`
}
129 changes: 129 additions & 0 deletions src/tests/allure-parsing.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { beforeAll, describe, expect, test, vi } from 'vitest'
import { parseAllureResults } from '../utils/result-upload/allureParser'

const allureParserBasePath = './src/tests/fixtures/allure/parser'

let testcases: Awaited<ReturnType<typeof parseAllureResults>>

describe('Allure results parsing', () => {
beforeAll(async () => {
testcases = await parseAllureResults(allureParserBasePath, allureParserBasePath, {
skipStdout: 'never',
skipStderr: 'never',
})
Comment on lines +8 to +13
Copy link

Choose a reason for hiding this comment

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

Missing test coverage for skipStdout/skipStderr on-success behavior: Every test here uses skipStdout: 'never' and skipStderr: 'never'. The buildMessage function has branching logic for on-success that is never exercised. The JUnit and Playwright parser tests each have dedicated tests for this behavior.

Suggested additions:

  • Test that message is omitted for passed tests when skipStdout is on-success
  • Test that trace is omitted for passed tests when skipStderr is on-success
  • Test that both are still included for failed tests with on-success options

})

test('Should parse results directory and ignore non-result files', () => {
expect(testcases).toHaveLength(9)

const statuses = testcases.map((tc) => tc.status)
expect(statuses).toContain('passed')
expect(statuses).toContain('failed')
expect(statuses).toContain('blocked')
expect(statuses).toContain('skipped')
})

test('Should derive folders from labels with correct priority', () => {
const suiteCase = testcases.find((tc) => tc.name.includes('Login happy path'))
const parentCase = testcases.find((tc) => tc.name.includes('Payment error'))
const featureCase = testcases.find((tc) => tc.name.includes('Broken flow'))
const packageCase = testcases.find((tc) => tc.name.includes('Skipped TEST-003'))
const noLabelCase = testcases.find((tc) => tc.name.includes('Unknown status test'))

expect(suiteCase?.folder).toBe('SuiteA')
expect(parentCase?.folder).toBe('ParentOnly')
expect(featureCase?.folder).toBe('FeatureOnly')
expect(packageCase?.folder).toBe('pkg.module')
expect(noLabelCase?.folder).toBe('')
})

test('Should calculate durations from start/stop timestamps', () => {
const suiteCase = testcases.find((tc) => tc.name.includes('Login happy path'))
const parentCase = testcases.find((tc) => tc.name.includes('Payment error'))

expect(suiteCase?.timeTaken).toBe(1500)
expect(parentCase?.timeTaken).toBe(600)
})

test('Should map Allure statuses to QA Sphere statuses', () => {
const brokenCase = testcases.find((tc) => tc.name.includes('Broken flow'))
const unknownCase = testcases.find((tc) => tc.name.includes('Unknown status test'))

expect(brokenCase?.status).toBe('blocked')
expect(unknownCase?.status).toBe('passed')
})

test('Should build messages from status details', () => {
const parentCase = testcases.find((tc) => tc.name.includes('Payment error'))
const brokenCase = testcases.find((tc) => tc.name.includes('Broken flow'))
const skippedCase = testcases.find((tc) => tc.name.includes('Skipped TEST-003'))

expect(parentCase?.message).toContain('AssertionError')
expect(parentCase?.message).toContain('Trace line 1')
expect(brokenCase?.message).toContain('NullPointerException')
expect(skippedCase?.message).toBe('')
})

test('Should resolve attachments from result directory', () => {
const parentCase = testcases.find((tc) => tc.name.includes('Payment error'))
expect(parentCase?.attachments).toHaveLength(1)
expect(parentCase?.attachments[0].filename).toBe('failure-log.txt')
expect(parentCase?.attachments[0].buffer).not.toBeNull()
})

test('Should handle missing or empty attachments arrays', () => {
const suiteCase = testcases.find((tc) => tc.name.includes('Login happy path'))
const brokenCase = testcases.find((tc) => tc.name.includes('Broken flow'))

expect(suiteCase?.attachments).toHaveLength(0)
expect(brokenCase?.attachments).toHaveLength(0)
})

test('Should keep marker when present in test name', () => {
const suiteCase = testcases.find((tc) => tc.name.includes('Login happy path'))
expect(suiteCase?.name).toContain('TEST-002')
})

test('Should extract markers from TMS links', () => {
const tmsUrlCase = testcases.find((tc) => tc.name.includes('TMS URL linked test'))
const tmsNameCase = testcases.find((tc) => tc.name.includes('TMS name linked test'))

expect(tmsUrlCase?.name.startsWith('ALR-123:')).toBe(true)
expect(tmsNameCase?.name.startsWith('TESTCASE-002:')).toBe(true)
})

test('Should keep parameterized results as separate entries', () => {
const paramCases = testcases.filter((tc) => tc.name.startsWith('Param test'))
expect(paramCases).toHaveLength(2)
})

test('Should handle empty results directory', async () => {
const emptyResults = await parseAllureResults(
'./src/tests/fixtures/allure/empty',
'./src/tests/fixtures/allure/empty',
{
skipStdout: 'never',
skipStderr: 'never',
}
)
expect(emptyResults).toHaveLength(0)
})

test('Should skip malformed or invalid result files with warnings', async () => {
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})

const results = await parseAllureResults(allureParserBasePath, allureParserBasePath, {
skipStdout: 'never',
skipStderr: 'never',
})

expect(results).toHaveLength(9)
expect(warnSpy.mock.calls.length).toBeGreaterThanOrEqual(2)

const warnings = warnSpy.mock.calls.map((call) => String(call[0]))
expect(warnings.some((w) => w.includes('malformed-result.json'))).toBe(true)
expect(warnings.some((w) => w.includes('invalid-schema-result.json'))).toBe(true)

warnSpy.mockRestore()
})
})
8 changes: 8 additions & 0 deletions src/tests/fixtures/allure/empty-tsuite/tc-2-result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Test cart TEST-002",
"status": "passed",
"uuid": "et-2",
"start": 1700000200000,
"stop": 1700000200300,
"labels": [{ "name": "suite", "value": "ui.cart.spec.ts" }]
}
Empty file.
1 change: 1 addition & 0 deletions src/tests/fixtures/allure/matching-tcases/attachment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
matching attachment
15 changes: 15 additions & 0 deletions src/tests/fixtures/allure/matching-tcases/tc-2-result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Test cart TEST-002",
"status": "passed",
"uuid": "tc-2",
"start": 1700000000000,
"stop": 1700000000500,
"attachments": [
{
"name": "Attachment",
"source": "attachment.txt",
"type": "text/plain"
}
],
"labels": [{ "name": "suite", "value": "ui.cart.spec.ts" }]
}
15 changes: 15 additions & 0 deletions src/tests/fixtures/allure/matching-tcases/tc-3-result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Test checkout TEST-003",
"status": "passed",
"uuid": "tc-3",
"start": 1700000001000,
"stop": 1700000001400,
"attachments": [
{
"name": "Attachment",
"source": "attachment.txt",
"type": "text/plain"
}
],
"labels": [{ "name": "suite", "value": "ui.cart.spec.ts" }]
}
15 changes: 15 additions & 0 deletions src/tests/fixtures/allure/matching-tcases/tc-4-result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "About page content TEST-004",
"status": "passed",
"uuid": "tc-4",
"start": 1700000002000,
"stop": 1700000002700,
"attachments": [
{
"name": "Attachment",
"source": "attachment.txt",
"type": "text/plain"
}
],
"labels": [{ "name": "suite", "value": "ui.contents.spec.ts" }]
}
15 changes: 15 additions & 0 deletions src/tests/fixtures/allure/matching-tcases/tc-5-result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Menu page content TEST-005",
"status": "passed",
"uuid": "tc-5",
"start": 1700000003000,
"stop": 1700000003600,
"attachments": [
{
"name": "Attachment",
"source": "attachment.txt",
"type": "text/plain"
}
],
"labels": [{ "name": "suite", "value": "ui.contents.spec.ts" }]
}
15 changes: 15 additions & 0 deletions src/tests/fixtures/allure/matching-tcases/tc-6-result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Navigation bar items TEST-006",
"status": "failed",
"uuid": "tc-6",
"start": 1700000004000,
"stop": 1700000004800,
"attachments": [
{
"name": "Attachment",
"source": "attachment.txt",
"type": "text/plain"
}
],
"labels": [{ "name": "suite", "value": "ui.contents.spec.ts" }]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
attachment content
Loading