adding request-level error reporting

This commit is contained in:
Andrew 2023-12-15 10:09:20 -05:00
parent 882341c35b
commit de530a889c
2 changed files with 54 additions and 2 deletions

View File

@ -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);
});

View File

@ -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');
});
});