fix: Change test output formatting from code to html (#35857)

This commit is contained in:
Oliver Eyton-Williams
2019-06-09 01:58:10 +02:00
committed by mrugesh
parent b1956a7ba1
commit 60dd7ca703
4 changed files with 26 additions and 50 deletions

View File

@ -63,6 +63,7 @@
"redux-saga": "^0.16.0", "redux-saga": "^0.16.0",
"reselect": "^3.0.1", "reselect": "^3.0.1",
"rxjs": "^6.4.0", "rxjs": "^6.4.0",
"sanitize-html": "^1.20.0",
"sass.js": "^0.10.13", "sass.js": "^0.10.13",
"store": "^2.0.12", "store": "^2.0.12",
"validator": "^10.11.0", "validator": "^10.11.0",

View File

@ -1,60 +1,25 @@
import React, { Fragment, Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import MonacoEditor from 'react-monaco-editor'; import sanitizeHtml from 'sanitize-html';
import { decodeHTML } from 'entities';
import './output.css';
const propTypes = { const propTypes = {
defaultOutput: PropTypes.string, defaultOutput: PropTypes.string,
dimensions: PropTypes.object,
height: PropTypes.number,
output: PropTypes.string output: PropTypes.string
}; };
const options = {
lineNumbers: false,
minimap: {
enabled: false
},
readOnly: true,
wordWrap: 'on',
scrollBeyondLastLine: false,
scrollbar: {
horizontal: 'hidden',
vertical: 'visible',
verticalHasArrows: true
}
};
class Output extends Component { class Output extends Component {
constructor() {
super();
this._editor = null;
}
editorDidMount(editor) {
this._editor = editor;
}
componentDidUpdate(prevProps) {
if (this.props.dimensions !== prevProps.dimensions && this._editor) {
this._editor.layout();
}
}
render() { render() {
const { output, defaultOutput, height } = this.props; const { output, defaultOutput } = this.props;
const message = sanitizeHtml(output ? output : defaultOutput, {
allowedTags: ['b', 'i', 'em', 'strong', 'code', 'wbr']
});
return ( return (
<Fragment> <pre
<base href='/' /> className='output-text'
<MonacoEditor dangerouslySetInnerHTML={{ __html: message }}
className='challenge-output' />
editorDidMount={::this.editorDidMount}
height={height}
options={options}
value={decodeHTML(output ? output : defaultOutput)}
/>
</Fragment>
); );
} }
} }

View File

@ -0,0 +1,12 @@
.output-text {
white-space: pre-line;
word-break: normal;
padding-top: 0;
height: 100%;
width: 100%;
overflow-y: auto;
}
pre.output-text code {
color: #c7254e;
}

View File

@ -98,9 +98,7 @@ function* executeTests(testRunner, tests, testTimeout = 5000) {
throw err; throw err;
} }
} catch (err) { } catch (err) {
newTest.message = text newTest.message = text;
.replace(/<code>(.*?)<\/code>/g, '$1')
.replace(/<wbr>/g, '');
if (err === 'timeout') { if (err === 'timeout') {
newTest.err = 'Test timed out'; newTest.err = 'Test timed out';
newTest.message = `${newTest.message} (${newTest.err})`; newTest.message = `${newTest.message} (${newTest.err})`;