Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include JUnit hostname in meta_data #54

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/parsers/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ const TestResult = require('../models/TestResult');
const TestSuite = require('../models/TestSuite');
const TestCase = require('../models/TestCase');
const TestAttachment = require('../models/TestAttachment');
const { Test } = require('mocha');
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;
test_case.meta_data = new Map(suite_meta);
setAttachments(rawCase, test_case);
setMetaData(rawCase.properties, test_case);
setMetaData(rawCase, test_case);
if (rawCase.failure && rawCase.failure.length > 0) {
test_case.status = 'FAIL';
test_case.setFailure(rawCase.failure[0]["@_message"]);
Expand All @@ -38,28 +39,34 @@ 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;
}

/**
*
* @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"]);
}
}
// handle testsuite specific attributes
if (test_element instanceof TestSuite) {
if (rawElement["@_hostname"]) {
test_element.meta_data.set("hostname", rawElement["@_hostname"]);
}
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/parsers/junit.result.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type JUnitTestSuite = {
'@_tests': number;
'@_failures': number;
'@_time': number;
'@_hostname': string;
}

export type JUnitResult = {
Expand Down
23 changes: 23 additions & 0 deletions tests/data/junit/playwright.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<testsuites id="" name="" tests="9" failures="0" skipped="0" errors="0" time="58.798214">
<testsuite name="example.spec.ts" timestamp="2024-02-12T01:09:14.317Z" hostname="chromium" tests="2" failures="0" skipped="0" time="4.508" errors="0">
<testcase name="has title" classname="example.spec.ts" time="3.209">
</testcase>
<testcase name="get started link" classname="example.spec.ts" time="1.299">
</testcase>
</testsuite>

<testsuite name="example.spec.ts" timestamp="2024-02-12T01:09:14.317Z" hostname="firefox" tests="2" failures="0" skipped="0" time="4.743" errors="0">
<testcase name="has title" classname="example.spec.ts" time="3.066">
</testcase>
<testcase name="get started link" classname="example.spec.ts" time="1.677">
</testcase>
</testsuite>

<testsuite name="example.spec.ts" timestamp="2024-02-12T01:09:14.317Z" hostname="webkit" tests="2" failures="0" skipped="0" time="5.129" errors="0">
<testcase name="has title" classname="example.spec.ts" time="2.657">
</testcase>
<testcase name="get started link" classname="example.spec.ts" time="2.472">
</testcase>
</testsuite>

</testsuites>
Loading
Loading