diff --git a/packages/bruno-cli/src/reporters/junit.js b/packages/bruno-cli/src/reporters/junit.js
index 71d523b94..3a6611ba6 100644
--- a/packages/bruno-cli/src/reporters/junit.js
+++ b/packages/bruno-cli/src/reporters/junit.js
@@ -1,6 +1,7 @@
const os = require('os');
const fs = require('fs');
const xmlbuilder = require('xmlbuilder');
+const { stripExtension } = require('../utils/filesystem');
const makeJUnitOutput = async (results, outputPath) => {
const output = {
@@ -15,6 +16,7 @@ const makeJUnitOutput = async (results, outputPath) => {
const testCount = result.testResults ? result.testResults.length : 0;
const postResponseTestCount = result.postResponseTestResults ? result.postResponseTestResults.length : 0;
const totalTests = assertionTestCount + preRequestTestCount + testCount + postResponseTestCount;
+ const classname = stripExtension(result.path);
const suite = {
'@name': result.name,
@@ -34,7 +36,7 @@ const makeJUnitOutput = async (results, outputPath) => {
const testcase = {
'@name': `${assertion.lhsExpr} ${assertion.rhsExpr}`,
'@status': assertion.status,
- '@classname': result.request.url,
+ '@classname': classname,
'@time': (result.runDuration / totalTests).toFixed(3)
};
@@ -52,7 +54,7 @@ const makeJUnitOutput = async (results, outputPath) => {
const testcase = {
'@name': test.description,
'@status': test.status,
- '@classname': result.request.url,
+ '@classname': classname,
'@time': (result.runDuration / totalTests).toFixed(3)
};
@@ -70,7 +72,7 @@ const makeJUnitOutput = async (results, outputPath) => {
const testcase = {
'@name': test.description,
'@status': test.status,
- '@classname': result.request.url,
+ '@classname': classname,
'@time': (result.runDuration / totalTests).toFixed(3)
};
@@ -88,7 +90,7 @@ const makeJUnitOutput = async (results, outputPath) => {
const testcase = {
'@name': test.description,
'@status': test.status,
- '@classname': result.request.url,
+ '@classname': classname,
'@time': (result.runDuration / totalTests).toFixed(3)
};
@@ -110,7 +112,7 @@ const makeJUnitOutput = async (results, outputPath) => {
{
'@name': 'Test suite has no errors',
'@status': 'fail',
- '@classname': result.request.url,
+ '@classname': classname,
'@time': result.runDuration.toFixed(3),
'error': [{ '@type': 'error', '@message': result.error }]
}
diff --git a/packages/bruno-cli/tests/reporters/junit.spec.js b/packages/bruno-cli/tests/reporters/junit.spec.js
index 30430b370..f53d3710a 100644
--- a/packages/bruno-cli/tests/reporters/junit.spec.js
+++ b/packages/bruno-cli/tests/reporters/junit.spec.js
@@ -103,6 +103,36 @@ describe('makeJUnitOutput', () => {
expect(failcase.failure[0]['@type']).toBe('failure');
});
+ it('should use the request path as the testcase classname instead of the request url', () => {
+ const results = [
+ {
+ name: '1st API',
+ path: 'f1/1st API.bru',
+ test: {
+ filename: 'f1/1st API.bru'
+ },
+ request: {
+ method: 'GET',
+ url: 'https://ima.test'
+ },
+ testResults: [
+ {
+ description: 'Status is 200',
+ status: 'pass'
+ }
+ ],
+ runDuration: 1.2345678
+ }
+ ];
+
+ makeJUnitOutput(results, '/tmp/testfile.xml');
+
+ const junit = xmlbuilder.create.mock.calls[0][0];
+ const testcase = junit.testsuites.testsuite[0].testcase[0];
+
+ expect(testcase['@classname']).toBe('f1/1st API');
+ });
+
it('should handle request errors', () => {
const results = [
{
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 8d710b3a1..2121ec320 100644
--- a/tests/runner/collection-run-report/collection-run-report.spec.ts
+++ b/tests/runner/collection-run-report/collection-run-report.spec.ts
@@ -10,11 +10,7 @@ function normalizeJunitReport(xmlContent: string): string {
// Replace hostnames with fixed value
.replace(/hostname="[^"]*"/g, 'hostname="test-host"')
// 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"');
+ .replace(/time="[^"]*"/g, 'time="0.100"');
}
test.describe('Collection Run Report Tests', () => {
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 4325f1814..d4a0db669 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,29 +1,29 @@
-
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
+
+
-
+
\ No newline at end of file
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 4325f1814..d4a0db669 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,29 +1,29 @@
-
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
+
+
-
+
\ No newline at end of file
diff --git a/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-win32.xml b/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-win32.xml
index 4325f1814..525402824 100644
--- a/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-win32.xml
+++ b/tests/runner/collection-run-report/collection-run-report.spec.ts-snapshots/cli-junit-report-default-win32.xml
@@ -1,29 +1,29 @@
-
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
+
+
-
+
\ No newline at end of file