From 5f5d98cb8b6abb49ead1e789cbc233f5440ee480 Mon Sep 17 00:00:00 2001 From: Anudeep Date: Sat, 13 Jul 2024 14:07:40 +0530 Subject: [PATCH] feat: refactor tags and meta_data (#76) * feat: refactor tags and meta_data * feat: rename metadata --- src/models/TestCase.d.ts | 8 +- src/models/TestCase.js | 8 +- src/models/TestResult.d.ts | 3 + src/models/TestResult.js | 3 + src/models/TestSuite.d.ts | 4 +- src/models/TestSuite.js | 4 +- src/parsers/cucumber.js | 17 +-- src/parsers/junit.js | 8 +- src/parsers/mocha.js | 25 ++--- src/parsers/mstest.js | 19 ++-- src/parsers/nunit.js | 43 ++++---- src/parsers/testng.js | 5 +- src/parsers/xunit.js | 10 +- tests/parser.cucumber.spec.js | 27 +++-- tests/parser.junit.spec.js | 120 ++++++++++++-------- tests/parser.mocha.spec.js | 144 +++++++++++++++--------- tests/parser.mstest.spec.js | 185 ++++++++++++++++--------------- tests/parser.nunit.spec.js | 151 +++++++++++++++++++------ tests/parser.testng.spec.js | 202 +++++++++++++++++++++++----------- tests/parser.xunit.spec.js | 109 ++++++++++-------- 20 files changed, 682 insertions(+), 413 deletions(-) diff --git a/src/models/TestCase.d.ts b/src/models/TestCase.d.ts index 67f16e6..2676459 100644 --- a/src/models/TestCase.d.ts +++ b/src/models/TestCase.d.ts @@ -1,5 +1,5 @@ -import * as TestStep from './TestStep'; import * as TestAttachment from './TestAttachment'; +import * as TestStep from './TestStep'; declare class TestCase { name: string; @@ -12,10 +12,12 @@ declare class TestCase { status: string; failure: string; stack_trace: string; + tags: string[]; + metadata: object; + steps: TestStep[]; attachments: TestAttachment[]; - meta_data: Map; - + setFailure: SetFailureFunction } export type SetFailureFunction = (value: string) => string; diff --git a/src/models/TestCase.js b/src/models/TestCase.js index 87b7d58..cd1daf2 100644 --- a/src/models/TestCase.js +++ b/src/models/TestCase.js @@ -14,15 +14,17 @@ class TestCase { this.status = 'NA'; this.failure = ''; this.stack_trace = ''; + this.tags = []; + this.metadata = {}; + this.steps = []; this.attachments = []; - this.meta_data = new Map(); } setFailure(value) { this.failure = value ? unescape(value) : value; } - + } - + module.exports = TestCase; \ No newline at end of file diff --git a/src/models/TestResult.d.ts b/src/models/TestResult.d.ts index 2003e22..ef4123d 100644 --- a/src/models/TestResult.d.ts +++ b/src/models/TestResult.d.ts @@ -10,6 +10,9 @@ declare class TestResult { retried: number; duration: number; status: string; + tags: string[]; + metadata: object; + suites: TestSuite[]; } diff --git a/src/models/TestResult.js b/src/models/TestResult.js index d48f4f8..7a29e9d 100644 --- a/src/models/TestResult.js +++ b/src/models/TestResult.js @@ -11,6 +11,9 @@ class TestResult { this.retried = 0; this.duration = 0; this.status = 'NA'; + this.tags = []; + this.metadata = {}; + this.suites = []; } } diff --git a/src/models/TestSuite.d.ts b/src/models/TestSuite.d.ts index 11ca293..2a7628a 100644 --- a/src/models/TestSuite.d.ts +++ b/src/models/TestSuite.d.ts @@ -9,7 +9,9 @@ declare class TestSuite { skipped: number; duration: number; status: string; - meta_data: Map; + tags: string[]; + metadata: object; + cases: TestCase[]; } diff --git a/src/models/TestSuite.js b/src/models/TestSuite.js index 6d87c1f..776c56f 100644 --- a/src/models/TestSuite.js +++ b/src/models/TestSuite.js @@ -10,7 +10,9 @@ class TestSuite { this.skipped = 0; this.duration = 0; this.status = 'NA'; - this.meta_data = new Map(); + this.tags = []; + this.metadata = {}; + this.cases = []; } diff --git a/src/parsers/cucumber.js b/src/parsers/cucumber.js index a6325c9..878a1b2 100644 --- a/src/parsers/cucumber.js +++ b/src/parsers/cucumber.js @@ -11,7 +11,7 @@ function getTestCase(rawCase) { setMetaData(rawCase, test_case); if (rawCase.state && rawCase.state === "failed") { test_case.status = 'FAIL'; - set_error_and_stack_trace(test_case, rawCase.errorStack); + setErrorAndStackTrace(test_case, rawCase.errorStack); } else { test_case.status = 'PASS'; @@ -23,7 +23,7 @@ function getTestCase(rawCase) { * @param {TestCase} test_case * @param {string?} message */ -function set_error_and_stack_trace(test_case, message) { +function setErrorAndStackTrace(test_case, message) { if (message) { const stack_trace_start_index = message.indexOf(' at '); if (stack_trace_start_index) { @@ -43,21 +43,16 @@ function set_error_and_stack_trace(test_case, message) { * @param {TestCase | TestSuite} test_element */ function setMetaData(element, test_element) { - const meta_tags = []; - const meta_raw_tags = []; const tags = element.tags; if (tags && tags.length > 0) { for (const tag of tags) { - const [name, value] = tag["name"].substring(1).split("="); - if (value) { - test_element.meta_data.set(name, value); + if (tag["name"].includes("=")) { + const [name, value] = tag["name"].substring(1).split("="); + test_element.metadata[name] = value; } else { - meta_tags.push(name); - meta_raw_tags.push(tag["name"]); + test_element.tags.push(tag["name"]); } } - test_element.meta_data.set("tags", meta_tags.join(",")); - test_element.meta_data.set("tagsRaw", meta_raw_tags.join(",")); } } diff --git a/src/parsers/junit.js b/src/parsers/junit.js index 1dffc96..073d7a6 100644 --- a/src/parsers/junit.js +++ b/src/parsers/junit.js @@ -10,7 +10,7 @@ function getTestCase(rawCase, suite_meta) { const test_case = new TestCase(); test_case.name = rawCase["@_name"]; test_case.duration = rawCase["@_time"] * 1000; - test_case.meta_data = new Map(suite_meta); + test_case.metadata = Object.assign({}, suite_meta); setAttachments(rawCase, test_case); setMetaData(rawCase, test_case); if (rawCase.failure && rawCase.failure.length > 0) { @@ -67,7 +67,7 @@ function getTestSuite(rawSuite) { 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.meta_data)); + suite.cases.push(getTestCase(raw_test_cases[i], suite.metadata)); } } return suite; @@ -81,13 +81,13 @@ 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"]); + test_element.metadata[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"]); + test_element.metadata["hostname"] = rawElement["@_hostname"]; } } } diff --git a/src/parsers/mocha.js b/src/parsers/mocha.js index 81ede55..4958026 100644 --- a/src/parsers/mocha.js +++ b/src/parsers/mocha.js @@ -47,7 +47,7 @@ function getTestSuite(rawSuite) { /** * Function to format the mocha raw json report - * @param {import("./mocha.result").MochaJsonData} raw_json + * @param {import("./mocha.result").MochaJsonData} raw_json */ function getTestResult(raw_json) { const result = new TestResult(); @@ -82,7 +82,7 @@ function getTestResult(raw_json) { /** * Function to format the mocha raw json report - * @param {import("./mocha.result").MochaJsonData} raw_json + * @param {import("./mocha.result").MochaJsonData} raw_json * @returns formatted json object */ function formatMochaJsonReport(raw_json) { @@ -125,8 +125,8 @@ function formatMochaJsonReport(raw_json) { } /** - * - * @param {import("./mocha.result").MochaSuite} suite + * + * @param {import("./mocha.result").MochaSuite} suite */ function flattenTestSuite(suite) { if (!suite.suites) { @@ -144,27 +144,22 @@ function flattenTestSuite(suite) { } /** - * - * @param {TestCase | TestSuite} test_element + * + * @param {TestCase | TestSuite} test_element */ function setMetaData(test_element) { const regexp = /([\@\#][^\s]*)/gm; // match @tag or #tag const matches = [...test_element.name.matchAll(regexp)]; if (matches.length > 0) { - const meta_tags = []; - const meta_raw_tags = []; for (const match of matches) { const rawTag = match[0]; - const [name, value] = rawTag.substring(1).split("="); - if (value) { - test_element.meta_data.set(name, value); + if (rawTag.includes("=")) { + const [name, value] = rawTag.substring(1).split("="); + test_element.metadata[name] = value; } else { - meta_tags.push(name); - meta_raw_tags.push(rawTag); + test_element.tags.push(rawTag); } } - test_element.meta_data.set("tags", meta_tags.join(",")); - test_element.meta_data.set("tagsRaw", meta_raw_tags.join(",")); } } diff --git a/src/parsers/mstest.js b/src/parsers/mstest.js index 9fb15f8..202301e 100644 --- a/src/parsers/mstest.js +++ b/src/parsers/mstest.js @@ -12,18 +12,23 @@ const RESULT_MAP = { NotExecuted: "SKIP", } -function populateMetaData(rawElement, map) { +/** + * + * @param {*} rawElement + * @param {TestCase | TestSuite} test_element + */ +function populateMetaData(rawElement, test_element) { if (rawElement.TestCategory && rawElement.TestCategory.TestCategoryItem) { let rawCategories = rawElement.TestCategory.TestCategoryItem; for (let i = 0; i < rawCategories.length; i++) { let categoryName = rawCategories[i]["@_TestCategory"]; - map.set(categoryName, ""); + test_element.tags.push(categoryName); // create comma-delimited list of categories - if (map.has("Categories")) { - map.set("Categories", map.get("Categories").concat(",", categoryName)); + if (test_element.metadata["Categories"]) { + test_element.metadata["Categories"] = test_element.metadata["Categories"].concat(",", categoryName) } else { - map.set("Categories", categoryName); + test_element.metadata["Categories"] = categoryName; } } } @@ -36,7 +41,7 @@ function populateMetaData(rawElement, map) { for (let i = 0; i < rawProperties.length; i++) { let key = rawProperties[i].Key ?? "not-set"; let val = rawProperties[i].Value ?? ""; - map.set(key, val); + map[key] = val; } } } @@ -120,7 +125,7 @@ function getTestCase(rawTestResult, definitionMap, testRunName) { // populate attachments populateAttachments(rawTestResult, testCase.attachments, testRunName); // populate meta - populateMetaData(rawDefinition, testCase.meta_data); + populateMetaData(rawDefinition, testCase); return testCase; } else { diff --git a/src/parsers/nunit.js b/src/parsers/nunit.js index dec9d2f..dabe28d 100644 --- a/src/parsers/nunit.js +++ b/src/parsers/nunit.js @@ -40,25 +40,30 @@ function populateAttachments(rawCase, attachments) { } function mergeMeta(map1, map2) { - for (let kvp of map1) { - map2.set(kvp[0], kvp[1]); + for (let kvp of Object.entries(map1)) { + map2[kvp[0]] = kvp[1]; } } -function populateMetaData(raw, map) { +/** + * + * @param {*} raw + * @param {TestCase | TestSuite} test_element + */ +function populateMetaData(raw, test_element) { // v2 supports categories if (raw.categories) { let categories = raw.categories.category; for (let i = 0; i < categories.length; i++) { let categoryName = categories[i]["@_name"]; - map.set(categoryName, ""); + test_element.tags.push(categoryName); // create comma-delimited list of categories - if (map.has("Categories")) { - map.set("Categories", map.get("Categories").concat(",", categoryName)); + if (test_element.metadata["Categories"]) { + test_element.metadata["Categories"] = test_element.metadata["Categories"].concat(",", categoryName); } else { - map.set("Categories", categoryName); + test_element.metadata["Categories"] = categoryName; } } } @@ -74,15 +79,14 @@ function populateMetaData(raw, map) { // v3 treats 'Categories' as property "Category" if (propName == "Category") { - if (map.has("Categories")) { - map.set("Categories", map.get("Categories").concat(",", propValue)); + if (test_element.metadata["Categories"]) { + test_element.metadata["Categories"] = test_element.metadata["Categories"].concat(",", propValue); } else { - map.set("Categories", propValue); + test_element.metadata["Categories"] = propValue; } - map.set(propValue, ""); } else { - map.set(propName, propValue); + test_element.metadata[propName] = propValue; } } } @@ -148,8 +152,8 @@ function getTestCases(rawSuite, parent_meta) { // populate attachments populateAttachments(rawCase, testCase.attachments); // copy parent_meta data to test case - mergeMeta(parent_meta, testCase.meta_data); - populateMetaData(rawCase, testCase.meta_data); + mergeMeta(parent_meta, testCase.metadata); + populateMetaData(rawCase, testCase); cases.push(testCase); } @@ -165,8 +169,8 @@ function getTestSuites(rawSuites, assembly_meta) { let rawSuite = rawSuites[i]; if (rawSuite["@_type"] == "Assembly") { - assembly_meta = new Map(); - populateMetaData(rawSuite, assembly_meta); + assembly_meta = {}; + populateMetaData(rawSuite, { tags: [], metadata: assembly_meta }); } if (hasNestedSuite(rawSuite)) { @@ -180,10 +184,9 @@ function getTestSuites(rawSuites, assembly_meta) { suite.duration = (rawSuite["@_time"] ?? rawSuite["@_duration"]) * 1000; // in milliseconds suite.status = RESULT_MAP[rawSuite["@_result"]]; - const meta_data = new Map(); - mergeMeta(assembly_meta, meta_data); - populateMetaData(rawSuite, meta_data); - suite.cases.push(...getTestCases(rawSuite, meta_data)); + mergeMeta(assembly_meta, suite.metadata); + populateMetaData(rawSuite, suite); + suite.cases.push(...getTestCases(rawSuite, suite.metadata)); // calculate totals suite.total = suite.cases.length; diff --git a/src/parsers/testng.js b/src/parsers/testng.js index fc91439..7a9cc39 100644 --- a/src/parsers/testng.js +++ b/src/parsers/testng.js @@ -39,10 +39,7 @@ function getTestCase(rawCase, testCaseToGroupMap) { const key = getFullTestName(rawCase); if (testCaseToGroupMap.has(key)) { let groups = testCaseToGroupMap.get(key); - test_case.meta_data.set("groups", groups.join(",")); - groups.forEach(group => { - test_case.meta_data.set(group, ""); - }) + test_case.tags = groups; } if (rawCase.exception) { test_case.setFailure(rawCase.exception[0].message); diff --git a/src/parsers/xunit.js b/src/parsers/xunit.js index 8bad9a7..371547a 100644 --- a/src/parsers/xunit.js +++ b/src/parsers/xunit.js @@ -15,14 +15,14 @@ function getTestCase(rawCase) { else if (rawCase.failure && rawCase.failure.length > 0) { test_case.status = 'FAIL'; test_case.setFailure(rawCase.failure[0]["message"]); - } + } else { test_case.status = 'PASS'; } if(rawCase.traits && rawCase.traits.trait && rawCase.traits.trait.length > 0) { const traits = rawCase.traits.trait; for(let i = 0; i < traits.length; i++) { - test_case.meta_data.set( traits[i]["@_name"], traits[i]["@_value"]); + test_case.metadata[traits[i]["@_name"]] = traits[i]["@_value"]; } } @@ -51,7 +51,7 @@ function getTestSuite(rawSuite) { function getTestResult(json) { const result = new TestResult(); const rawResult = json["assemblies"][0]["assembly"][0]; - + result.name = rawResult["@_name"]; result.total = rawResult["@_total"]; result.passed = rawResult["@_passed"]; @@ -66,8 +66,8 @@ function getTestResult(json) { } result.duration = rawResult["@_time"] * 1000; const rawSuites = rawResult["collection"]; - - + + for (let i = 0; i < rawSuites.length; i++) { result.suites.push(getTestSuite(rawSuites[i])); } diff --git a/tests/parser.cucumber.spec.js b/tests/parser.cucumber.spec.js index 25b5e7b..50767a6 100644 --- a/tests/parser.cucumber.spec.js +++ b/tests/parser.cucumber.spec.js @@ -19,6 +19,8 @@ describe('Parser - Cucumber Json', () => { retried: 0, duration: 1.59, status: 'PASS', + tags: [], + metadata: {}, suites: [ { id: '', @@ -30,7 +32,8 @@ describe('Parser - Cucumber Json', () => { skipped: 0, duration: 1.59, status: 'PASS', - meta_data: newMap({ tags: "blue,slow", suite: "1234", tagsRaw: "@blue,@slow" }), + tags: ["@blue", "@slow"], + metadata: { suite: "1234" }, cases: [ { attachments: [], @@ -44,7 +47,8 @@ describe('Parser - Cucumber Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: newMap({ tags: "green,fast", testCase: "1234", tagsRaw: "@green,@fast" }), + tags: ["@green", "@fast"], + metadata: { testCase: "1234" }, steps: [], total: 0 } @@ -67,6 +71,8 @@ describe('Parser - Cucumber Json', () => { retried: 0, duration: 0, status: 'PASS', + tags: [], + metadata: {}, suites: [] }); }); @@ -84,6 +90,8 @@ describe('Parser - Cucumber Json', () => { retried: 0, duration: 3.36, status: 'FAIL', + tags: [], + metadata: {}, suites: [ { id: '', @@ -95,7 +103,8 @@ describe('Parser - Cucumber Json', () => { skipped: 0, duration: 2.84, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -109,7 +118,8 @@ describe('Parser - Cucumber Json', () => { skipped: 0, stack_trace: " at CustomWorld. (D:\\workspace\\nodejs\\cc-tests\\features\\support\\steps.js:18:12)", status: "FAIL", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 }, @@ -125,7 +135,8 @@ describe('Parser - Cucumber Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -141,7 +152,8 @@ describe('Parser - Cucumber Json', () => { skipped: 0, duration: 0.52, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -155,7 +167,8 @@ describe('Parser - Cucumber Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } diff --git a/tests/parser.junit.spec.js b/tests/parser.junit.spec.js index 91833f8..f2bcd81 100644 --- a/tests/parser.junit.spec.js +++ b/tests/parser.junit.spec.js @@ -19,6 +19,8 @@ describe('Parser - JUnit', () => { retried: 0, duration: 10000, status: 'FAIL', + tags: [], + metadata: {}, suites: [ { id: '', @@ -30,7 +32,8 @@ describe('Parser - JUnit', () => { skipped: 0, duration: 10000, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -44,7 +47,8 @@ describe('Parser - JUnit', () => { skipped: 0, stack_trace: "Some Text", status: "FAIL", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -67,6 +71,8 @@ describe('Parser - JUnit', () => { retried: 0, duration: 10000, status: 'FAIL', + tags: [], + metadata: {}, suites: [ { id: '', @@ -78,7 +84,8 @@ describe('Parser - JUnit', () => { skipped: 0, duration: 10000, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -92,7 +99,8 @@ describe('Parser - JUnit', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -115,6 +123,8 @@ describe('Parser - JUnit', () => { retried: 0, duration: 10000, status: 'PASS', + tags: [], + metadata: {}, suites: [ { id: '', @@ -126,7 +136,8 @@ describe('Parser - JUnit', () => { skipped: 0, duration: 10000, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -140,7 +151,8 @@ describe('Parser - JUnit', () => { skipped: 0, stack_trace: "", status: "SKIP", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -163,6 +175,8 @@ describe('Parser - JUnit', () => { retried: 0, duration: 20000, status: 'FAIL', + tags: [], + metadata: {}, suites: [ { id: '', @@ -174,7 +188,8 @@ describe('Parser - JUnit', () => { skipped: 0, duration: 10000, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -188,7 +203,8 @@ describe('Parser - JUnit', () => { skipped: 0, stack_trace: "Some Text", status: "FAIL", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -204,7 +220,8 @@ describe('Parser - JUnit', () => { skipped: 0, duration: 10000, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -218,7 +235,8 @@ describe('Parser - JUnit', () => { skipped: 0, stack_trace: "Some Text", status: "FAIL", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -241,6 +259,8 @@ describe('Parser - JUnit', () => { retried: 0, duration: 20000, status: 'FAIL', + tags: [], + metadata: {}, suites: [ { id: '', @@ -252,7 +272,8 @@ describe('Parser - JUnit', () => { skipped: 0, duration: 10000, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -266,7 +287,8 @@ describe('Parser - JUnit', () => { skipped: 0, stack_trace: "Some Text", status: "FAIL", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -282,7 +304,8 @@ describe('Parser - JUnit', () => { skipped: 0, duration: 10000, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -296,7 +319,8 @@ describe('Parser - JUnit', () => { skipped: 0, stack_trace: "Some Text", status: "FAIL", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -319,6 +343,8 @@ describe('Parser - JUnit', () => { retried: 0, duration: 32937, status: 'PASS', + tags: [], + metadata: {}, suites: [ { id: '', @@ -330,7 +356,8 @@ describe('Parser - JUnit', () => { skipped: 0, duration: 807, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -344,7 +371,8 @@ describe('Parser - JUnit', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -367,6 +395,8 @@ describe('Parser - JUnit', () => { retried: 0, duration: 37506, status: "FAIL", + tags: [], + metadata: {}, suites: [ { id: "", @@ -378,7 +408,8 @@ describe('Parser - JUnit', () => { skipped: 0, duration: 446, status: "FAIL", - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { id: "", @@ -392,7 +423,8 @@ describe('Parser - JUnit', () => { status: "FAIL", failure: "expected to include 'Residntial'", stack_trace: "", - meta_data: new Map(), + tags: [], + metadata: {}, attachments: [], steps: [] }, @@ -408,7 +440,8 @@ describe('Parser - JUnit', () => { status: "PASS", failure: "", stack_trace: "", - meta_data: new Map(), + tags: [], + metadata: {}, attachments: [], steps: [] } @@ -424,7 +457,8 @@ describe('Parser - JUnit', () => { skipped: 0, duration: 634, status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { id: "", @@ -438,7 +472,8 @@ describe('Parser - JUnit', () => { status: "PASS", failure: "", stack_trace: "", - meta_data: new Map(), + tags: [], + metadata: {}, attachments: [], steps: [] } @@ -450,12 +485,11 @@ 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.suites[0].meta_data, inheritedProperties); - assert.deepEqual(result.suites[0].cases[0].meta_data, inheritedProperties); + assert.deepEqual(result.suites[0].metadata, { "hostname": "REDACTED" }); + assert.deepEqual(result.suites[0].cases[0].metadata, { "hostname": "REDACTED" }); }); - it('parse testcafe with testsuite root node', () => { + it('parse testcafe with test suite root node', () => { const result = parse({ type: 'junit', files: [`${testDataPath}/testCafe.xml`] }); assert.equal(result.suites.length, 1); @@ -475,6 +509,8 @@ describe('Parser - JUnit', () => { retried: 0, duration: 0, status: 'PASS', + tags: [], + metadata: {}, suites: [] }); }); @@ -488,34 +524,26 @@ describe('Parser - JUnit', () => { assert.notEqual(null, result2); }); - it('meta-data from suite merged with testcase', () => { + it('meta-data from suite merged with test case', () => { 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"); - - // 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 + assert.deepEqual(result.suites[0].metadata, { "key1": "value1", "key2": "value2" }); + assert.deepEqual(result.suites[0].cases[0].metadata, { "key1": "override-value1", "key2": "value2" }); }); - it('include hostname in meta-data from suite and testcase', () => { + it('include hostname in meta-data from suite and test case', () => { 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.deepEqual(result.suites[0].metadata, { "hostname": "chromium" }); + assert.deepEqual(result.suites[0].cases[0].metadata, { "hostname": "chromium" }); + assert.deepEqual(result.suites[0].cases[1].metadata, { "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.deepEqual(result.suites[1].metadata, { "hostname": "firefox" }); + assert.deepEqual(result.suites[1].cases[0].metadata, { "hostname": "firefox" }); + assert.deepEqual(result.suites[1].cases[1].metadata, { "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"); + assert.deepEqual(result.suites[2].metadata, { "hostname": "webkit" }); + assert.deepEqual(result.suites[2].cases[0].metadata, { "hostname": "webkit" }); + assert.deepEqual(result.suites[2].cases[1].metadata, { "hostname": "webkit" }); }); diff --git a/tests/parser.mocha.spec.js b/tests/parser.mocha.spec.js index aa30846..9ce546f 100644 --- a/tests/parser.mocha.spec.js +++ b/tests/parser.mocha.spec.js @@ -3,9 +3,9 @@ const assert = require('assert'); const path = require('path'); describe('Parser - Mocha Json', () => { - + const testDataPath = "tests/data/mocha/json" - + it('single suite with single test', () => { const result = parse({ type: 'mocha', files: [`${testDataPath}/single-suite-single-test.json`] }); assert.deepEqual(result, { @@ -19,6 +19,8 @@ describe('Parser - Mocha Json', () => { retried: 0, duration: 3, status: 'PASS', + tags: [], + metadata: {}, suites: [ { id: '', @@ -30,7 +32,8 @@ describe('Parser - Mocha Json', () => { skipped: 0, duration: 1, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -44,7 +47,8 @@ describe('Parser - Mocha Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -53,7 +57,7 @@ describe('Parser - Mocha Json', () => { ] }); }); - + it('empty suite report', () => { const result = parse({ type: 'mocha', files: [`${testDataPath}/empty-suite.json`] }); assert.deepEqual(result, { @@ -67,6 +71,8 @@ describe('Parser - Mocha Json', () => { retried: 0, duration: 0, status: 'PASS', + tags: [], + metadata: {}, suites: [] }); }); @@ -84,6 +90,8 @@ describe('Parser - Mocha Json', () => { retried: 0, duration: 3, status: 'PASS', + tags: [], + metadata: {}, suites: [ { id: '', @@ -95,7 +103,8 @@ describe('Parser - Mocha Json', () => { skipped: 1, duration: 1, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -109,7 +118,8 @@ describe('Parser - Mocha Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 }, @@ -125,7 +135,8 @@ describe('Parser - Mocha Json', () => { skipped: 0, stack_trace: "", status: "SKIP", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -147,6 +158,8 @@ describe('Parser - Mocha Json', () => { retried: 0, duration: 7, status: 'FAIL', + tags: [], + metadata: {}, suites: [ { id: '', @@ -158,7 +171,8 @@ describe('Parser - Mocha Json', () => { skipped: 0, duration: 4, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -172,7 +186,8 @@ describe('Parser - Mocha Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 }, @@ -188,7 +203,8 @@ describe('Parser - Mocha Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -204,7 +220,8 @@ describe('Parser - Mocha Json', () => { skipped: 0, duration: 1, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -218,7 +235,8 @@ describe('Parser - Mocha Json', () => { skipped: 0, stack_trace: "", status: "FAIL", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -233,35 +251,31 @@ describe('Parser - Mocha Json', () => { let absolutePath = path.resolve(relativePath); const result1 = parse({ type: 'mocha', files: [absolutePath] }); assert.notEqual(null, result1); - const result2 = parse({ type: 'mocha', files: [relativePath]}); + const result2 = parse({ type: 'mocha', files: [relativePath] }); assert.notEqual(null, result2); }); it('has multiple tags', () => { const result = parse({ type: 'mocha', files: [`${testDataPath}/multiple-suites-multiple-tests-tags.json`] }); + let test_suite = result.suites[0]; let test_case = result.suites[0].cases[0]; - assert.equal(test_suite.meta_data.has("tags"), true); - assert.equal(test_suite.meta_data.get("tags"), ""); - assert.equal(test_suite.meta_data.get("tagsRaw"), ""); - assert.equal(test_suite.meta_data.get("type"), "api"); - assert.equal(test_case.meta_data.has("tags"), true); - assert.equal(test_case.meta_data.get("tags"), "fast,1255"); - assert.equal(test_case.meta_data.get("tagsRaw"), "@fast,#1255"); + + assert.deepEqual(test_suite.metadata, { type: 'api' }); + assert.deepEqual(test_case.tags, ['@fast', '#1255']); }); it('has single tag', () => { const result = parse({ type: 'mocha', files: [`${testDataPath}/multiple-suites-multiple-tests-tags.json`] }); let test_case = result.suites[1].cases[0]; - assert.equal(test_case.meta_data.has("tags"), true); - assert.equal(test_case.meta_data.get("tags"), "1234"); - assert.equal(test_case.meta_data.get("tagsRaw"), "#1234"); + + assert.deepEqual(test_case.tags, ['#1234']); }); - it('does not include tags meta if no tags are present', () =>{ + it('does not include tags meta if no tags are present', () => { const result = parse({ type: 'mocha', files: [`${testDataPath}/multiple-suites-multiple-tests-tags.json`] }); - let testcase = result.suites[0].cases[1]; - assert.equal(testcase.meta_data.has("tags"), false); + let test_case = result.suites[0].cases[1]; + assert.deepEqual(test_case.tags, []); }); }); @@ -281,6 +295,8 @@ describe('Parser - Mocha Awesome Json', () => { retried: 0, duration: 3, status: 'PASS', + tags: [], + metadata: {}, suites: [ { id: '', @@ -292,7 +308,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, duration: 1, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -306,7 +323,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -329,10 +347,12 @@ describe('Parser - Mocha Awesome Json', () => { retried: 0, duration: 0, status: 'PASS', + tags: [], + metadata: {}, suites: [] }); }); - + it('suite with pending tests', () => { const result = parse({ type: 'mocha', files: [`${testDataPath}/pending-tests.json`] }); assert.deepEqual(result, { @@ -346,6 +366,8 @@ describe('Parser - Mocha Awesome Json', () => { retried: 0, duration: 3, status: 'PASS', + tags: [], + metadata: {}, suites: [ { id: '', @@ -357,7 +379,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 1, duration: 1, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -371,7 +394,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 }, @@ -387,7 +411,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, stack_trace: "", status: "SKIP", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -410,6 +435,8 @@ describe('Parser - Mocha Awesome Json', () => { retried: 0, duration: 7, status: 'FAIL', + tags: [], + metadata: {}, suites: [ { id: '', @@ -421,7 +448,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, duration: 4, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -435,7 +463,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 }, @@ -451,7 +480,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -467,7 +497,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, duration: 1, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -481,7 +512,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, stack_trace: "", status: "FAIL", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -504,6 +536,8 @@ describe('Parser - Mocha Awesome Json', () => { retried: 0, duration: 7, status: 'FAIL', + tags: [], + metadata: {}, suites: [ { id: '', @@ -515,7 +549,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, duration: 4, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -529,7 +564,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 }, @@ -545,7 +581,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, stack_trace: "", status: "PASS", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -561,7 +598,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, duration: 1, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -575,7 +613,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 0, stack_trace: "", status: "FAIL", - meta_data: new Map(), + tags: [], + metadata: {}, steps: [], total: 0 } @@ -590,7 +629,7 @@ describe('Parser - Mocha Awesome Json', () => { let absolutePath = path.resolve(relativePath); const result1 = parse({ type: 'mocha', files: [absolutePath] }); assert.notEqual(null, result1); - const result2 = parse({ type: 'mocha', files: [relativePath]}); + const result2 = parse({ type: 'mocha', files: [relativePath] }); assert.notEqual(null, result2); }); @@ -607,6 +646,8 @@ describe('Parser - Mocha Awesome Json', () => { skipped: 1, status: "PASS", total: 3, + tags: [], + metadata: {}, suites: [ { cases: [ @@ -617,7 +658,8 @@ describe('Parser - Mocha Awesome Json', () => { failed: 0, failure: "", id: "", - meta_data: new Map(), + tags: [], + metadata: {}, name: "first skipped test", passed: 0, skipped: 0, @@ -631,7 +673,8 @@ describe('Parser - Mocha Awesome Json', () => { errors: 0, failed: 0, id: "", - meta_data: new Map(), + tags: [], + metadata: {}, name: "Example Suite", passed: 0, skipped: 0, @@ -647,7 +690,8 @@ describe('Parser - Mocha Awesome Json', () => { failed: 0, failure: "", id: "", - meta_data: new Map(), + tags: [], + metadata: {}, name: "first passed test", passed: 0, skipped: 0, @@ -663,7 +707,8 @@ describe('Parser - Mocha Awesome Json', () => { failed: 0, failure: "", id: "", - meta_data: new Map(), + tags: [], + metadata: {}, name: "second passed test", passed: 0, skipped: 0, @@ -677,7 +722,8 @@ describe('Parser - Mocha Awesome Json', () => { errors: 0, failed: 0, id: "", - meta_data: new Map(), + tags: [], + metadata: {}, name: "Second Example Suite", passed: 2, skipped: 0, diff --git a/tests/parser.mstest.spec.js b/tests/parser.mstest.spec.js index 7fd54ba..cc2c222 100644 --- a/tests/parser.mstest.spec.js +++ b/tests/parser.mstest.spec.js @@ -4,99 +4,102 @@ const path = require('path'); describe('Parser - MSTest', () => { - const testDataPath = "tests/data/mstest"; - var result; - - before(() => { - result = parse({ type: 'mstest', files: [`${testDataPath}/testresults.trx`] }); - }); - - it('Should calculate totals', () => { - assert.equal(result.total, 12); - assert.equal(result.passed, 7); - assert.equal(result.failed, 3); - assert.equal(result.skipped, 2); - - assert.equal(result.suites.length, 3); - //assert.equal(result.duration > 0, true); // TODO: Fix - }) - - it('Should express durations in milliseconds', () => { - //trx represents timestamps with microseconds - //assert.equal(result.suites[0].cases[0].duration, 259.239); // TODO: Fix - }) - - it('Should map results correctly', () => { - assert.equal(result.status, "FAIL"); - - // assert suite results - assert.equal(result.suites[0].status, "FAIL") - - assert.equal(result.suites[0].cases[0].status, "FAIL"); - assert.equal(result.suites[0].cases[1].status, "SKIP"); // inconclusive - assert.equal(result.suites[0].cases[2].status, "PASS"); - assert.equal(result.suites[0].cases[3].status, "PASS"); - assert.equal(result.suites[0].cases[4].status, "PASS"); - assert.equal(result.suites[0].cases[5].status, "SKIP"); // ignore - assert.equal(result.suites[0].cases[6].status, "FAIL"); // not runnable - assert.equal(result.suites[0].cases[7].status, "FAIL"); // exception - assert.equal(result.suites[0].cases[8].status, "PASS"); - - assert.equal(result.suites[1].status, "PASS") - assert.equal(result.suites[1].cases[0].status, "PASS"); // datarow - - assert.equal(result.suites[2].status, "PASS") - }); - - it('Should include fullnames for testsuites and testcases', () => { - assert.equal(result.suites[0].name, "MSTestSample.MockTestFixture"); - assert.equal(result.suites[0].cases[0].name, "MSTestSample.MockTestFixture.FailingTest"); - }); - - it('Should include failure and stack trace for failed test', () => { - assert.equal(result.suites[0].cases[0].failure, 'Assert.Fail failed.') - assert.equal(result.suites[0].cases[0].stack_trace, 'at MSTestSample.MockTestFixture.FailingTest() in C:\\dev\\code\\_Experiments\\MSTestSample\\UnitTest1.cs:line 12 '); + const testDataPath = "tests/data/mstest"; + var result; + + before(() => { + result = parse({ type: 'mstest', files: [`${testDataPath}/testresults.trx`] }); + }); + + it('Should calculate totals', () => { + assert.equal(result.total, 12); + assert.equal(result.passed, 7); + assert.equal(result.failed, 3); + assert.equal(result.skipped, 2); + + assert.equal(result.suites.length, 3); + //assert.equal(result.duration > 0, true); // TODO: Fix + }) + + it('Should express durations in milliseconds', () => { + //trx represents timestamps with microseconds + //assert.equal(result.suites[0].cases[0].duration, 259.239); // TODO: Fix + }) + + it('Should map results correctly', () => { + assert.equal(result.status, "FAIL"); + + // assert suite results + assert.equal(result.suites[0].status, "FAIL") + + assert.equal(result.suites[0].cases[0].status, "FAIL"); + assert.equal(result.suites[0].cases[1].status, "SKIP"); // inconclusive + assert.equal(result.suites[0].cases[2].status, "PASS"); + assert.equal(result.suites[0].cases[3].status, "PASS"); + assert.equal(result.suites[0].cases[4].status, "PASS"); + assert.equal(result.suites[0].cases[5].status, "SKIP"); // ignore + assert.equal(result.suites[0].cases[6].status, "FAIL"); // not runnable + assert.equal(result.suites[0].cases[7].status, "FAIL"); // exception + assert.equal(result.suites[0].cases[8].status, "PASS"); + + assert.equal(result.suites[1].status, "PASS") + assert.equal(result.suites[1].cases[0].status, "PASS"); // datarow + + assert.equal(result.suites[2].status, "PASS") + }); + + it('Should include fullnames for testsuites and testcases', () => { + assert.equal(result.suites[0].name, "MSTestSample.MockTestFixture"); + assert.equal(result.suites[0].cases[0].name, "MSTestSample.MockTestFixture.FailingTest"); + }); + + it('Should include failure and stack trace for failed test', () => { + assert.equal(result.suites[0].cases[0].failure, 'Assert.Fail failed.') + assert.equal(result.suites[0].cases[0].stack_trace, 'at MSTestSample.MockTestFixture.FailingTest() in C:\\dev\\code\\_Experiments\\MSTestSample\\UnitTest1.cs:line 12 '); + }); + + it('Should include categories from suite', () => { + const testCaseInheritedCategories = result.suites[0].cases[0]; + assert.deepEqual(testCaseInheritedCategories.tags, ['FixtureCategory']); + assert.deepEqual(testCaseInheritedCategories.metadata, { + Categories: 'FixtureCategory' }); + }) - it('Should include categories from suite', () => { - const testCaseInheritedCategories = result.suites[0].cases[0]; - assert.equal(testCaseInheritedCategories.meta_data.has("FixtureCategory"), true); - assert.equal(testCaseInheritedCategories.meta_data.get("Categories"), "FixtureCategory"); - }) - - it('Should combine categories from suite and case', () => { - const testCaseWithCategories = result.suites[0].cases[3]; - assert.equal(testCaseWithCategories.meta_data.has("FixtureCategory"), true); - assert.equal(testCaseWithCategories.meta_data.has("MockCategory"), true); - assert.equal(testCaseWithCategories.meta_data.get("Categories"), "FixtureCategory,MockCategory"); + it('Should combine categories from suite and case', () => { + const testCaseWithCategories = result.suites[0].cases[3]; + assert.deepEqual(testCaseWithCategories.tags, ['FixtureCategory', 'MockCategory']); + assert.deepEqual(testCaseWithCategories.metadata, { + Categories: 'FixtureCategory,MockCategory' }); - - it('Should include ResultFiles as test case attachments', () => { - const testSuiteWithAttachments = result.suites[2]; - let expectedPath1 = resolveExpectedResultFilePath("238c26aa-9963-4623-aeda-95ef9a6799d0", "dummy1.txt"); - let expectedPath2 = resolveExpectedResultFilePath("2b2b0f58-3d88-432c-9955-1040315f96e9", "dummy2.txt"); - let expectedPath3 = resolveExpectedResultFilePath("2b2b0f58-3d88-432c-9955-1040315f96e9", "dummy3.txt"); - - assert.equal(testSuiteWithAttachments.cases[0].attachments.length, 1); - assert.equal(testSuiteWithAttachments.cases[0].attachments[0].path, expectedPath1); - - assert.equal(testSuiteWithAttachments.cases[1].attachments.length, 2); - assert.equal(testSuiteWithAttachments.cases[1].attachments[0].path, expectedPath2) - assert.equal(testSuiteWithAttachments.cases[1].attachments[1].path, expectedPath3) - }); - - it('Should report overall status as PASS if all tests pass', () => { - const result = parse({ type: 'mstest', files: [`${testDataPath}/testresults_pass.trx`] }); - assert.equal(result.status, "PASS"); - }); - - function resolveExpectedResultFilePath(executionId, filePath) { - return path.join( - "bryan.b.cook_MYCOMPUTER_2023-11-12_19_21_51", - "In", - executionId, - "MYCOMPUTER", - filePath); - } + }); + + it('Should include ResultFiles as test case attachments', () => { + const testSuiteWithAttachments = result.suites[2]; + let expectedPath1 = resolveExpectedResultFilePath("238c26aa-9963-4623-aeda-95ef9a6799d0", "dummy1.txt"); + let expectedPath2 = resolveExpectedResultFilePath("2b2b0f58-3d88-432c-9955-1040315f96e9", "dummy2.txt"); + let expectedPath3 = resolveExpectedResultFilePath("2b2b0f58-3d88-432c-9955-1040315f96e9", "dummy3.txt"); + + assert.equal(testSuiteWithAttachments.cases[0].attachments.length, 1); + assert.equal(testSuiteWithAttachments.cases[0].attachments[0].path, expectedPath1); + + assert.equal(testSuiteWithAttachments.cases[1].attachments.length, 2); + assert.equal(testSuiteWithAttachments.cases[1].attachments[0].path, expectedPath2) + assert.equal(testSuiteWithAttachments.cases[1].attachments[1].path, expectedPath3) + }); + + it('Should report overall status as PASS if all tests pass', () => { + const result = parse({ type: 'mstest', files: [`${testDataPath}/testresults_pass.trx`] }); + assert.equal(result.status, "PASS"); + }); + + function resolveExpectedResultFilePath(executionId, filePath) { + return path.join( + "bryan.b.cook_MYCOMPUTER_2023-11-12_19_21_51", + "In", + executionId, + "MYCOMPUTER", + filePath); + } }); \ No newline at end of file diff --git a/tests/parser.nunit.spec.js b/tests/parser.nunit.spec.js index 54583f8..ef44a3b 100644 --- a/tests/parser.nunit.spec.js +++ b/tests/parser.nunit.spec.js @@ -60,11 +60,11 @@ describe('Parser - NUnit', () => { assert.equal(result.suites[0].status, "FAIL"); assert.equal(result.suites[0].cases[0].status, "FAIL"); // Failure assert.equal(result.suites[0].cases[8].status, "ERROR"); // Error - assert.equal(result.suites[1].status, "SKIP"); + assert.equal(result.suites[1].status, "SKIP"); assert.equal(result.suites[1].cases[0].status, "SKIP"); // NotRunnable - assert.equal(result.suites[2].status, "PASS"); + assert.equal(result.suites[2].status, "PASS"); assert.equal(result.suites[2].cases[0].status, "PASS"); // Success - assert.equal(result.suites[6].status, "SKIP"); + assert.equal(result.suites[6].status, "SKIP"); assert.equal(result.suites[6].cases[0].status, "SKIP"); // Ignored }); @@ -79,26 +79,35 @@ describe('Parser - NUnit', () => { assert.notEqual(result.suites[0].cases[0].stack_trace, ''); }); - it('Should map suite categories to testcases', () => { + it('Should map suite categories to test cases', () => { let count = 0; result.suites[0].cases.forEach( c => { count++; - assert.equal(c.meta_data.has("FixtureCategory"), true); - assert.equal(c.meta_data.get("Categories").includes("FixtureCategory"), true); + assert.equal(c.metadata["Categories"].includes("FixtureCategory"), true); }); assert.equal( count > 0, true); }); - it('Should map test-case categories and properties to testcases', () => { + it('Should map test-case categories and properties to test cases', () => { // case 3 has additional category + properties - let testcase = result.suites[0].cases[3]; - // categories - assert.equal(testcase.meta_data.has("MockCategory"), true); - assert.equal(testcase.meta_data.get("Categories").includes("MockCategory"), true); - assert.equal(testcase.meta_data.get("Categories"), "FixtureCategory,MockCategory"); // combined - - // properties - assert.equal(testcase.meta_data.get("Severity"),"Critical"); + let test_case = result.suites[0].cases[3]; + assert.deepEqual(test_case, { + id: '', + name: 'NUnit.Tests.Assemblies.MockTestFixture.MockTest2', + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 0, + status: 'PASS', + failure: '', + stack_trace: '', + tags: [ 'MockCategory' ], + metadata: { Categories: 'FixtureCategory,MockCategory', Severity: 'Critical' }, + steps: [], + attachments: [] + }); }); }); @@ -201,36 +210,106 @@ describe('Parser - NUnit', () => { }); it('Should support properties defined at the Assembly level', () => { - const testCaseWithNoProperties = result.suites[2].cases[0].meta_data; - assert.equal(testCaseWithNoProperties.size, 2, "Test case without properties should inherit from assembly"); - assert.equal(testCaseWithNoProperties.has("_PID"), true); - assert.equal(testCaseWithNoProperties.has("_APPDOMAIN"), true); + const test_case = testCaseWithNoProperties = result.suites[2].cases[0]; + assert.deepEqual(test_case, { + id: 1027, + name: 'NUnit.Tests.FixtureWithTestCases.MethodWithParameters(2,2)', + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 6, + status: 'PASS', + failure: '', + stack_trace: '', + tags: [], + metadata: { + _APPDOMAIN: 'test-domain-mock-assembly.dll', + _PID: 11928 + }, + steps: [], + attachments: [] + }); }); it('Should include both suite and assembly level properties', () => { - const testCaseWithSuiteProperties = result.suites[0].cases[0].meta_data - assert.equal(testCaseWithSuiteProperties.size, 5, "Suite with properties should inherit assembly properties"); - assert.equal(testCaseWithSuiteProperties.has("_PID"), true); - assert.equal(testCaseWithSuiteProperties.has("_APPDOMAIN"), true); - assert.equal(testCaseWithSuiteProperties.has("Description"), true); - assert.equal(testCaseWithSuiteProperties.get("Description"), "Fake Test Fixture"); + const test_case = result.suites[0].cases[0]; + assert.deepEqual(test_case, { + id: 1005, + name: 'NUnit.Tests.Assemblies.MockTestFixture.FailingTest', + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 23, + status: 'FAIL', + failure: 'Intentional failure', + stack_trace: " at NUnit.Framework.Assert.Fail(String message, Object[] args) in D:\\Dev\\NUnit\\nunit-3.0\\work\\NUnitFramework\\src\\framework\\Assert.cs:line 142\n at NUnit.Framework.Assert.Fail(String message) in D:\\Dev\\NUnit\\nunit-3.0\\work\\NUnitFramework\\src\\framework\\Assert.cs:line 152\n at NUnit.Tests.Assemblies.MockTestFixture.FailingTest() in D:\\Dev\\NUnit\\nunit-3.0\\work\\NUnitFramework\\src\\mock-assembly\\MockAssembly.cs:line 121", + tags: [], + metadata: { + Categories: "FixtureCategory", + _APPDOMAIN: 'test-domain-mock-assembly.dll', + _PID: 11928, + Description: 'Fake Test Fixture' + }, + steps: [], + attachments: [] + }); }); it('Should include properties from assembly, suite and test case', () => { - - const testCaseWithProperties = result.suites[0].cases[2].meta_data; - assert.equal(testCaseWithProperties.size, 5, "Test case with properties should iherit assembly, suite and override"); - assert.equal(testCaseWithProperties.has("_PID"), true); - assert.equal(testCaseWithProperties.has("_APPDOMAIN"), true); - assert.equal(testCaseWithProperties.get("Description"), "Mock Test #1"); + const test_case = result.suites[0].cases[2]; + assert.deepEqual(test_case, { + id: 1001, + name: 'NUnit.Tests.Assemblies.MockTestFixture.MockTest1', + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 0, + status: 'PASS', + failure: '', + stack_trace: '', + tags: [], + metadata: { + _PID: 11928, + _APPDOMAIN: 'test-domain-mock-assembly.dll', + Categories: 'FixtureCategory', + Description: 'Mock Test #1' + }, + steps: [], + attachments: [] + }); }); it('Should allow multiple categories to be specified', () => { - const testCaseWithMultipleCategories = result.suites[0].cases[3].meta_data; - assert.equal(testCaseWithMultipleCategories.has("Categories"), true); - assert.equal(testCaseWithMultipleCategories.get("Categories"), "FixtureCategory,MockCategory"); - assert.equal(testCaseWithMultipleCategories.has("FixtureCategory"), true); - assert.equal(testCaseWithMultipleCategories.has("MockCategory"), true); + const test_case = result.suites[0].cases[3]; + assert.deepEqual(test_case, { + id: 1002, + name: 'NUnit.Tests.Assemblies.MockTestFixture.MockTest2', + total: 0, + passed: 0, + failed: 0, + errors: 0, + skipped: 0, + duration: 0, + status: 'PASS', + failure: '', + stack_trace: '', + tags: [], + metadata: { + _PID: 11928, + _APPDOMAIN: 'test-domain-mock-assembly.dll', + Categories: 'FixtureCategory,MockCategory', + Description: 'This is a really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really long description', + Severity: 'Critical' + }, + steps: [], + attachments: [] + }); }); it('Should include attachments associated to test-case', () => { diff --git a/tests/parser.testng.spec.js b/tests/parser.testng.spec.js index 0bd9ecc..719af1c 100644 --- a/tests/parser.testng.spec.js +++ b/tests/parser.testng.spec.js @@ -17,6 +17,8 @@ describe('Parser - TestNG', () => { retried: 0, duration: 2000, status: 'PASS', + tags: [], + metadata: {}, suites: [ { id: '', @@ -28,7 +30,8 @@ describe('Parser - TestNG', () => { skipped: 0, duration: 2000, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -43,7 +46,8 @@ describe('Parser - TestNG', () => { status: 'PASS', failure: '', stack_trace: '', - meta_data: new Map(), + tags: [], + metadata: {}, steps: [] }, { @@ -59,7 +63,8 @@ describe('Parser - TestNG', () => { status: 'PASS', failure: '', stack_trace: '', - meta_data: new Map(), + tags: [], + metadata: {}, steps: [] }, { @@ -75,7 +80,8 @@ describe('Parser - TestNG', () => { status: 'PASS', failure: '', stack_trace: '', - meta_data: new Map(), + tags: [], + metadata: {}, steps: [] }, { @@ -91,7 +97,8 @@ describe('Parser - TestNG', () => { status: 'PASS', failure: 'expected [true] but found [false]', stack_trace: '', - meta_data: new Map(), + tags: [], + metadata: {}, steps: [] } ] @@ -113,6 +120,8 @@ describe('Parser - TestNG', () => { "retried": 0, "duration": 1403931, "status": "FAIL", + "tags": [], + "metadata": {}, "suites": [ { "id": "", @@ -124,7 +133,8 @@ describe('Parser - TestNG', () => { "skipped": 0, "duration": 202082, "status": "FAIL", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "cases": [ { "attachments": [], @@ -139,7 +149,9 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "expected [A] but found [948474]", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "tags": [], + "metadata": {}, "steps": [] }, { @@ -155,7 +167,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -171,7 +184,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -187,7 +201,8 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "Expected condition failed: : <95ddbda01ea4b3dbcb049e681a6>", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -203,7 +218,8 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "element click intercepted:", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] } ] @@ -218,7 +234,8 @@ describe('Parser - TestNG', () => { "skipped": 1, "duration": 545598, "status": "FAIL", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "cases": [ { "attachments": [], @@ -233,7 +250,8 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "expected [A] but found [948474]", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -249,7 +267,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -265,7 +284,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -281,7 +301,8 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "Appium error: An unknown sr='Search...']}", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -297,7 +318,8 @@ describe('Parser - TestNG', () => { "status": "SKIP", "failure": "A script did not complete ", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] } ] @@ -319,6 +341,8 @@ describe('Parser - TestNG', () => { "retried": 0, "duration": 2000, "status": "PASS", + "tags": [], + "metadata": {}, "suites": [ { "id": "", @@ -330,7 +354,8 @@ describe('Parser - TestNG', () => { "skipped": 0, "duration": 2000, "status": "PASS", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "cases": [ { "attachments": [], @@ -345,7 +370,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -361,7 +387,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -377,7 +404,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -393,7 +421,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "expected [true] but found [false]", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] } ] @@ -415,6 +444,8 @@ describe('Parser - TestNG', () => { "retried": 0, "duration": 4000, "status": "PASS", + "tags": [], + "metadata": {}, "suites": [ { "id": "", @@ -426,7 +457,8 @@ describe('Parser - TestNG', () => { "skipped": 0, "duration": 2000, "status": "PASS", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "cases": [ { "attachments": [], @@ -441,7 +473,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -457,7 +490,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -473,7 +507,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -489,7 +524,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "expected [true] but found [false]", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] } ] @@ -504,7 +540,8 @@ describe('Parser - TestNG', () => { "skipped": 0, "duration": 2000, "status": "PASS", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "cases": [ { "attachments": [], @@ -519,7 +556,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -535,7 +573,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -551,7 +590,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -567,7 +607,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "expected [true] but found [false]", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] } ] @@ -589,6 +630,8 @@ describe('Parser - TestNG', () => { "retried": 2, "duration": 1883597, "status": "FAIL", + "tags": [], + "metadata": {}, "suites": [ { "id": "", @@ -600,7 +643,8 @@ describe('Parser - TestNG', () => { "skipped": 0, "duration": 1164451, "status": "FAIL", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "cases": [ { "attachments": [], @@ -615,7 +659,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -631,7 +676,8 @@ describe('Parser - TestNG', () => { "status": "RETRY", "failure": "failed", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -647,7 +693,8 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "failed", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -663,7 +710,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] } ] @@ -678,7 +726,8 @@ describe('Parser - TestNG', () => { "skipped": 0, "duration": 714100, "status": "FAIL", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "cases": [ { "attachments": [], @@ -693,7 +742,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -709,7 +759,8 @@ describe('Parser - TestNG', () => { "status": "RETRY", "failure": "failed", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -725,7 +776,8 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "failed", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -741,7 +793,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] } ] @@ -763,6 +816,8 @@ describe('Parser - TestNG', () => { "retried": 0, "duration": 1405931, "status": "FAIL", + "tags": [], + "metadata": {}, "suites": [ { "id": "", @@ -774,7 +829,8 @@ describe('Parser - TestNG', () => { "skipped": 0, "duration": 202082, "status": "FAIL", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "cases": [ { "attachments": [], @@ -789,7 +845,8 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "expected [A] but found [948474]", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -805,7 +862,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -821,7 +879,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -837,7 +896,8 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "Expected condition failed: : <95ddbda01ea4b3dbcb049e681a6>", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -853,7 +913,8 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "element click intercepted:", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] } ] @@ -868,7 +929,8 @@ describe('Parser - TestNG', () => { "skipped": 1, "duration": 545598, "status": "FAIL", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "cases": [ { "attachments": [], @@ -883,7 +945,8 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "expected [A] but found [948474]", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -899,7 +962,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -915,7 +979,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -931,7 +996,8 @@ describe('Parser - TestNG', () => { "status": "FAIL", "failure": "Appium error: An unknown sr='Search...']}", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -947,7 +1013,8 @@ describe('Parser - TestNG', () => { "status": "SKIP", "failure": "A script did not complete ", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] } ] @@ -962,7 +1029,8 @@ describe('Parser - TestNG', () => { "skipped": 0, "duration": 2000, "status": "PASS", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "cases": [ { "attachments": [], @@ -977,7 +1045,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -993,7 +1062,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -1009,7 +1079,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] }, { @@ -1025,7 +1096,8 @@ describe('Parser - TestNG', () => { "status": "PASS", "failure": "expected [true] but found [false]", "stack_trace": "", - "meta_data": new Map(), + "tags": [], + "metadata": {}, "steps": [] } ] @@ -1047,6 +1119,8 @@ describe('Parser - TestNG', () => { retried: 0, duration: 0, status: 'PASS', + tags: [], + metadata: {}, suites: [] }); }); @@ -1056,17 +1130,13 @@ describe('Parser - TestNG', () => { let absolutePath = path.resolve(relativePath); const result1 = parse({ type: 'testng', files: [absolutePath] }); assert.notEqual(null, result1); - const result2 = parse({ type: 'testng', files: [relativePath]}); + const result2 = parse({ type: 'testng', files: [relativePath] }); assert.notEqual(null, result2); }); it('assign groups to testcases in single suite', () => { const result = parse({ type: 'testng', files: ['tests/data/testng/groups.xml'] }); - assert.equal(result.suites[0].cases[0].meta_data.get("groups"), "group1"); - assert.equal(result.suites[0].cases[0].meta_data.has("group1"), true); - // 2nd testcase has multiple groups - assert.equal(result.suites[0].cases[1].meta_data.get("groups"), "group1,group2"); - assert.equal(result.suites[0].cases[1].meta_data.has("group1"), true); - assert.equal(result.suites[0].cases[1].meta_data.has("group2"), true); + assert.deepEqual(result.suites[0].cases[0].tags, ['group1']); + assert.deepEqual(result.suites[0].cases[1].tags, ['group1', 'group2']); }); }); \ No newline at end of file diff --git a/tests/parser.xunit.spec.js b/tests/parser.xunit.spec.js index 4dbca40..44ba4da 100644 --- a/tests/parser.xunit.spec.js +++ b/tests/parser.xunit.spec.js @@ -5,7 +5,7 @@ const path = require('path'); describe('Parser - XUnit', () => { const testDataPath = "tests/data/xunit"; - + it('single suite with single test', () => { const result = parse({ type: 'xunit', files: [`${testDataPath}/single-suite.xml`] }); assert.deepEqual(result, { @@ -19,6 +19,8 @@ describe('Parser - XUnit', () => { retried: 0, duration: 86006.5, status: 'FAIL', + tags: [], + metadata: {}, suites: [ { id: '', @@ -30,7 +32,8 @@ describe('Parser - XUnit', () => { skipped: 0, duration: 86006.5, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -44,8 +47,9 @@ describe('Parser - XUnit', () => { skipped: 0, stack_trace: "", status: "FAIL", + tags: [], + metadata: { TestID: "ID", TestLevel: "Regression", TestProduct: "TestProductExample", TestSuite: "TestSuiteExample" }, steps: [], - meta_data: newMap({ TestID: "ID", TestLevel: "Regression", TestProduct: "TestProductExample", TestSuite: "TestSuiteExample"}), total: 0 } ] @@ -53,6 +57,7 @@ describe('Parser - XUnit', () => { ] }); }); + it('suite with single skipped test', () => { const result = parse({ type: 'xunit', files: [`${testDataPath}/skipped-suite.xml`] }); assert.deepEqual(result, { @@ -66,6 +71,8 @@ describe('Parser - XUnit', () => { retried: 0, duration: 1, status: 'PASS', + tags: [], + metadata: {}, suites: [ { id: '', @@ -77,28 +84,32 @@ describe('Parser - XUnit', () => { skipped: 1, duration: 1, status: 'PASS', - meta_data: new Map(), - cases: [ + tags: [], + metadata: {}, + cases: [ { - attachments: [], - duration: 1, - errors: 0, - failed: 0, - failure: "", - id: "", - name: "SkippedTest", - passed: 0, - skipped: 0, - stack_trace: "", - status: "SKIP", - steps: [], - meta_data: newMap({ UnsupportedEnvirnoment: "uat"}), - total: 0 - }] + attachments: [], + duration: 1, + errors: 0, + failed: 0, + failure: "", + id: "", + name: "SkippedTest", + passed: 0, + skipped: 0, + stack_trace: "", + status: "SKIP", + tags: [], + metadata: { UnsupportedEnvirnoment: "uat" }, + steps: [], + total: 0 + } + ] } ] }); }); + it('multiple suites', () => { const result = parse({ type: 'xunit', files: [`${testDataPath}/multiple-suites.xml`] }); const expectedObj = { @@ -112,6 +123,8 @@ describe('Parser - XUnit', () => { retried: 0, duration: 348807, status: 'FAIL', + tags: [], + metadata: {}, suites: [ { id: '', @@ -123,7 +136,8 @@ describe('Parser - XUnit', () => { skipped: 0, duration: 92155, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -137,8 +151,9 @@ describe('Parser - XUnit', () => { skipped: 0, stack_trace: "", status: "FAIL", + tags: [], + metadata: { TestID: "RTA-21505", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite" }, steps: [], - meta_data: newMap({ TestID: "RTA-21505", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite"}), total: 0 }, { @@ -153,8 +168,9 @@ describe('Parser - XUnit', () => { skipped: 0, stack_trace: "", status: "PASS", + tags: [], + metadata: { TestID: "RTA-21510", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite" }, steps: [], - meta_data: newMap({ TestID: "RTA-21510", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite"}), total: 0 } ] @@ -169,7 +185,8 @@ describe('Parser - XUnit', () => { skipped: 0, duration: 85450, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -183,10 +200,11 @@ describe('Parser - XUnit', () => { skipped: 0, stack_trace: "", status: "FAIL", + tags: [], + metadata: { TestID: "RTA-21516", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite" }, steps: [], - meta_data: newMap({ TestID: "RTA-21516", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite"}), total: 0 - }, + }, { attachments: [], duration: 1791.1067, @@ -199,8 +217,9 @@ describe('Parser - XUnit', () => { skipped: 0, stack_trace: "", status: "PASS", + tags: [], + metadata: { TestID: "RTA-21513", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite" }, steps: [], - meta_data: newMap({ TestID: "RTA-21513", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite"}), total: 0 } ] @@ -215,7 +234,8 @@ describe('Parser - XUnit', () => { skipped: 0, duration: 84195, status: 'PASS', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -229,8 +249,9 @@ describe('Parser - XUnit', () => { skipped: 0, stack_trace: "", status: "PASS", + tags: [], + metadata: { TestID: "RTA-21538", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite" }, steps: [], - meta_data: newMap({ TestID: "RTA-21538", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite"}), total: 0 } ] @@ -245,7 +266,8 @@ describe('Parser - XUnit', () => { skipped: 0, duration: 86007, status: 'FAIL', - meta_data: new Map(), + tags: [], + metadata: {}, cases: [ { attachments: [], @@ -259,15 +281,16 @@ describe('Parser - XUnit', () => { skipped: 0, stack_trace: "", status: "FAIL", + tags: [], + metadata: { TestID: "RTA-37684", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite" }, steps: [], - meta_data: newMap({ TestID: "RTA-37684", TestLevel: "Regression", TestProduct: "ExampleTestProduct", TestSuite: "ExampleTestSuite"}), total: 0 } ] } ] } - assert.deepEqual(result, expectedObj ); + assert.deepEqual(result, expectedObj); }); it('can support absolute and relative file paths', () => { @@ -275,25 +298,23 @@ describe('Parser - XUnit', () => { let absolutePath = path.resolve(relativePath); const result1 = parse({ type: 'xunit', files: [absolutePath] }); assert.notEqual(null, result1); - const result2 = parse({ type: 'xunit', files: [relativePath]}); + const result2 = parse({ type: 'xunit', files: [relativePath] }); assert.notEqual(null, result2); }); it('meta-data from traits', () => { const result = parse({ type: 'xunit', files: ['tests/data/xunit/single-suite.xml'] }); - assert.equal(result.suites[0].cases[0].meta_data.size, 4); + assert.deepEqual(result.suites[0].cases[0].metadata, { + TestID: 'ID', + TestLevel: 'Regression', + TestProduct: 'TestProductExample', + TestSuite: 'TestSuiteExample' + }); }); - + it('no meta-data from empty traits', () => { const result = parse({ type: 'xunit', files: ['tests/data/xunit/no-traits-suite.xml'] }); - assert.equal(result.suites[0].cases[0].meta_data.size, 0); - }) + assert.deepEqual(result.suites[0].cases[0].metadata, {}); + }); - function newMap( obj ) { - let map = new Map(); - for (const property in obj) { - map.set( property, obj[property]); - } - return map; - } }); \ No newline at end of file