Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: single file HTML report #2540

Merged
merged 6 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/reporters/html/HtmlReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import fileUrl = require('file-url');

import { bindMutationTestReport } from './templates/bindMutationTestReport';
import * as HtmlReporterUtil from './HtmlReporterUtil';
import { singleFileTemplate } from './single-file-template/single-file-template';

const DEFAULT_BASE_FOLDER = path.normalize('reports/mutation/html');
export const RESOURCES_DIR_NAME = 'strykerResources';
Expand All @@ -31,12 +32,14 @@ export default class HtmlReporter implements Reporter {

private async generateReport(report: mutationTestReportSchema.MutationTestResult) {
const indexFileName = path.resolve(this.baseDir, 'index.html');
const singleFile = singleFileTemplate(report);
await this.cleanBaseFolder();
await Promise.all([
HtmlReporterUtil.copyFile(
require.resolve('mutation-testing-elements/dist/mutation-test-elements.js'),
path.resolve(this.baseDir, 'mutation-test-elements.js')
),
HtmlReporterUtil.writeFile(path.resolve(this.baseDir, 'singleFile.html'), singleFile),
HtmlReporterUtil.copyFile(path.resolve(__dirname, 'templates', 'stryker-80x80.png'), path.resolve(this.baseDir, 'stryker-80x80.png')),
HtmlReporterUtil.copyFile(path.resolve(__dirname, 'templates', 'index.html'), path.resolve(this.baseDir, 'index.html')),
HtmlReporterUtil.writeFile(path.resolve(this.baseDir, 'bind-mutation-test-report.js'), bindMutationTestReport(report)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { readFileSync } from 'fs';

import { mutationTestReportSchema } from '@stryker-mutator/api/report';

export function singleFileTemplate(report: mutationTestReportSchema.MutationTestResult) {
return `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
${readFileSync(require.resolve('mutation-testing-elements/dist/mutation-test-elements.js')).toString('utf-8')}
nicojs marked this conversation as resolved.
Show resolved Hide resolved
</script>
</head>
<body>
<img class="stryker-image" alt="Stryker" src="stryker-80x80.png" style="position: fixed; right: 0; top: 0; z-index: 10">
<mutation-test-report-app titlePostfix="Stryker">
Your browser doesn't support <a href="https://caniuse.com/#search=custom%20elements">custom elements</a>.
Please use a latest version of an evergreen browser (Firefox, Chrome, Safari, Opera, etc).
</mutation-test-report-app>
<script>
document.querySelector('mutation-test-report-app').report = ${JSON.stringify(report)};
nicojs marked this conversation as resolved.
Show resolved Hide resolved
</script>
</body>
</html>`;
}