Skip to content

Commit

Permalink
feat(HtmlReporter): include the html reporter in the core package and…
Browse files Browse the repository at this point in the history
… add it to the default reporters (#2036)

Adds the html reporter to the list of default reporters.
The `@stryker-mutator/html-reporter` package is now deprecated and only a stub. There is no need to install this package anymore since the html reporter is bundled with the `@stryker-mutator/core` package.

Fixes #1919 

BREAKING CHANGE: the `html` reporter is now enabled by default. If you don't want to use it, be sure to override the `reporters` configuration option.

```json
{
  "reporters": ["progress", "clear-text"]
}
```
  • Loading branch information
simondel committed Feb 14, 2020
1 parent baa41e1 commit 09702d9
Show file tree
Hide file tree
Showing 27 changed files with 62 additions and 81 deletions.
19 changes: 18 additions & 1 deletion packages/api/schema/stryker-core.json
Expand Up @@ -67,6 +67,18 @@
}
}
},
"htmlReporterOptions": {
"title": "HtmlReporterOptions",
"additionalProperties": false,
"type": "object",
"properties": {
"baseDir": {
"description": "The output folder for the html report.",
"type": "string",
"default": "reports/mutation/html"
}
}
},
"mutationScoreThresholds": {
"title": "MutationScoreThresholds",
"additionalProperties": false,
Expand Down Expand Up @@ -211,9 +223,14 @@
},
"default": [
"clear-text",
"progress"
"progress",
"html"
]
},
"htmlReporter": {
"description": "The options for the html reporter",
"$ref": "#/definitions/htmlReporterOptions"
},
"symlinkNodeModules": {
"description": "The 'symlinkNodeModules' value indicates whether Stryker should create a symbolic link to your current node_modules directory in the sandbox directories. This makes running your tests by Stryker behave more like your would run the tests yourself in your project directory. Only disable this setting if you really know what you are doing.",
"type": "boolean",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/config/Config.ts
Expand Up @@ -27,7 +27,7 @@ export default class Config implements StrykerOptions {
public timeoutMS = 5000;
public timeoutFactor = 1.5;
public plugins: string[] = ['@stryker-mutator/*'];
public reporters: string[] = ['progress', 'clear-text'];
public reporters: string[] = ['html', 'progress', 'clear-text'];
public coverageAnalysis: 'perTest' | 'all' | 'off' = 'off';
public testRunner: string = 'command';
public testFramework: string;
Expand Down
3 changes: 3 additions & 0 deletions packages/api/testResources/module/useCore.ts
Expand Up @@ -26,6 +26,9 @@ const optionsAllArgs: StrykerOptions = {
project: 'project',
version: 'version'
},
htmlReporter: {
baseDir: 'mydir'
},
tempDirName: '.stryker-tmp',
};

Expand Down
13 changes: 7 additions & 6 deletions packages/core/README.md
Expand Up @@ -246,8 +246,8 @@ When using the config file, you can provide either a string representing the mut
### `plugins` [`string[]`]

Default: `['@stryker-mutator/*']`
Command line: `--plugins stryker-html-reporter,stryker-karma-runner`
Config file: `plugins: ['stryker-html-reporter', 'stryker-karma-runner']`
Command line: `--plugins @stryker-mutator/jasmine-framework,@stryker-mutator/karma-runner`
Config file: `plugins: ['@stryker-mutator/jasmine-framework', '@stryker-mutator/karma-runner']`


With `plugins`, you can add additional Node modules for Stryker to load (or `require`).
Expand All @@ -259,17 +259,18 @@ you can consult [npm](https://www.npmjs.com/search?q=%40stryker-plugin) or
<a name="reporters"></a>
### `reporters` [`string[]`]

Default: `['clear-text', 'progress']`
Default: `['clear-text', 'progress', 'html']`
Command line: `--reporters clear-text,progress,dots,dashboard,html`
Config file: `reporters: ['clear-text', 'progress', 'dots', 'dashboard', 'html']`

With `reporters`, you can set the reporters for stryker to use.
These reporters can be used out of the box: `clear-text`, `progress`, `dots`, `dashboard` and `event-recorder`.
The `html` reporter can be installed as a plugin, see [the html reporter's readme](https://github.com/stryker-mutator/stryker/tree/master/packages/html-reporter#readme).
By default, `clear-text` and `progress` are active if no reporters are configured.
These reporters can be used out of the box: `html`, `progress`, `clear-text`, `dots`, `dashboard` and `event-recorder`.
By default, `clear-text`, `progress`, `html` are active if no reporters are configured.
You can load additional plugins to get more reporters. See [stryker-mutator.io](https://stryker-mutator.io)
for an up-to-date list of supported reporter plugins and a description on each reporter.

The `html` reporter allows you to specify an output folder. This defaults to `reports/mutation/html`. The config for your config file is: `htmlReporter: { baseDir: 'mypath/reports/stryker' }`

The `clear-text` reporter supports three additional config options:
* `allowColor` to use cyan and yellow in printing source file names and positions. This defaults to `true`, so specify as `clearTextReporter: { allowColor: false },` to disable if you must.
* `logTests` to log the names of unit tests that were run to allow mutants. By default, only the first three are logged. The config for your config file is: `clearTextReporter: { logTests: true },`
Expand Down
2 changes: 2 additions & 0 deletions packages/core/package.json
Expand Up @@ -57,6 +57,7 @@
"@stryker-mutator/util": "^2.5.0",
"chalk": "~3.0.0",
"commander": "~4.1.0",
"file-url": "~3.0.0",
"get-port": "~5.0.0",
"glob": "~7.1.2",
"inquirer": "~7.0.0",
Expand All @@ -65,6 +66,7 @@
"lodash.groupby": "^4.6.0",
"log4js": "6.1.2",
"mkdirp": "~1.0.3",
"mutation-testing-elements": "^1.0.2",
"mutation-testing-metrics": "^1.1.1",
"progress": "~2.0.0",
"rimraf": "~3.0.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/initializer/StrykerInitializer.ts
Expand Up @@ -132,6 +132,10 @@ export default class StrykerInitializer {
let reporterOptions: PromptOption[];
reporterOptions = await this.client.getTestReporterOptions();
reporterOptions.push(
{
name: 'html',
pkg: null
},
{
name: 'clear-text',
pkg: null
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/initializer/StrykerInquirer.ts
Expand Up @@ -72,7 +72,7 @@ export class StrykerInquirer {
public async promptReporters(options: PromptOption[]): Promise<PromptOption[]> {
const answers = await inquirer.prompt<{ reporters: string[] }>({
choices: options.map(_ => _.name),
default: ['clear-text', 'progress'],
default: ['html', 'clear-text', 'progress'],
message: 'Which reporter(s) do you want to use?',
name: 'reporters',
type: 'checkbox'
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/initializer/presets/AngularPreset.ts
Expand Up @@ -8,12 +8,7 @@ const handbookUrl = 'https://github.com/stryker-mutator/stryker-handbook/blob/ma
export class AngularPreset implements Preset {
public readonly name = 'angular-cli';
// Please keep config in sync with handbook
private readonly dependencies = [
'@stryker-mutator/core',
'@stryker-mutator/karma-runner',
'@stryker-mutator/typescript',
'@stryker-mutator/html-reporter'
];
private readonly dependencies = ['@stryker-mutator/core', '@stryker-mutator/karma-runner', '@stryker-mutator/typescript'];
private readonly config = `{
mutate: [
'src/**/*.ts',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/initializer/presets/ReactPreset.ts
Expand Up @@ -10,7 +10,7 @@ const handbookUrl = 'https://github.com/stryker-mutator/stryker-handbook/blob/ma
*/
export class ReactPreset implements Preset {
public readonly name = 'create-react-app';
private readonly generalDependencies = ['@stryker-mutator/core', '@stryker-mutator/jest-runner', '@stryker-mutator/html-reporter'];
private readonly generalDependencies = ['@stryker-mutator/core', '@stryker-mutator/jest-runner'];

private readonly sharedConfig = `testRunner: 'jest',
reporters: ['progress', 'clear-text', 'html'],
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/initializer/presets/VueJsPreset.ts
Expand Up @@ -10,7 +10,7 @@ const handbookUrl = 'https://github.com/stryker-mutator/stryker-handbook/blob/ma
*/
export class VueJsPreset implements Preset {
public readonly name = 'vueJs';
private readonly generalDependencies = ['@stryker-mutator/core', '@stryker-mutator/vue-mutator', '@stryker-mutator/html-reporter'];
private readonly generalDependencies = ['@stryker-mutator/core', '@stryker-mutator/vue-mutator'];

private readonly jestDependency = '@stryker-mutator/jest-runner';
private readonly jestConf = `{
Expand Down
Expand Up @@ -8,7 +8,7 @@ import { mutationTestReportSchema, Reporter } from '@stryker-mutator/api/report'
import fileUrl = require('file-url');

import { bindMutationTestReport } from './templates/bindMutationTestReport';
import * as util from './util';
import * as HtmlReporterUtil from './HtmlReporterUtil';

const DEFAULT_BASE_FOLDER = path.normalize('reports/mutation/html');
export const RESOURCES_DIR_NAME = 'strykerResources';
Expand All @@ -33,13 +33,13 @@ export default class HtmlReporter implements Reporter {
const indexFileName = path.resolve(this.baseDir, 'index.html');
await this.cleanBaseFolder();
await Promise.all([
util.copyFile(
HtmlReporterUtil.copyFile(
require.resolve('mutation-testing-elements/dist/mutation-test-elements.js'),
path.resolve(this.baseDir, 'mutation-test-elements.js')
),
util.copyFile(path.resolve(__dirname, 'templates', 'stryker-80x80.png'), path.resolve(this.baseDir, 'stryker-80x80.png')),
util.copyFile(path.resolve(__dirname, 'templates', 'index.html'), path.resolve(this.baseDir, 'index.html')),
util.writeFile(path.resolve(this.baseDir, 'bind-mutation-test-report.js'), bindMutationTestReport(report))
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))
]);
this.log.info(`Your report can be found at: ${fileUrl(indexFileName)}`);
}
Expand All @@ -60,7 +60,7 @@ export default class HtmlReporter implements Reporter {
}

private async cleanBaseFolder(): Promise<void> {
await util.deleteDir(this.baseDir);
await util.mkdir(this.baseDir);
await HtmlReporterUtil.deleteDir(this.baseDir);
await HtmlReporterUtil.mkdir(this.baseDir);
}
}
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/core/src/reporters/index.ts
Expand Up @@ -6,12 +6,14 @@ import DotsReporter from './DotsReporter';
import EventRecorderReporter from './EventRecorderReporter';
import ProgressAppendOnlyReporter from './ProgressAppendOnlyReporter';
import ProgressReporter from './ProgressReporter';
import HtmlReporter from './html/HtmlReporter';

export const strykerPlugins = [
declareClassPlugin(PluginKind.Reporter, 'clear-text', ClearTextReporter),
declareClassPlugin(PluginKind.Reporter, 'progress', ProgressReporter),
declareClassPlugin(PluginKind.Reporter, 'progress-append-only', ProgressAppendOnlyReporter),
declareClassPlugin(PluginKind.Reporter, 'dots', DotsReporter),
declareClassPlugin(PluginKind.Reporter, 'event-recorder', EventRecorderReporter),
declareClassPlugin(PluginKind.Reporter, 'html', HtmlReporter),
declareFactoryPlugin(PluginKind.Reporter, 'dashboard', dashboardReporterFactory)
];
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs';
import { testInjector } from '@stryker-mutator/test-helpers';
import { expect } from 'chai';

import HtmlReporter from '../../src/HtmlReporter';
import HtmlReporter from '../../../../src/reporters/html/HtmlReporter';

import { simpleReport } from './simpleReport';

Expand Down
Expand Up @@ -124,7 +124,7 @@ describe(StrykerInitializer.name, () => {
expect(promptTranspilers.type).to.eq('checkbox');
expect(promptTranspilers.choices).to.deep.eq(['typescript', 'webpack']);
expect(promptReporters.type).to.eq('checkbox');
expect(promptReporters.choices).to.deep.eq(['dimension', 'mars', 'clear-text', 'progress', 'dashboard']);
expect(promptReporters.choices).to.deep.eq(['dimension', 'mars', 'html', 'clear-text', 'progress', 'dashboard']);
expect(promptPackageManagers.type).to.eq('list');
expect(promptPackageManagers.choices).to.deep.eq(['npm', 'yarn']);
});
Expand Down
Expand Up @@ -5,9 +5,9 @@ import { testInjector } from '@stryker-mutator/test-helpers';
import { expect } from 'chai';
import * as sinon from 'sinon';

import HtmlReporter from '../../src/HtmlReporter';
import { bindMutationTestReport } from '../../src/templates/bindMutationTestReport';
import * as util from '../../src/util';
import HtmlReporter from '../../../../src/reporters/html/HtmlReporter';
import * as HtmlReporterUtil from '../../../../src/reporters/html/HtmlReporterUtil';
import { bindMutationTestReport } from '../../../../src/reporters/html/templates/bindMutationTestReport';

describe(HtmlReporter.name, () => {
let copyFileStub: sinon.SinonStub;
Expand All @@ -17,10 +17,10 @@ describe(HtmlReporter.name, () => {
let sut: HtmlReporter;

beforeEach(() => {
copyFileStub = sinon.stub(util, 'copyFile');
writeFileStub = sinon.stub(util, 'writeFile');
deleteDirStub = sinon.stub(util, 'deleteDir');
mkdirStub = sinon.stub(util, 'mkdir');
copyFileStub = sinon.stub(HtmlReporterUtil, 'copyFile');
writeFileStub = sinon.stub(HtmlReporterUtil, 'writeFile');
deleteDirStub = sinon.stub(HtmlReporterUtil, 'deleteDir');
mkdirStub = sinon.stub(HtmlReporterUtil, 'mkdir');
sut = testInjector.injector.injectClass(HtmlReporter);
});

Expand Down Expand Up @@ -55,11 +55,11 @@ describe(HtmlReporter.name, () => {
actReportReady();
await sut.wrapUp();
expect(copyFileStub).calledWith(
path.resolve(__dirname, '..', '..', 'src', 'templates', 'stryker-80x80.png'),
path.resolve(__dirname, '..', '..', '..', '..', 'src', 'reporters', 'html', 'templates', 'stryker-80x80.png'),
path.resolve('reports', 'mutation', 'html', 'stryker-80x80.png')
);
expect(copyFileStub).calledWith(
path.resolve(__dirname, '..', '..', 'src', 'templates', 'index.html'),
path.resolve(__dirname, '..', '..', '..', '..', 'src', 'reporters', 'html', 'templates', 'index.html'),
path.resolve('reports', 'mutation', 'html', 'index.html')
);
});
Expand Down
Binary file removed packages/html-reporter/example.png
Binary file not shown.
20 changes: 0 additions & 20 deletions packages/html-reporter/package.json
Expand Up @@ -4,9 +4,6 @@
"description": "An html reporter for the JavaScript mutation testing framework Stryker",
"main": "src/index.js",
"scripts": {
"test": "nyc --exclude-after-remap=false --check-coverage --reporter=html --report-dir=reports/coverage --lines 95 --functions 95 --branches 90 npm run mocha",
"mocha": "mocha \"test/helpers/**/*.js\" \"test/unit/**/*.js\" && mocha --timeout 20000 \"test/helpers/**/*.js\" \"test/integration/**/*.js\"",
"stryker": "node ../core/bin/stryker run"
},
"repository": {
"type": "git",
Expand All @@ -17,7 +14,6 @@
},
"keywords": [
"stryker",
"@stryker-mutator/reporter-plugin",
"html",
"report",
"mutation",
Expand All @@ -32,22 +28,6 @@
"url": "https://github.com/stryker-mutator/stryker/issues"
},
"homepage": "https://github.com/stryker-mutator/stryker/tree/master/packages/html-reporter#readme",
"dependencies": {
"@stryker-mutator/api": "^2.5.0",
"@stryker-mutator/util": "^2.5.0",
"file-url": "~3.0.0",
"mkdirp": "~1.0.3",
"mutation-testing-elements": "^1.0.2",
"rimraf": "~3.0.0"
},
"peerDependencies": {
"@stryker-mutator/core": "^2.0.0"
},
"devDependencies": {
"@stryker-mutator/test-helpers": "^2.5.0",
"@types/jsdom": "~12.2.0",
"@types/node": "^10.11.5"
},
"contributors": [
"Nico Jansen <jansennico@gmail.com>",
"Simon de Lang <simondelang@gmail.com>"
Expand Down
8 changes: 3 additions & 5 deletions packages/html-reporter/src/index.ts
@@ -1,5 +1,3 @@
import { declareClassPlugin, PluginKind } from '@stryker-mutator/api/plugin';

import HtmlReporter from './HtmlReporter';

export const strykerPlugins = [declareClassPlugin(PluginKind.Reporter, 'html', HtmlReporter)];
console.warn(
'This package is a stub package. The html reporter is now included with @stryker-mutator/core. There is no need to have the @stryker-mutator/html-reporter package installed! Are you still using stryker v2? Then please upgrade stryker to 3.x or downgrade this plugin to the latest 2.x release.'
);
7 changes: 0 additions & 7 deletions packages/html-reporter/stryker.conf.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/html-reporter/test/helpers/initChai.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/html-reporter/test/helpers/initSinon.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/html-reporter/test/helpers/initSourceMaps.ts

This file was deleted.

0 comments on commit 09702d9

Please sign in to comment.