Add file attribute to Junit testsuite report (#6425)

* feat: add file attribute to Junit testsuite report

* test: update tests to include file attribute

* fix: update playwright tests to support the new file attribute

---------

Co-authored-by: Thomas Vackier <thomas.vackier@inthepocket.com>
Co-authored-by: Bijin A B <bijin@usebruno.com>
This commit is contained in:
Thomas
2025-12-19 14:30:15 +01:00
committed by GitHub
parent 5f88e7d201
commit f47e9e9304
6 changed files with 29 additions and 9 deletions

View File

@@ -11,7 +11,7 @@ import {
IconSortAscendingLetters,
IconSortDescendingLetters,
IconSquareX,
IconBox,
IconBox,
IconTerminal2
} from '@tabler/icons';

View File

@@ -18,6 +18,7 @@ const makeJUnitOutput = async (results, outputPath) => {
const suite = {
'@name': result.name,
'@file': result.test.filename,
'@errors': 0,
'@failures': 0,
'@skipped': 0,

View File

@@ -23,6 +23,9 @@ describe('makeJUnitOutput', () => {
{
description: 'description provided',
name: 'Tests/Suite A',
test: {
filename: 'Tests/Suite A.bru'
},
request: {
method: 'GET',
url: 'https://ima.test'
@@ -48,6 +51,9 @@ describe('makeJUnitOutput', () => {
url: 'https://imanother.test'
},
name: 'Tests/Suite B',
test: {
filename: 'Tests/Suite B.bru'
},
testResults: [
{
lhsExpr: 'res.status',
@@ -79,6 +85,9 @@ describe('makeJUnitOutput', () => {
expect(junit.testsuites.testsuite[0]['@name']).toBe('Tests/Suite A');
expect(junit.testsuites.testsuite[1]['@name']).toBe('Tests/Suite B');
expect(junit.testsuites.testsuite[0]['@file']).toBe('Tests/Suite A.bru');
expect(junit.testsuites.testsuite[1]['@file']).toBe('Tests/Suite B.bru');
expect(junit.testsuites.testsuite[0]['@tests']).toBe(2);
expect(junit.testsuites.testsuite[1]['@tests']).toBe(2);
@@ -99,6 +108,9 @@ describe('makeJUnitOutput', () => {
{
description: 'description provided',
name: 'Tests/Suite A',
test: {
filename: 'Tests/Suite A.bru'
},
request: {
method: 'GET',
url: 'https://ima.test'
@@ -124,6 +136,7 @@ describe('makeJUnitOutput', () => {
expect(junit.testsuites).toBeDefined;
expect(junit.testsuites.testsuite.length).toBe(1);
expect(junit.testsuites.testsuite[0].testcase.length).toBe(1);
expect(junit.testsuites.testsuite[0]['@file']).toBe('Tests/Suite A.bru');
const failcase = junit.testsuites.testsuite[0].testcase[0];
@@ -137,6 +150,9 @@ describe('makeJUnitOutput', () => {
const results = [
{
name: 'Tests/Suite A',
test: {
filename: 'Tests/Suite A.bru'
},
request: {
method: 'GET',
url: 'https://ima.test'
@@ -176,6 +192,7 @@ describe('makeJUnitOutput', () => {
expect(junit.testsuites).toBeDefined;
expect(junit.testsuites.testsuite.length).toBe(1);
expect(junit.testsuites.testsuite[0].testcase.length).toBe(4);
expect(junit.testsuites.testsuite[0]['@file']).toBe('Tests/Suite A.bru');
expect(junit.testsuites.testsuite[0]['@tests']).toBe(4);
const testcase1 = junit.testsuites.testsuite[0].testcase[0];

View File

@@ -12,6 +12,8 @@ function normalizeJunitReport(xmlContent: string): string {
// Replace execution times with fixed value
.replace(/time="[^"]*"/g, 'time="0.100"')
// Replace file paths with normalized path
.replace(/file="[^"]*\/[^"]*"/g, 'file="/mock/path/to/file.bru"')
// Replace test paths with normalized path
.replace(/classname="[^"]*\/[^"]*"/g, 'classname="/test/path/collection"');
}

View File

@@ -1,12 +1,12 @@
<?xml version="1.0"?>
<testsuites>
<testsuite name="Get User Info" errors="0" failures="0" skipped="0" tests="4" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testsuite name="Get User Info" file="/mock/path/to/file.bru" errors="0" failures="0" skipped="0" tests="4" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testcase name="Status code is 200" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="Response is an object" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="Response has slideshow property" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="Slideshow has title" status="pass" classname="/test/path/collection" time="0.100"/>
</testsuite>
<testsuite name="Get UUID" errors="0" failures="1" skipped="0" tests="5" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testsuite name="Get UUID" file="/mock/path/to/file.bru" errors="0" failures="1" skipped="0" tests="5" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testcase name="This test will fail" status="fail" classname="/test/path/collection" time="0.100">
<failure type="failure" message="expected 200 to equal 404"/>
</testcase>
@@ -15,12 +15,12 @@
<testcase name="Response has uuid property" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="UUID is a string" status="pass" classname="/test/path/collection" time="0.100"/>
</testsuite>
<testsuite name="Login Request" errors="0" failures="0" skipped="0" tests="3" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testsuite name="Login Request" file="/mock/path/to/file.bru" errors="0" failures="0" skipped="0" tests="3" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testcase name="Status code is 200" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="Response has json field" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="Response json has username" status="pass" classname="/test/path/collection" time="0.100"/>
</testsuite>
<testsuite name="Logout Request" errors="0" failures="1" skipped="0" tests="2" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testsuite name="Logout Request" file="/mock/path/to/file.bru" errors="0" failures="1" skipped="0" tests="2" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testcase name="This test will also fail" status="fail" classname="/test/path/collection" time="0.100">
<failure type="failure" message="expected 200 to equal 500"/>
</testcase>

View File

@@ -1,12 +1,12 @@
<?xml version="1.0"?>
<testsuites>
<testsuite name="Get User Info" errors="0" failures="0" skipped="0" tests="4" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testsuite name="Get User Info" file="/mock/path/to/file.bru" errors="0" failures="0" skipped="0" tests="4" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testcase name="Status code is 200" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="Response is an object" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="Response has slideshow property" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="Slideshow has title" status="pass" classname="/test/path/collection" time="0.100"/>
</testsuite>
<testsuite name="Get UUID" errors="0" failures="1" skipped="0" tests="5" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testsuite name="Get UUID" file="/mock/path/to/file.bru" errors="0" failures="1" skipped="0" tests="5" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testcase name="This test will fail" status="fail" classname="/test/path/collection" time="0.100">
<failure type="failure" message="expected 200 to equal 404"/>
</testcase>
@@ -15,12 +15,12 @@
<testcase name="Response has uuid property" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="UUID is a string" status="pass" classname="/test/path/collection" time="0.100"/>
</testsuite>
<testsuite name="Login Request" errors="0" failures="0" skipped="0" tests="3" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testsuite name="Login Request" file="/mock/path/to/file.bru" errors="0" failures="0" skipped="0" tests="3" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testcase name="Status code is 200" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="Response has json field" status="pass" classname="/test/path/collection" time="0.100"/>
<testcase name="Response json has username" status="pass" classname="/test/path/collection" time="0.100"/>
</testsuite>
<testsuite name="Logout Request" errors="0" failures="1" skipped="0" tests="2" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testsuite name="Logout Request" file="/mock/path/to/file.bru" errors="0" failures="1" skipped="0" tests="2" timestamp="2024-01-01T00:00:00.000" hostname="test-host" time="0.100">
<testcase name="This test will also fail" status="fail" classname="/test/path/collection" time="0.100">
<failure type="failure" message="expected 200 to equal 500"/>
</testcase>