Skip to content

Commit

Permalink
feat(print-report-url): Print report location
Browse files Browse the repository at this point in the history
* Print location of HTML report file when done (#10)
  • Loading branch information
wannesvr authored and nicojs committed Apr 26, 2017
1 parent add7ff8 commit a4e9c55
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
4 changes: 3 additions & 1 deletion packages/stryker-html-reporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"homepage": "https://github.com/stryker-mutator/stryker-html-reporter#readme",
"dependencies": {
"file-url": "^2.0.0",
"handlebars": "^4.0.5",
"lodash": "^4.13.1",
"log4js": "^1.0.1",
Expand All @@ -38,6 +39,7 @@
"devDependencies": {
"@types/chai": "^3.4.32",
"@types/chai-as-promised": "0.0.29",
"@types/file-url": "^1.0.28",
"@types/handlebars": "^4.0.30",
"@types/lodash": "^4.14.34",
"@types/log4js": "0.0.31",
Expand Down Expand Up @@ -81,4 +83,4 @@
"Nico Jansen <jansennico@gmail.com>",
"Simon de Lang <simondelang@gmail.com>"
]
}
}
25 changes: 14 additions & 11 deletions packages/stryker-html-reporter/src/HtmlReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import { StrykerOptions } from 'stryker-api/core';
import SourceFileTreeNode from './SourceFileTreeNode';
import * as fs from 'fs';
import * as path from 'path';
import * as url from 'url';
import * as log4js from 'log4js';
import * as handlebars from 'handlebars';
import * as util from './util';
import fileUrl = require('file-url');

const log = log4js.getLogger('HtmlReporter');
const DEFAULT_BASE_FOLDER = 'reports/mutation/html';

export default class HtmlReporter implements Reporter {

private rootNode: SourceFileTreeNode;
private _baseFolder: string;
private _baseDir: string;
private templates: { node: HandlebarsTemplateDelegate, header: HandlebarsTemplateDelegate, footer: HandlebarsTemplateDelegate };
private mainPromise: Promise<void>;

Expand All @@ -40,12 +42,12 @@ export default class HtmlReporter implements Reporter {

private writeBootstrapAndHighlightResources() {
let resourcesDir = path.join(__dirname, '..', 'resources');
return util.copyFolder(resourcesDir, this.baseFolder);
return util.copyFolder(resourcesDir, this.baseDir);
}

private writeStrykerResources() {
let resourcesDir = path.join(__dirname, 'resources', 'stryker');
return util.copyFolder(resourcesDir, this.baseFolder);
return util.copyFolder(resourcesDir, this.baseDir);
}

private writeCommonResources() {
Expand All @@ -54,25 +56,26 @@ export default class HtmlReporter implements Reporter {

private writeReport() {
this.rootNode.calculateModel('');
this.rootNode.writeReportNodeRecursive(this.baseFolder);
this.rootNode.writeReportNodeRecursive(this.baseDir);
log.info(`Your report can be found at: ${fileUrl(path.resolve(this.baseDir, 'index.html'))}`);
}


private get baseFolder() {
if (!this._baseFolder) {
private get baseDir() {
if (!this._baseDir) {
if (this.options['htmlReporter'] && this.options['htmlReporter']['baseDir']) {
this._baseFolder = this.options['htmlReporter']['baseDir'];
log.debug(`Using configured output folder ${this._baseFolder}`);
this._baseDir = this.options['htmlReporter']['baseDir'];
log.debug(`Using configured output folder ${this._baseDir}`);
} else {
log.debug(`No base folder configuration found (using configuration: htmlReporter: { baseDir: 'output/folder' }), using default ${DEFAULT_BASE_FOLDER}`);
this._baseFolder = DEFAULT_BASE_FOLDER;
this._baseDir = DEFAULT_BASE_FOLDER;
}
}
return this._baseFolder;
return this._baseDir;
}

private cleanBaseFolder(): Promise<void> {
return util.deleteDir(this.baseFolder).then(() => util.mkdirRecursive(this.baseFolder));
return util.deleteDir(this.baseDir).then(() => util.mkdirRecursive(this.baseDir));
}

wrapUp() {
Expand Down
1 change: 0 additions & 1 deletion packages/stryker-html-reporter/test/helpers/log4jsMock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as log4js from 'log4js';
import * as sinon from 'sinon';

const l = log4js.getLogger();
let logger = {
isTraceEnabled: sinon.stub(),
trace: sinon.stub(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import HtmlReporter from '../../src/HtmlReporter';
import * as fs from 'fs';
import * as path from 'path';
import {expect} from 'chai';
import { expect } from 'chai';
import logger from '../helpers/log4jsMock';
import fileUrl = require('file-url');

const exampleMutations = require('./exampleMutations.json');
const exampleSourceFiles = require('./exampleSourceFiles.json');
Expand Down Expand Up @@ -37,6 +39,9 @@ describe('HtmlReporter with example project', () => {
expectFileExists(`${baseDir}/Add.js.html`, true);
});

it('should output a log message with a link to the HTML report', () => {
expect(logger.info).to.have.been.calledWith(`Your report can be found at: ${fileUrl(baseDir + '/index.html')}`);
});
});

describe('when initiated a second time with empty events', () => {
Expand All @@ -56,7 +61,5 @@ describe('HtmlReporter with example project', () => {
});

});


});

0 comments on commit a4e9c55

Please sign in to comment.