From 84bbbadece3199ec187e809436c5742e242041ea Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Thu, 29 Feb 2024 12:04:22 -0500 Subject: [PATCH 1/3] test consistency fix --- tests/parser.junit.spec.js | 278 ++++++++++++++++++------------------- 1 file changed, 139 insertions(+), 139 deletions(-) diff --git a/tests/parser.junit.spec.js b/tests/parser.junit.spec.js index ae5add7..af2efe7 100644 --- a/tests/parser.junit.spec.js +++ b/tests/parser.junit.spec.js @@ -349,87 +349,87 @@ describe('Parser - JUnit', () => { it('parse newman with failures', () => { const result = parse({ type: 'junit', files: [`${testDataPath}/newman-failures.xml`] }); assert.deepEqual(result, { - "id": "", - "name": "MainApi", - "total": 3, - "passed": 1, - "failed": 2, - "errors": 0, - "skipped": 0, - "retried": 0, - "duration": 37506, - "status": "FAIL", - "suites": [ + id: "", + name: "MainApi", + total: 3, + passed: 1, + failed: 2, + errors: 0, + skipped: 0, + retried: 0, + duration: 37506, + status: "FAIL", + suites: [ { - "id": "", - "name": "Main / GetSectors", - "total": 2, - "passed": 0, - "failed": 2, - "errors": 0, - "skipped": 0, - "duration": 446, - "status": "FAIL", + id: "", + name: "Main / GetSectors", + total: 2, + passed: 0, + failed: 2, + errors: 0, + skipped: 0, + duration: 446, + status: "FAIL", meta_data: new Map(), - "cases": [ + cases: [ { - "id": "", - "name": "Sectors - Verify 'Residential' is in list", - "total": 0, - "passed": 0, - "failed": 0, - "errors": 0, - "skipped": 0, - "duration": 446, - "status": "FAIL", - "failure": "expected to include 'Residntial'", - "stack_trace": "", - "meta_data": new Map(), - "steps": [] + id: "", + name: "Sectors - Verify 'Residential' is in list", + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 446, + status: "FAIL", + failure: "expected to include 'Residntial'", + stack_trace: "", + meta_data: new Map(), + steps: [] }, { - "id": "", - "name": "Sectors EndPoint - returns a JSON response", - "total": 0, - "passed": 0, - "failed": 0, - "errors": 0, - "skipped": 0, - "duration": 446, - "status": "PASS", - "failure": "", - "stack_trace": "", - "meta_data": new Map(), - "steps": [] + id: "", + name: "Sectors EndPoint - returns a JSON response", + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 446, + status: "PASS", + failure: "", + stack_trace: "", + meta_data: new Map(), + steps: [] } ] }, { - "id": "", - "name": "Main / Verifyresponsedata-MarketAsset", - "total": 1, - "passed": 1, - "failed": 0, - "errors": 0, - "skipped": 0, - "duration": 634, - "status": "PASS", + id: "", + name: "Main / Verifyresponsedata-MarketAsset", + total: 1, + passed: 1, + failed: 0, + errors: 0, + skipped: 0, + duration: 634, + status: "PASS", meta_data: new Map(), - "cases": [ + cases: [ { - "id": "", - "name": "Market Asset(id-387) response - data is as expected", - "total": 0, - "passed": 0, - "failed": 0, - "errors": 0, - "skipped": 0, - "duration": 634, - "status": "PASS", - "failure": "", - "stack_trace": "", - "meta_data": new Map(), - "steps": [] + id: "", + name: "Market Asset(id-387) response - data is as expected", + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 634, + status: "PASS", + failure: "", + stack_trace: "", + meta_data: new Map(), + steps: [] } ] } @@ -440,88 +440,88 @@ describe('Parser - JUnit', () => { it('parse spekt/junit.testlogger', () => { const result = parse({ type: 'junit', files: [`${testDataPath}/junit.testlogger.xml`] }); assert.deepEqual(result, { - "id": "", - "name": "", - "total": 3, - "passed": 2, - "failed": 1, - "errors": 0, - "skipped": 1, - "retried": 0, - "duration": 870.6800000000001, - "status": "FAIL", - "suites": [ + id: "", + name: "", + total: 3, + passed: 2, + failed: 1, + errors: 0, + skipped: 1, + retried: 0, + duration: 870.6800000000001, + status: "FAIL", + suites: [ { - "id": "", - "name": "JUnit.Xml.TestLogger.NetCore.Tests.dll", - "total": 3, - "passed": 2, - "failed": 1, - "errors": 0, - "skipped": 1, - "duration": 870.6800000000001, - "status": "FAIL", + id: "", + name: "JUnit.Xml.TestLogger.NetCore.Tests.dll", + total: 3, + passed: 2, + failed: 1, + errors: 0, + skipped: 1, + duration: 870.6800000000001, + status: "FAIL", meta_data: new Map(), - "cases": [ + cases: [ { - "id": "", - "name": "TestD", - "total": 0, - "passed": 0, - "failed": 0, - "errors": 0, - "skipped": 0, - "duration": 2.195, - "status": "PASS", - "failure": "", - "stack_trace": "", + id: "", + name: "TestD", + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 2.195, + status: "PASS", + failure: "", + stack_trace: "", "meta_data": new Map(), - "steps": [] + steps: [] }, { - "id": "", - "name": "TestC", - "total": 0, - "passed": 0, - "failed": 0, - "errors": 0, - "skipped": 0, - "duration": 1.109, - "status": "FAIL", - "failure": "TearDown : System.InvalidOperationException : Operation is not valid due to the current state of the object.", - "stack_trace": "", + id: "", + name: "TestC", + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 1.109, + status: "FAIL", + failure: "TearDown : System.InvalidOperationException : Operation is not valid due to the current state of the object.", + stack_trace: "", "meta_data": new Map(), - "steps": [] + steps: [] }, { - "id": "", - "name": "InconclusiveTest", - "total": 0, - "passed": 0, - "failed": 0, - "errors": 0, - "skipped": 0, - "duration": 0.7200000000000001, - "status": "PASS", - "failure": "", - "stack_trace": "", + id: "", + name: "InconclusiveTest", + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 0.7200000000000001, + status: "PASS", + failure: "", + stack_trace: "", "meta_data": new Map(), - "steps": [] + steps: [] }, { - "id": "", - "name": "Ignored", - "total": 0, - "passed": 0, - "failed": 0, - "errors": 0, - "skipped": 0, - "duration": 0.29500000000000004, - "status": "PASS", - "failure": "", - "stack_trace": "", + id: "", + name: "Ignored", + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 0.29500000000000004, + status: "PASS", + failure: "", + stack_trace: "", "meta_data": new Map(), - "steps": [] + steps: [] } ] } From 2a3f74f3b088c2fd7d4021c72c9471098a2159c7 Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Thu, 29 Feb 2024 12:06:01 -0500 Subject: [PATCH 2/3] fix for junit suite property inheritence --- src/parsers/junit.js | 18 ++++++++++-------- tests/parser.junit.spec.js | 23 +++++++++++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/parsers/junit.js b/src/parsers/junit.js index 0d39c68..af0e6f3 100644 --- a/src/parsers/junit.js +++ b/src/parsers/junit.js @@ -3,12 +3,14 @@ const { getJsonFromXMLFile } = require('../helpers/helper'); const TestResult = require('../models/TestResult'); const TestSuite = require('../models/TestSuite'); const TestCase = require('../models/TestCase'); +const JUnitTypes = import('./junit.result'); -function getTestCase(rawCase) { +function getTestCase(rawCase, suite_meta) { const test_case = new TestCase(); test_case.name = rawCase["@_name"]; test_case.duration = rawCase["@_time"] * 1000; - setMetaData(rawCase.properties, test_case); + test_case.meta_data = new Map(suite_meta); + setMetaData(rawCase, test_case); if (rawCase.failure && rawCase.failure.length > 0) { test_case.status = 'FAIL'; test_case.setFailure(rawCase.failure[0]["@_message"]); @@ -35,11 +37,11 @@ function getTestSuite(rawSuite) { suite.passed = suite.total - suite.failed - suite.errors; suite.duration = rawSuite["@_time"] * 1000; suite.status = suite.total === suite.passed ? 'PASS' : 'FAIL'; - setMetaData(rawSuite.properties, suite); + setMetaData(rawSuite, suite); const raw_test_cases = rawSuite.testcase; if (raw_test_cases) { for (let i = 0; i < raw_test_cases.length; i++) { - suite.cases.push(getTestCase(raw_test_cases[i])); + suite.cases.push(getTestCase(raw_test_cases[i], suite.meta_data)); } } return suite; @@ -47,12 +49,12 @@ function getTestSuite(rawSuite) { /** * - * @param {import('./junit.result').JUnitProperties} properties + * @param {JUnitTypes.TestSuite | JUnitTypes.JUnitTestCase} rawElement * @param {TestCase | TestSuite} test_element */ -function setMetaData(properties, test_element) { - if (properties && properties.property.length > 0) { - const raw_properties = properties.property; +function setMetaData(rawElement, test_element) { + if (rawElement.properties && rawElement.properties.property.length > 0) { + const raw_properties = rawElement.properties.property; for (const raw_property of raw_properties) { test_element.meta_data.set(raw_property["@_name"], raw_property["@_value"]); } diff --git a/tests/parser.junit.spec.js b/tests/parser.junit.spec.js index af2efe7..817bbaf 100644 --- a/tests/parser.junit.spec.js +++ b/tests/parser.junit.spec.js @@ -439,6 +439,7 @@ describe('Parser - JUnit', () => { it('parse spekt/junit.testlogger', () => { const result = parse({ type: 'junit', files: [`${testDataPath}/junit.testlogger.xml`] }); + var inheritedProperties = new Map([ ["hostname", "REDACTED"] ]); assert.deepEqual(result, { id: "", name: "", @@ -461,7 +462,7 @@ describe('Parser - JUnit', () => { skipped: 1, duration: 870.6800000000001, status: "FAIL", - meta_data: new Map(), + meta_data: inheritedProperties, cases: [ { id: "", @@ -475,7 +476,7 @@ describe('Parser - JUnit', () => { status: "PASS", failure: "", stack_trace: "", - "meta_data": new Map(), + meta_data: inheritedProperties, steps: [] }, { @@ -490,7 +491,7 @@ describe('Parser - JUnit', () => { status: "FAIL", failure: "TearDown : System.InvalidOperationException : Operation is not valid due to the current state of the object.", stack_trace: "", - "meta_data": new Map(), + meta_data: inheritedProperties, steps: [] }, { @@ -505,7 +506,7 @@ describe('Parser - JUnit', () => { status: "PASS", failure: "", stack_trace: "", - "meta_data": new Map(), + meta_data: inheritedProperties, steps: [] }, { @@ -520,7 +521,7 @@ describe('Parser - JUnit', () => { status: "PASS", failure: "", stack_trace: "", - "meta_data": new Map(), + meta_data: inheritedProperties, steps: [] } ] @@ -562,13 +563,19 @@ describe('Parser - JUnit', () => { assert.notEqual(null, result2); }); - it('meta-data from suite copied to testcase', () => { + it('meta-data from suite merged with testcase', () => { const result = parse({ type: 'junit', files: ['tests/data/junit/multiple-suites-properties.xml'] }); + + // confirm that suite level properties exist and are accurate assert.equal(result.suites[0].meta_data.size, 2); assert.equal(result.suites[0].meta_data.get("key1"), "value1"); assert.equal(result.suites[0].meta_data.get("key2"), "value2"); - assert.equal(result.suites[0].cases[0].meta_data.size, 1); - assert.equal(result.suites[0].cases[0].meta_data.get("key1"), "override-value1"); + + // confirm that the suite level properties were inherited into the test case and overridden if present + assert.equal(result.suites[0].cases[0].meta_data.size, 2); + assert.equal(result.suites[0].cases[0].meta_data.get("key1"), "override-value1"); // testcase value + assert.equal(result.suites[0].cases[0].meta_data.get("key2"), "value2"); // suite value + }); }); }); \ No newline at end of file From 7dda7e99207a947a6506f35d2816f45d01e66df9 Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Thu, 29 Feb 2024 12:18:11 -0500 Subject: [PATCH 3/3] include hostname in meta-data from suite in testcases #52 --- src/parsers/junit.js | 6 ++++++ src/parsers/junit.result.d.ts | 1 + tests/data/junit/playwright.xml | 23 +++++++++++++++++++++++ tests/parser.junit.spec.js | 16 ++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 tests/data/junit/playwright.xml diff --git a/src/parsers/junit.js b/src/parsers/junit.js index af0e6f3..42a316a 100644 --- a/src/parsers/junit.js +++ b/src/parsers/junit.js @@ -59,6 +59,12 @@ function setMetaData(rawElement, test_element) { test_element.meta_data.set(raw_property["@_name"], raw_property["@_value"]); } } + // handle testsuite specific attributes + if (test_element instanceof TestSuite) { + if (rawElement["@_hostname"]) { + test_element.meta_data.set("hostname", rawElement["@_hostname"]); + } + } } /** diff --git a/src/parsers/junit.result.d.ts b/src/parsers/junit.result.d.ts index 6a4d326..910323a 100644 --- a/src/parsers/junit.result.d.ts +++ b/src/parsers/junit.result.d.ts @@ -29,6 +29,7 @@ export type TestSuite = { '@_tests': number; '@_failures': number; '@_time': number; + '@_hostname': string; } export type JUnitResult = { diff --git a/tests/data/junit/playwright.xml b/tests/data/junit/playwright.xml new file mode 100644 index 0000000..ba0fedc --- /dev/null +++ b/tests/data/junit/playwright.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/parser.junit.spec.js b/tests/parser.junit.spec.js index 817bbaf..31aba10 100644 --- a/tests/parser.junit.spec.js +++ b/tests/parser.junit.spec.js @@ -576,6 +576,22 @@ describe('Parser - JUnit', () => { assert.equal(result.suites[0].cases[0].meta_data.get("key1"), "override-value1"); // testcase value assert.equal(result.suites[0].cases[0].meta_data.get("key2"), "value2"); // suite value }); + + it('include hostname in meta-data from suite and testcase', () => { + const result = parse({ type: 'junit', files: ['tests/data/junit/playwright.xml'] }); + + assert.equal(result.suites[0].meta_data.get("hostname"), "chromium"); + assert.equal(result.suites[0].cases[0].meta_data.get("hostname"), "chromium"); + assert.equal(result.suites[0].cases[1].meta_data.get("hostname"), "chromium"); + + assert.equal(result.suites[1].meta_data.get("hostname"), "firefox"); + assert.equal(result.suites[1].cases[0].meta_data.get("hostname"), "firefox"); + assert.equal(result.suites[1].cases[1].meta_data.get("hostname"), "firefox"); + + assert.equal(result.suites[2].meta_data.get("hostname"), "webkit"); + assert.equal(result.suites[2].cases[0].meta_data.get("hostname"), "webkit"); + assert.equal(result.suites[2].cases[1].meta_data.get("hostname"), "webkit"); + }); }); \ No newline at end of file