From f47e9e9304f1908bb8076fd1ff0a46ec7819e5e0 Mon Sep 17 00:00:00 2001 From: Thomas <20792077+fantpmas@users.noreply.github.com> Date: Fri, 19 Dec 2025 14:30:15 +0100 Subject: [PATCH] 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 Co-authored-by: Bijin A B --- .../Sections/CollectionsSection/index.js | 2 +- packages/bruno-cli/src/reporters/junit.js | 1 + .../bruno-cli/tests/reporters/junit.spec.js | 17 +++++++++++++++++ .../collection-run-report.spec.ts | 2 ++ .../cli-junit-report-default-darwin.xml | 8 ++++---- .../cli-junit-report-default-linux.xml | 8 ++++---- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/packages/bruno-app/src/components/Sidebar/Sections/CollectionsSection/index.js b/packages/bruno-app/src/components/Sidebar/Sections/CollectionsSection/index.js index 120b02cd9..ce812931b 100644 --- a/packages/bruno-app/src/components/Sidebar/Sections/CollectionsSection/index.js +++ b/packages/bruno-app/src/components/Sidebar/Sections/CollectionsSection/index.js @@ -11,7 +11,7 @@ import { IconSortAscendingLetters, IconSortDescendingLetters, IconSquareX, - IconBox, + IconBox, IconTerminal2 } from '@tabler/icons'; diff --git a/packages/bruno-cli/src/reporters/junit.js b/packages/bruno-cli/src/reporters/junit.js index df0430381..71d523b94 100644 --- a/packages/bruno-cli/src/reporters/junit.js +++ b/packages/bruno-cli/src/reporters/junit.js @@ -18,6 +18,7 @@ const makeJUnitOutput = async (results, outputPath) => { const suite = { '@name': result.name, + '@file': result.test.filename, '@errors': 0, '@failures': 0, '@skipped': 0, diff --git a/packages/bruno-cli/tests/reporters/junit.spec.js b/packages/bruno-cli/tests/reporters/junit.spec.js index 6c9303d2f..30430b370 100644 --- a/packages/bruno-cli/tests/reporters/junit.spec.js +++ b/packages/bruno-cli/tests/reporters/junit.spec.js @@ -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]; diff --git a/tests/runner/collection-run-report/collection-run-report.spec.ts b/tests/runner/collection-run-report/collection-run-report.spec.ts index e106a91d2..9db409257 100644 --- a/tests/runner/collection-run-report/collection-run-report.spec.ts +++ b/tests/runner/collection-run-report/collection-run-report.spec.ts @@ -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"'); } diff --git a/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-darwin.xml b/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-darwin.xml index a1a6d34a1..4325f1814 100644 --- a/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-darwin.xml +++ b/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-darwin.xml @@ -1,12 +1,12 @@ - + - + @@ -15,12 +15,12 @@ - + - + diff --git a/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-linux.xml b/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-linux.xml index a1a6d34a1..4325f1814 100644 --- a/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-linux.xml +++ b/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-linux.xml @@ -1,12 +1,12 @@ - + - + @@ -15,12 +15,12 @@ - + - +