From de530a889c97c6ed235ecb16d3a77cf2c456f639 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 15 Dec 2023 10:09:20 -0500 Subject: [PATCH] adding request-level error reporting --- packages/bruno-cli/src/commands/run.js | 17 +++++++- packages/bruno-cli/tests/commands/run.spec.js | 39 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index 6fee148fe..42b45b637 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -174,7 +174,7 @@ const makeJunitOutput = async (results, outputPath) => { } }; - results.forEach((result, idx) => { + results.forEach((result) => { const assertionTestCount = result.assertionResults ? result.assertionResults.length : 0; const testCount = result.testResults ? result.testResults.length : 0; const totalTests = assertionTestCount + testCount; @@ -212,7 +212,6 @@ const makeJunitOutput = async (results, outputPath) => { result.testResults && result.testResults.forEach((test) => { const testcase = { - '@type': 'testcase', '@name': test.description, '@status': test.status, '@classname': result.request.url, @@ -228,6 +227,20 @@ const makeJunitOutput = async (results, outputPath) => { suite.testcase.push(testcase); }); + if (result.error) { + suite['@errors'] = 1; + suite['@tests'] = 1; + suite.testcase = [ + { + '@name': 'Test suite has no errors', + '@status': 'fail', + '@classname': result.request.url, + '@time': result.runtime.toFixed(3), + error: [{ '@type': 'error', '@message': result.error }] + } + ]; + } + output.testsuites.testsuite.push(suite); }); diff --git a/packages/bruno-cli/tests/commands/run.spec.js b/packages/bruno-cli/tests/commands/run.spec.js index 7b69da7f8..375620885 100644 --- a/packages/bruno-cli/tests/commands/run.spec.js +++ b/packages/bruno-cli/tests/commands/run.spec.js @@ -157,4 +157,43 @@ describe('makeJUnitOutput', () => { expect(failcase.failure).toBeDefined; expect(failcase.failure[0]['@type']).toBe('failure'); }); + + it('should handle request errors', () => { + const results = [ + { + description: 'description provided', + suitename: 'Tests/Suite A', + request: { + method: 'GET', + url: 'https://ima.test' + }, + assertionResults: [ + { + lhsExpr: 'res.status', + rhsExpr: 'eq 200', + status: 'fail' + } + ], + runtime: 1.2345678, + error: 'timeout of 2000ms exceeded' + } + ]; + + makeJunitOutput(results, '/tmp/testfile.xml'); + + const junit = xmlbuilder.create.mock.calls[0][0]; + + expect(createStub).toBeCalled; + + expect(junit.testsuites).toBeDefined; + expect(junit.testsuites.testsuite.length).toBe(1); + expect(junit.testsuites.testsuite[0].testcase.length).toBe(1); + + const failcase = junit.testsuites.testsuite[0].testcase[0]; + + expect(failcase['@name']).toBe('Test suite has no errors'); + expect(failcase.error).toBeDefined; + expect(failcase.error[0]['@type']).toBe('error'); + expect(failcase.error[0]['@message']).toBe('timeout of 2000ms exceeded'); + }); });