[JENKINS-39542] Test results trimming null string fix. (#656)

* [JENKINS-39542] trim() being called on null in TestReport

* test case

* Fix Tests

* Fix linting
This commit is contained in:
Ivan Meredith 2016-12-14 18:37:48 +13:00 committed by GitHub
parent 38163fb388
commit 9bf0b0c45f
2 changed files with 132 additions and 101 deletions

View File

@ -7,7 +7,7 @@ import 'moment/min/locales.min';
/* eslint-disable max-len */
const ConsoleLog = ({ text, className, key = 'console' }) =>
<div className={`${className} console-log insert-line-numbers`}>
<div className={`${className} console-log insert-line-numbers`}>
{text.trim().split('\n').map((line, idx) =>
<div className="line" id={`#${key}-L${idx}`} key={`#${key}-L${idx}`}>{line}</div>
)}
@ -26,7 +26,7 @@ const TestCaseResultRow = (props) => {
let testDetails = null;
if (t.errorStackTrace) {
if (t.errorStackTrace || t.errorDetails) {
testDetails = (<div>
<div className="test-details">
<div className="test-detail-text" style={{ display: 'none' }}>
@ -34,10 +34,10 @@ const TestCaseResultRow = (props) => {
</div>
</div>
<div className="test-console">
<h4>{translation('rundetail.tests.results.error.message', { defaultValue: 'Error' })}</h4>
<ConsoleLog className="error-message" text={t.errorDetails} key={`${t}-message`} />
<h4>{translation('rundetail.tests.results.error.output', { defaultValue: 'Stacktrace' })}</h4>
<ConsoleLog className="stack-trace" text={t.errorStackTrace} key={`${t}-stack-trace`} />
{t.errorDetails && <h4>{translation('rundetail.tests.results.error.message', { defaultValue: 'Error' })}</h4>}
{t.errorDetails && <ConsoleLog className="error-message" text={t.errorDetails} key={`${t}-message`} />}
{t.errorStackTrace && <h4>{translation('rundetail.tests.results.error.output', { defaultValue: 'Stacktrace' })}</h4>}
{t.errorStackTrace && <ConsoleLog className="stack-trace" text={t.errorStackTrace} key={`${t}-stack-trace`} />}
</div>
</div>);
}

View File

@ -1,6 +1,9 @@
import { prepareMount } from './util/EnzymeUtils';
prepareMount();
import React from 'react';
import { assert } from 'chai';
import { shallow } from 'enzyme';
import { shallow, mount } from 'enzyme';
import TestResults from '../../main/js/components/testing/TestResults.jsx';
@ -9,117 +12,145 @@ import { i18nTranslator } from '@jenkins-cd/blueocean-core-js';
const t = i18nTranslator('blueocean-dashboard');
describe("TestResults", () => {
const testResults1 = {
"_class":"hudson.tasks.junit.TestResult",
"duration":0.008,
"empty":false,
"failCount":4,
"passCount":9,
"skipCount":3,
"suites":[
{"cases":[
{"age":0,"className":"failure.TestThisWillFailAbunch","duration":0.002,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest3","skipped":false,"skippedMessage":null,"status":"PASSED","stderr":null,"stdout":null},
{"age":0,"className":"failure.TestThisWillFailAbunch","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest4","skipped":false,"skippedMessage":null,"status":"PASSED","stderr":null,"stdout":null},
{"age":4,"className":"failure.TestThisWillFailAbunch","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":7,"name":"aFailingTest2","skipped":true,"skippedMessage":null,"status":"SKIPPED","stderr":null,"stdout":null},
{"age":4,"className":"failure.TestThisWillFailAbunch","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":7,"name":"aFailingTest3","skipped":true,"skippedMessage":null,"status":"SKIPPED","stderr":null,"stdout":null},
{"age":0,"className":"failure.TestThisWillFailAbunch","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aFailingTest4","skipped":false,"skippedMessage":null,"status":"FIXED","stderr":null,"stdout":null},
{"age":1,"className":"failure.TestThisWillFailAbunch","duration":0.003,"errorDetails":"<some exception here>","failedSince":7,"name":"aFailingTest","skipped":false,"skippedMessage":null,"status":"FAILED","stderr":null,"stdout":null},
{"age":4,"className":"failure.TestThisWillFailAbunch","duration":0.001,"errorDetails":null,"errorStackTrace":null,"failedSince":7,"name":"aNewFailingTest31","skipped":true,"skippedMessage":null,"status":"SKIPPED","stderr":null,"stdout":null}
const testResults1 = {
"_class": "hudson.tasks.junit.TestResult",
"duration": 0.008,
"empty": false,
"failCount": 4,
"passCount": 9,
"skipCount": 3,
"suites": [
{
"cases": [
{ "age": 0, "className": "failure.TestThisWillFailAbunch", "duration": 0.002, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest3", "skipped": false, "skippedMessage": null, "status": "PASSED", "stderr": null, "stdout": null },
{ "age": 0, "className": "failure.TestThisWillFailAbunch", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest4", "skipped": false, "skippedMessage": null, "status": "PASSED", "stderr": null, "stdout": null },
{ "age": 4, "className": "failure.TestThisWillFailAbunch", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 7, "name": "aFailingTest2", "skipped": true, "skippedMessage": null, "status": "SKIPPED", "stderr": null, "stdout": null },
{ "age": 4, "className": "failure.TestThisWillFailAbunch", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 7, "name": "aFailingTest3", "skipped": true, "skippedMessage": null, "status": "SKIPPED", "stderr": null, "stdout": null },
{ "age": 0, "className": "failure.TestThisWillFailAbunch", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aFailingTest4", "skipped": false, "skippedMessage": null, "status": "FIXED", "stderr": null, "stdout": null },
{ "age": 1, "className": "failure.TestThisWillFailAbunch", "duration": 0.003, "errorDetails": "<some exception here>", "failedSince": 7, "name": "aFailingTest", "skipped": false, "skippedMessage": null, "status": "FAILED", "stderr": null, "stdout": null },
{ "age": 4, "className": "failure.TestThisWillFailAbunch", "duration": 0.001, "errorDetails": null, "errorStackTrace": null, "failedSince": 7, "name": "aNewFailingTest31", "skipped": true, "skippedMessage": null, "status": "SKIPPED", "stderr": null, "stdout": null }
],
"duration":0.008,
"id":null,
"name":"failure.TestThisWillFailAbunch",
"stderr":null,
"stdout":null,
"timestamp":null
"duration": 0.008,
"id": null,
"name": "failure.TestThisWillFailAbunch",
"stderr": null,
"stdout": null,
"timestamp": null
},
{"cases":[
{"age":0,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest2","skipped":false,"skippedMessage":null,"status":"PASSED","stderr":null,"stdout":null},
{"age":0,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest3","skipped":false,"skippedMessage":null,"status":"PASSED","stderr":null,"stdout":null},
{"age":0,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest4","skipped":false,"skippedMessage":null,"status":"PASSED","stderr":null,"stdout":null},
{"age":4,"className":"failure.TestThisWillFailAbunch","duration":0.003,"errorDetails":"<some exception here>","failedSince":7,"name":"aFailingTest","skipped":false,"skippedMessage":null,"status":"FAILED","stderr":null,"stdout":null},
{"age":4,"className":"failure.TestThisWillFailAbunch","duration":0.003,"errorDetails":"<some exception here>","failedSince":7,"name":"aFailingTest","skipped":false,"skippedMessage":null,"status":"FAILED","stderr":null,"stdout":null},
{
"cases": [
{ "age": 0, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest2", "skipped": false, "skippedMessage": null, "status": "PASSED", "stderr": null, "stdout": null },
{ "age": 0, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest3", "skipped": false, "skippedMessage": null, "status": "PASSED", "stderr": null, "stdout": null },
{ "age": 0, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest4", "skipped": false, "skippedMessage": null, "status": "PASSED", "stderr": null, "stdout": null },
{ "age": 4, "className": "failure.TestThisWillFailAbunch", "duration": 0.003, "errorDetails": "<some exception here>", "failedSince": 7, "name": "aFailingTest", "skipped": false, "skippedMessage": null, "status": "FAILED", "stderr": null, "stdout": null },
{ "age": 4, "className": "failure.TestThisWillFailAbunch", "duration": 0.003, "errorDetails": "<some exception here>", "failedSince": 7, "name": "aFailingTest", "skipped": false, "skippedMessage": null, "status": "FAILED", "stderr": null, "stdout": null },
],
"duration":0,
"id":null,
"name":"failure.TestThisWontFail",
"stderr":null,
"stdout":null,
"timestamp":null
"duration": 0,
"id": null,
"name": "failure.TestThisWontFail",
"stderr": null,
"stdout": null,
"timestamp": null
}
]
};
it("Test fixed included", () => {
let wrapper = shallow(<TestResults t={t} testResults={testResults1} />);
it("Test fixed included", () => {
let wrapper = shallow(<TestResults t={t} testResults={testResults1} />);
const fixed = wrapper.find('.new-passed .count').text();
assert.equal(fixed, 1);
const fixed = wrapper.find('.new-passed .count').text();
assert.equal(fixed, 1);
const failed = wrapper.find('.failed .count').text();
assert.equal(failed, 4);
const failed = wrapper.find('.failed .count').text();
assert.equal(failed, 4);
const skipped = wrapper.find('.skipped .count').text();
assert.equal(skipped, 3);
const skipped = wrapper.find('.skipped .count').text();
assert.equal(skipped, 3);
const newFailed = wrapper.find('.new-failed .count').text();
assert.equal(newFailed, 1);
});
const newFailed = wrapper.find('.new-failed .count').text();
assert.equal(newFailed, 1);
});
it("Handles REGRESSION case", () => {
var failures = {
"_class":"hudson.tasks.junit.TestResult",
"duration":0.008, "empty":false, "failCount":3, "passCount":0, "skipCount":0, "suites":[
{ "duration":0, "id":null, "name":"failure.TestThisWontFail", "stderr":null, "stdout":null, "timestamp":null, "cases": [
{"age":5,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest2","skipped":false,"skippedMessage":null,"status":"FAILED","stderr":null,"stdout":null},
{"age":2,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest3","skipped":false,"skippedMessage":null,"status":"REGRESSION","stderr":null,"stdout":null},
{"age":1,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest4","skipped":false,"skippedMessage":null,"status":"FAILED","stderr":null,"stdout":null},
],
}]};
it("Handles REGRESSION case", () => {
var failures = {
"_class": "hudson.tasks.junit.TestResult",
"duration": 0.008, "empty": false, "failCount": 3, "passCount": 0, "skipCount": 0, "suites": [
{
"duration": 0, "id": null, "name": "failure.TestThisWontFail", "stderr": null, "stdout": null, "timestamp": null, "cases": [
{ "age": 5, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest2", "skipped": false, "skippedMessage": null, "status": "FAILED", "stderr": null, "stdout": null },
{ "age": 2, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest3", "skipped": false, "skippedMessage": null, "status": "REGRESSION", "stderr": null, "stdout": null },
{ "age": 1, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest4", "skipped": false, "skippedMessage": null, "status": "FAILED", "stderr": null, "stdout": null },
],
}]
};
let wrapper = shallow(<TestResults t={t} testResults={failures} />);
const newFailed = wrapper.find('.new-failure-block h4').text();
assert.equal(newFailed, 'New failing - 2');
let wrapper = shallow(<TestResults t={t} testResults={failures} />);
const newFailed = wrapper.find('.new-failure-block h4').text();
assert.equal(newFailed, 'New failing - 2');
const failed = wrapper.find('.existing-failure-block h4').text();
assert.equal(failed, 'Existing failures - 1');
});
const failed = wrapper.find('.existing-failure-block h4').text();
assert.equal(failed, 'Existing failures - 1');
});
it("All passing shown", () => {
let wrapper = shallow(<TestResults t={t} testResults={testResults1} />);
let isDone = wrapper.html().indexOf('done_all') > 0;
assert(!isDone, "Done all found, when shouldn't have been");
it("All passing shown", () => {
let wrapper = shallow(<TestResults t={t} testResults={testResults1} />);
let isDone = wrapper.html().indexOf('done_all') > 0;
assert(!isDone, "Done all found, when shouldn't have been");
var success = {
"_class":"hudson.tasks.junit.TestResult",
"duration":0.008, "empty":false, "failCount":0, "passCount":3, "skipCount":0, "suites":[
{ "duration":0, "id":null, "name":"failure.TestThisWontFail", "stderr":null, "stdout":null, "timestamp":null, "cases": [
{"age":0,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest2","skipped":false,"skippedMessage":null,"status":"PASSED","stderr":null,"stdout":null},
{"age":0,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest3","skipped":false,"skippedMessage":null,"status":"PASSED","stderr":null,"stdout":null},
{"age":0,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest4","skipped":false,"skippedMessage":null,"status":"PASSED","stderr":null,"stdout":null},
],
}]};
var success = {
"_class": "hudson.tasks.junit.TestResult",
"duration": 0.008, "empty": false, "failCount": 0, "passCount": 3, "skipCount": 0, "suites": [
{
"duration": 0, "id": null, "name": "failure.TestThisWontFail", "stderr": null, "stdout": null, "timestamp": null, "cases": [
{ "age": 0, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest2", "skipped": false, "skippedMessage": null, "status": "PASSED", "stderr": null, "stdout": null },
{ "age": 0, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest3", "skipped": false, "skippedMessage": null, "status": "PASSED", "stderr": null, "stdout": null },
{ "age": 0, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest4", "skipped": false, "skippedMessage": null, "status": "PASSED", "stderr": null, "stdout": null },
],
}]
};
wrapper = shallow(<TestResults t={t} testResults={success} />);
let html = wrapper.html();
assert(html.indexOf('done_all') > 0, "Done all not found, when should be");
assert(html.indexOf('fixed-block') < 0, "No fixed tests!");
});
wrapper = shallow(<TestResults t={t} testResults={success} />);
let html = wrapper.html();
assert(html.indexOf('done_all') > 0, "Done all not found, when should be");
assert(html.indexOf('fixed-block') < 0, "No fixed tests!");
});
it("All passing and fixed shown", () => {
var successWithFixed = {
"_class":"hudson.tasks.junit.TestResult",
"duration":0.008, "empty":false, "failCount":0, "passCount":3, "skipCount":0, "suites":[
{ "duration":0, "id":null, "name":"failure.TestThisWontFail", "stderr":null, "stdout":null, "timestamp":null, "cases": [
{"age":0,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest2","skipped":false,"skippedMessage":null,"status":"FIXED","stderr":null,"stdout":null},
{"age":0,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest3","skipped":false,"skippedMessage":null,"status":"PASSED","stderr":null,"stdout":null},
{"age":0,"className":"failure.TestThisWontFail","duration":0,"errorDetails":null,"errorStackTrace":null,"failedSince":0,"name":"aPassingTest4","skipped":false,"skippedMessage":null,"status":"PASSED","stderr":null,"stdout":null},
],
}]};
it("All passing and fixed shown", () => {
var successWithFixed = {
"_class": "hudson.tasks.junit.TestResult",
"duration": 0.008, "empty": false, "failCount": 0, "passCount": 3, "skipCount": 0, "suites": [
{
"duration": 0, "id": null, "name": "failure.TestThisWontFail", "stderr": null, "stdout": null, "timestamp": null, "cases": [
{ "age": 0, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest2", "skipped": false, "skippedMessage": null, "status": "FIXED", "stderr": null, "stdout": null },
{ "age": 0, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest3", "skipped": false, "skippedMessage": null, "status": "PASSED", "stderr": null, "stdout": null },
{ "age": 0, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": null, "failedSince": 0, "name": "aPassingTest4", "skipped": false, "skippedMessage": null, "status": "PASSED", "stderr": null, "stdout": null },
],
}]
};
let wrapper = shallow(<TestResults t={t} testResults={successWithFixed} />);
let html = wrapper.html();
assert(html.indexOf('done_all') > 0, "Done all not found, when should be");
assert(html.indexOf('fixed-block') > 0, "Should have fixed tests!");
});
let wrapper = shallow(<TestResults t={t} testResults={successWithFixed} />);
let html = wrapper.html();
assert(html.indexOf('done_all') > 0, "Done all not found, when should be");
assert(html.indexOf('fixed-block') > 0, "Should have fixed tests!");
});
it("unstable renders with no error message", () => {
var unstableWithNoMsg = {
"_class": "hudson.tasks.junit.TestResult",
"duration": 0.008, "empty": false, "failCount": 1, "passCount": 3, "skipCount": 0, "suites": [
{
"duration": 0, "id": null, "name": "failure.TestThisWontFail", "stderr": null, "stdout": null, "timestamp": null, "cases": [
{ "age": 0, "className": "failure.TestThisWontFail", "duration": 0, "errorDetails": null, "errorStackTrace": 'aa', "failedSince": 0, "name": "aPassingTest2", "skipped": false, "skippedMessage": null, "status": "FAILED", "stderr": null, "stdout": null },
],
}]
};
// Lets mount it to that it renders children.
let wrapper = mount(<TestResults t={t} testResults={unstableWithNoMsg} />);
// Expend the test result
wrapper.find('.result-item-head').simulate('click');
// Assert that it expanded and just shows the stacktrace.
assert.equal(wrapper.find('.test-console h4').length, 1);
});
});