Fixed undefined error in stack trace logic

pull/184/head
maishiroma 2022-05-19 16:56:57 -07:00
parent 46ddff2c3b
commit bb51f4aca4
4 changed files with 27 additions and 1 deletions

4
dist/index.js generated vendored
View File

@ -958,6 +958,10 @@ const ResultsParser = {
return testMeta; return testMeta;
} }
const trace = failure['stack-trace']._cdata; const trace = failure['stack-trace']._cdata;
if (trace === undefined) {
core.warning(`No cdata in stack trace for test case: ${fullname}`);
return testMeta;
}
const point = ResultsParser.findAnnotationPoint(trace); const point = ResultsParser.findAnnotationPoint(trace);
if (!point.path || !point.line) { if (!point.path || !point.line) {
core.warning(`Not able to find annotation point for failed test! Test trace: ${trace}`); core.warning(`Not able to find annotation point for failed test! Test trace: ${trace}`);

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -114,6 +114,24 @@ describe('ResultsParser', () => {
expect(result.annotation).toBeUndefined(); expect(result.annotation).toBeUndefined();
}); });
test('no cdata in stack trace', () => {
const result = ResultsParser.convertTestCase('Test Suite', {
_attributes: {
name: 'Test Name',
duration: '3.14',
},
failure: {
message: { _cdata: 'Message CDATA' },
'stack-trace': {},
},
});
expect(result.suite).toBe('Test Suite');
expect(result.title).toBe('Test Name');
expect(result.duration).toBe(3.14);
expect(result.annotation).toBeUndefined();
});
test('no annotation path', () => { test('no annotation path', () => {
const result = ResultsParser.convertTestCase('Test Suite', { const result = ResultsParser.convertTestCase('Test Suite', {
_attributes: { _attributes: {

View File

@ -90,6 +90,10 @@ const ResultsParser = {
} }
const trace = failure['stack-trace']._cdata; const trace = failure['stack-trace']._cdata;
if (trace === undefined) {
core.warning(`No cdata in stack trace for test case: ${fullname}`);
return testMeta;
}
const point = ResultsParser.findAnnotationPoint(trace); const point = ResultsParser.findAnnotationPoint(trace);
if (!point.path || !point.line) { if (!point.path || !point.line) {
core.warning(`Not able to find annotation point for failed test! Test trace: ${trace}`); core.warning(`Not able to find annotation point for failed test! Test trace: ${trace}`);