diff --git a/package.json b/package.json index 5aab20f..f8781d6 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,17 @@ "xUnit", "TestNG", "parser", + "parse", "test", "testing", "results", "result", + "report", "automation", "mocha", "cucumber", "nUnit", + "MSTest", "testbeats" ], "author": "Anudeep ", diff --git a/src/index.d.ts b/src/index.d.ts index 85b16e3..f128d44 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,10 +1,69 @@ -import TestResult from "./models/TestResult"; -declare interface ParseOptions { +export interface ITestResult { + name: string; + total: number; + passed: number; + failed: number; + errors: number; + skipped: number; + retried: number; + duration: number; + status: string; + tags: string[]; + metadata: object; + suites: ITestSuite[]; +} + +export interface ITestSuite { + name: string; + total: number; + passed: number; + failed: number; + errors: number; + skipped: number; + duration: number; + status: string; + tags: string[]; + metadata: object; + cases: ITestCase[]; +} + +export interface ITestCase { + name: string; + total: number; + passed: number; + failed: number; + errors: number; + skipped: number; + duration: number; + status: string; + failure: string; + stack_trace: string; + tags: string[]; + metadata: object; + steps: ITestStep[]; + attachments: ITestAttachment[]; +} + +export interface ITestStep { + name: string; + duration: number; + status: string; + failure: string; + stack_trace: string; +} + +export interface ITestAttachment { + name: string; + path: string; +} + +export interface ParseOptions { type: string; files: string[]; } -export function parse(options: ParseOptions): TestResult; +export function parse(options: ParseOptions): ITestResult; +export function parseV2(options: ParseOptions): { result: ITestResult, errors: string[] }; export namespace parser { } \ No newline at end of file diff --git a/src/index.js b/src/index.js index a6c1f81..4bf1f6b 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,11 @@ function parse(options) { return parser.parse(options); } +function parseV2(options) { + return parser.parseV2(options); +} + module.exports = { - parse + parse, + parseV2 } \ No newline at end of file diff --git a/src/parsers/index.js b/src/parsers/index.js index 802b7ce..31715b9 100644 --- a/src/parsers/index.js +++ b/src/parsers/index.js @@ -68,6 +68,29 @@ function parse(options) { return merge(results); } +function parseV2(options) { + const parser = getParser(options.type); + const results = []; + const errors = []; + for (let i = 0; i < options.files.length; i++) { + const matched_files = getMatchingFilePaths(options.files[i]); + for (let j = 0; j < matched_files.length; j++) { + const file = matched_files[j]; + try { + results.push(parser.parse(file, options)); + } catch (error) { + errors.push(error.toString()); + console.error(error); + } + } + } + if (results.length > 0) { + return { result: merge(results), errors: errors }; + } + return { result: null, errors: errors }; +} + module.exports = { - parse + parse, + parseV2 } \ No newline at end of file diff --git a/tests/parser.junit.spec.js b/tests/parser.junit.spec.js index f2bcd81..1797a9e 100644 --- a/tests/parser.junit.spec.js +++ b/tests/parser.junit.spec.js @@ -604,6 +604,6 @@ describe('Parser - JUnit', () => { assert.equal(result.status, 'FAIL'); assert.equal(result.suites[1].cases[1].attachments[0].name, `test-failed-1.png`); assert.equal(result.suites[1].cases[1].attachments[0].path, `example-get-started-link-chromium/test-failed-1.png`); - }) + }); }); \ No newline at end of file diff --git a/tests/parser.v2.junit.spec.js b/tests/parser.v2.junit.spec.js new file mode 100644 index 0000000..d8f85f3 --- /dev/null +++ b/tests/parser.v2.junit.spec.js @@ -0,0 +1,38 @@ +const { parseV2 } = require('../src'); +const assert = require('assert'); + +describe('Parser V2 - JUnit', () => { + + const testDataPath = "tests/data/junit" + + it('with all files valid', () => { + const { result } = parseV2({ type: 'junit', ignore_error_count: true, files: [`${testDataPath}/playwright-failures.xml`]}); + assert.equal(result.total, 16); + assert.equal(result.passed, 14); + assert.equal(result.failed, 2); + assert.equal(result.status, 'FAIL'); + assert.equal(result.suites[1].cases[1].attachments[0].name, `test-failed-1.png`); + assert.equal(result.suites[1].cases[1].attachments[0].path, `example-get-started-link-chromium/test-failed-1.png`); + }); + + it('with one invalid file ', () => { + const { result, errors } = parseV2({ type: 'junit', ignore_error_count: true, files: [`${testDataPath}/playwright-failures.xml`, `${testDataPath}/playwright-failures.json`] }); + assert.equal(result.total, 16); + assert.equal(result.passed, 14); + assert.equal(result.failed, 2); + assert.equal(result.status, 'FAIL'); + assert.equal(result.suites[1].cases[1].attachments[0].name, `test-failed-1.png`); + assert.equal(result.suites[1].cases[1].attachments[0].path, `example-get-started-link-chromium/test-failed-1.png`); + assert.ok(errors.length === 1); + assert.ok(errors[0].includes(`Error`)); + }); + + it('with all files invalid', () => { + const { result, errors } = parseV2({ type: 'junit', ignore_error_count: true, files: [`${testDataPath}/invalid.xml`, `${testDataPath}/invalid.json`] }); + assert.equal(result, null); + assert.ok(errors.length === 2); + assert.ok(errors[0].includes(`Error`)); + assert.ok(errors[1].includes(`Error`)); + }); + +}); \ No newline at end of file