From 8f30fc76e498b3c561f511e218a6d4a0b0fc6d16 Mon Sep 17 00:00:00 2001 From: pacien Date: Wed, 10 Oct 2018 16:41:04 +0200 Subject: Initial implementation --- src/App.css | 65 ++++++++++++++++++++----------- src/App.js | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/Blocks.js | 99 +++++++++++++++++++++++++++++++++++++++++++++++ src/logo.svg | 7 ---- 4 files changed, 248 insertions(+), 44 deletions(-) create mode 100644 src/Blocks.js delete mode 100644 src/logo.svg (limited to 'src') diff --git a/src/App.css b/src/App.css index 92f956e..d0870a2 100644 --- a/src/App.css +++ b/src/App.css @@ -1,32 +1,53 @@ +/* + * JaCoCo Report Viewer, a web-based coverage report viewer + * Copyright (C) 2018 Pacien TRAN-GIRARD + * Adam NAILI + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + .App { - text-align: center; + margin: 1rem; +} + +.App label { + display: inline-block; + width: 6rem; +} + +.App ul { + padding-left: 1.75rem; +} + +.App ul[inline-list="true"] { + display: inline; + padding-left: 0.75rem; } -.App-logo { - animation: App-logo-spin infinite 20s linear; - height: 40vmin; +.App ul[inline-list="true"] li { + display: inline; + list-style: none; } -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; +.App ul[inline-list="true"] li:not(:first-child) { + padding-left: 0.75rem; } -.App-link { - color: #61dafb; +.App li[well-covered="true"] { + color: green; } -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } +.App li[well-covered="false"] { + color: red; } diff --git a/src/App.js b/src/App.js index 7e261ca..347d243 100644 --- a/src/App.js +++ b/src/App.js @@ -1,28 +1,119 @@ +/* + * JaCoCo Report Viewer, a web-based coverage report viewer + * Copyright (C) 2018 Pacien TRAN-GIRARD + * Adam NAILI + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + import React, { Component } from 'react'; -import logo from './logo.svg'; +import {Parser} from 'xml2js'; + +import {Counters, SessionInfo, PackagesCoverage} from './Blocks.js'; import './App.css'; class App extends Component { + constructor(props) { + super(props); + this.state = { + report: null, + hasError: false + }; + } + + componentDidCatch(error, info) { + this.setState({ hasError: true }); + console.err(error, info); + } + + _useReportFile(file) { + const fileReader = new FileReader(); + fileReader.onloadend = (readEvent) => this._useReport(readEvent.target.result); + fileReader.readAsText(file); + } + + _useReport(xmlString) { + const xmlParser = new Parser(); + xmlParser.parseString(xmlString, (err, result) => this.setState({ report: result.report })); + } + + _renderError() { + return ( + + Something went wrong while rendering the report. + Are the provided files valid? + + ); + } + + _renderReport() { + return this.state.hasError ? this._renderError(): (); + } + render() { return (
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
+

JaCoCo Report Viewer

+ +
+ + this._useReportFile(event.target.files[0])} /> +
+ +
+ + null} /> +
+ +
+ {this._renderReport()} +
+ ); + } +} + +class Report extends Component { + _renderNone() { + return (Please provide a JaCoCo XML report file to visualise.); + } + + _renderReport() { + return ( +
+

Viewing report: "{this.props.report.$.name}"

+ +
+

Session info

+ +
+ +
+

Global coverage

+ +
+ +
+

Details

+ +
); } + + render() { + return this.props.report ? this._renderReport() : this._renderNone(); + } } export default App; diff --git a/src/Blocks.js b/src/Blocks.js new file mode 100644 index 0000000..48e0376 --- /dev/null +++ b/src/Blocks.js @@ -0,0 +1,99 @@ +/* + * JaCoCo Report Viewer, a web-based coverage report viewer + * Copyright (C) 2018 Pacien TRAN-GIRARD + * Adam NAILI + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import React, { Component } from 'react'; + +function renderRows(renderRowFunc, rows, inline) { + const renderedRows = rows ? rows.map(renderRowFunc) : (
  • None.
  • ); + return (
      {renderedRows}
    ); +} + +export class SessionInfo extends Component { + _renderRow(row) { + const date = new Date(parseInt(row.start)); + return (
  • {row.id}: {date.toISOString()} ({row.dump - row.start} ms)
  • ); + } + + render() { + return renderRows(row => this._renderRow(row.$), this.props.data, false); + } +} + +export class Counters extends Component { + _renderRow(row) { + const covered = parseInt(row.covered); + const totalCount = covered + parseInt(row.missed); + const wellCovered = covered === totalCount; + return (
  • {row.type}: {covered}/{totalCount}
  • ); + } + + render() { + return renderRows(row => this._renderRow(row.$), this.props.data, this.props.inlineList !== undefined); + } +} + +export class PackagesCoverage extends Component { + _renderRow(row) { + return ( +
  • + {row.$.name} + + +
  • + ) + } + + render() { + return renderRows(this._renderRow, this.props.packages, false); + } +} + +class ClassesCoverage extends Component { + _renderRow(row) { + const counters = row.counter.filter(counter => counter.$.type !== 'CLASS'); + return ( +
  • + {row.$.name} + + +
  • + ) + } + + render() { + return renderRows(this._renderRow, this.props.classes, false); + } +} + +class MethodsCoverage extends Component { + _renderRow(row) { + const counters = row.counter.filter(counter => counter.$.type !== 'METHOD'); + const method = row.$.name + ':' + row.$.line; + return ( +
  • + {method} + +
  • + ) + } + + render() { + return renderRows(this._renderRow, this.props.methods, false); + } +} diff --git a/src/logo.svg b/src/logo.svg deleted file mode 100644 index 6b60c10..0000000 --- a/src/logo.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - -- cgit v1.2.3