Comparing version 0.32.1 to 0.33.0
@@ -6,2 +6,19 @@ # Change Log | ||
<a name="0.33.0"></a> | ||
# [0.33.0](https://github.com/stryker-mutator/stryker/compare/stryker@0.32.1...stryker@0.33.0) (2018-11-29) | ||
### Bug Fixes | ||
* **JestTestRunner:** run jest with --findRelatedTests ([#1235](https://github.com/stryker-mutator/stryker/issues/1235)) ([5e0790e](https://github.com/stryker-mutator/stryker/commit/5e0790e)) | ||
### Features | ||
* **console-colors:** Add a global config option to enable/disable colors in console ([#1251](https://github.com/stryker-mutator/stryker/issues/1251)) ([19b1d64](https://github.com/stryker-mutator/stryker/commit/19b1d64)) | ||
* **Stryker CLI 'init':** Support for preset configuration during 'stryker init' ([#1248](https://github.com/stryker-mutator/stryker/issues/1248)) ([5673e6b](https://github.com/stryker-mutator/stryker/commit/5673e6b)) | ||
<a name="0.32.1"></a> | ||
@@ -8,0 +25,0 @@ ## [0.32.1](https://github.com/stryker-mutator/stryker/compare/stryker@0.32.0...stryker@0.32.1) (2018-11-21) |
{ | ||
"name": "stryker", | ||
"version": "0.32.1", | ||
"version": "0.33.0", | ||
"description": "The extendable JavaScript mutation testing framework", | ||
@@ -86,3 +86,3 @@ "main": "src/Stryker.js", | ||
"@types/progress": "~2.0.1", | ||
"stryker-api": "^0.21.5" | ||
"stryker-api": "^0.22.0" | ||
}, | ||
@@ -89,0 +89,0 @@ "peerDependencies": { |
@@ -345,1 +345,9 @@ [![Build Status](https://travis-ci.org/stryker-mutator/stryker.svg?branch=master)](https://travis-ci.org/stryker-mutator/stryker) | ||
Set the log level that Stryker uses to write to the "stryker.log" file. Possible values: `off`, `fatal`, `error`, `warn`, `info`, `debug` and `trace` | ||
### `allowConsoleColors` [`boolean`] | ||
Default: `true` | ||
Command line: `--allowConsoleColors true` | ||
Config file: `allowConsoleColors: true` | ||
The `allowConsoleColors` value indicates whether or not Stryker should use colors in console. |
import { StrykerOptions } from 'stryker-api/core'; | ||
import PromptOption from './PromptOption'; | ||
import PresetConfiguration from './presets/PresetConfiguration'; | ||
export default class StrykerConfigWriter { | ||
@@ -13,5 +14,11 @@ private readonly out; | ||
write(selectedTestRunner: null | PromptOption, selectedTestFramework: null | PromptOption, selectedMutator: null | PromptOption, selectedTranspilers: null | PromptOption[], selectedReporters: PromptOption[], selectedPackageManager: PromptOption, additionalPiecesOfConfig: Partial<StrykerOptions>[]): Promise<void>; | ||
/** | ||
* Create stryker.conf.js based on the chosen preset | ||
* @function | ||
*/ | ||
writePreset(presetConfig: PresetConfiguration): Promise<void>; | ||
private configureTestFramework; | ||
private writeStrykerConfigRaw; | ||
private writeStrykerConfig; | ||
private wrapInModule; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var _ = require("lodash"); | ||
@@ -36,2 +37,13 @@ var util_1 = require("@stryker-mutator/util"); | ||
}; | ||
/** | ||
* Create stryker.conf.js based on the chosen preset | ||
* @function | ||
*/ | ||
StrykerConfigWriter.prototype.writePreset = function (presetConfig) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
return [2 /*return*/, this.writeStrykerConfigRaw(presetConfig.config, "// This config was generated using a preset.\n // Please see the handbook for more information: " + presetConfig.handbookUrl)]; | ||
}); | ||
}); | ||
}; | ||
StrykerConfigWriter.prototype.configureTestFramework = function (configObject, selectedTestFramework) { | ||
@@ -46,8 +58,13 @@ if (selectedTestFramework) { | ||
}; | ||
StrykerConfigWriter.prototype.writeStrykerConfig = function (configObject) { | ||
StrykerConfigWriter.prototype.writeStrykerConfigRaw = function (rawConfig, rawHeader) { | ||
if (rawHeader === void 0) { rawHeader = ''; } | ||
this.out('Writing stryker.conf.js...'); | ||
return util_1.fsAsPromised.writeFile(STRYKER_CONFIG_FILE, this.wrapInModule(configObject)); | ||
var formattedConf = prettier_1.format(rawHeader + "\n module.exports = function(config){\n config.set(\n " + rawConfig + "\n );\n }", { parser: 'babylon' }); | ||
return util_1.fsAsPromised.writeFile(STRYKER_CONFIG_FILE, formattedConf); | ||
}; | ||
StrykerConfigWriter.prototype.writeStrykerConfig = function (configObject) { | ||
return this.writeStrykerConfigRaw(this.wrapInModule(configObject)); | ||
}; | ||
StrykerConfigWriter.prototype.wrapInModule = function (configObject) { | ||
return prettier_1.format("\n module.exports = function(config){\n config.set(\n " + JSON.stringify(configObject, null, 2) + "\n );\n }", { parser: 'babylon' }); | ||
return JSON.stringify(configObject, null, 2); | ||
}; | ||
@@ -54,0 +71,0 @@ return StrykerConfigWriter; |
import NpmClient from './NpmClient'; | ||
import Preset from './presets/Preset'; | ||
export default class StrykerInitializer { | ||
private readonly out; | ||
private readonly client; | ||
private readonly strykerPresets; | ||
private readonly log; | ||
private readonly inquirer; | ||
constructor(out?: (message?: any, ...optionalParams: any[]) => void, client?: NpmClient); | ||
constructor(out?: (message?: any, ...optionalParams: any[]) => void, client?: NpmClient, strykerPresets?: Preset[]); | ||
/** | ||
@@ -18,2 +20,5 @@ * Runs the initializer will prompt the user for questions about his setup. After that, install plugins and configure Stryker. | ||
private patchProxies; | ||
private selectPreset; | ||
private initiatePreset; | ||
private initiateCustom; | ||
private selectTestRunner; | ||
@@ -20,0 +25,0 @@ private selectReporters; |
@@ -11,8 +11,11 @@ "use strict"; | ||
var CommandTestRunner_1 = require("../test-runner/CommandTestRunner"); | ||
var StrykerPresets_1 = require("./StrykerPresets"); | ||
var StrykerInitializer = /** @class */ (function () { | ||
function StrykerInitializer(out, client) { | ||
function StrykerInitializer(out, client, strykerPresets) { | ||
if (out === void 0) { out = console.log; } | ||
if (client === void 0) { client = new NpmClient_1.default(); } | ||
if (strykerPresets === void 0) { strykerPresets = StrykerPresets_1.default; } | ||
this.out = out; | ||
this.client = client; | ||
this.strykerPresets = strykerPresets; | ||
this.log = logging_1.getLogger(StrykerInitializer.name); | ||
@@ -27,5 +30,5 @@ this.inquirer = new StrykerInquirer_1.StrykerInquirer(); | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var configWriter, selectedTestRunner, selectedTestFramework, _a, selectedMutator, selectedTranspilers, selectedReporters, selectedPackageManager, npmDependencies, _b, _c, _d; | ||
return tslib_1.__generator(this, function (_e) { | ||
switch (_e.label) { | ||
var configWriter, selectedPreset; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
@@ -35,4 +38,79 @@ configWriter = new StrykerConfigWriter_1.default(this.out); | ||
this.patchProxies(); | ||
return [4 /*yield*/, this.selectTestRunner()]; | ||
return [4 /*yield*/, this.selectPreset()]; | ||
case 1: | ||
selectedPreset = _a.sent(); | ||
if (!selectedPreset) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.initiatePreset(configWriter, selectedPreset)]; | ||
case 2: | ||
_a.sent(); | ||
return [3 /*break*/, 5]; | ||
case 3: return [4 /*yield*/, this.initiateCustom(configWriter)]; | ||
case 4: | ||
_a.sent(); | ||
_a.label = 5; | ||
case 5: | ||
this.out('Done configuring stryker. Please review `stryker.conf.js`, you might need to configure transpilers or your test runner correctly.'); | ||
this.out('Let\'s kill some mutants with this command: `stryker run`'); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* The typed rest client works only with the specific HTTP_PROXY and HTTPS_PROXY env settings. | ||
* Let's make sure they are available. | ||
*/ | ||
StrykerInitializer.prototype.patchProxies = function () { | ||
var copyEnvVariable = function (from, to) { | ||
if (process.env[from] && !process.env[to]) { | ||
process.env[to] = process.env[from]; | ||
} | ||
}; | ||
copyEnvVariable('http_proxy', 'HTTP_PROXY'); | ||
copyEnvVariable('https_proxy', 'HTTPS_PROXY'); | ||
}; | ||
StrykerInitializer.prototype.selectPreset = function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var presetOptions; | ||
return tslib_1.__generator(this, function (_a) { | ||
presetOptions = this.strykerPresets; | ||
if (presetOptions.length) { | ||
this.log.debug("Found presets: " + JSON.stringify(presetOptions)); | ||
return [2 /*return*/, this.inquirer.promptPresets(presetOptions)]; | ||
} | ||
else { | ||
this.log.debug('No presets have been configured, reverting to custom configuration'); | ||
return [2 /*return*/, undefined]; | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
StrykerInitializer.prototype.initiatePreset = function (configWriter, selectedPreset) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var presetConfig, selectedPackageManager; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, selectedPreset.createConfig()]; | ||
case 1: | ||
presetConfig = _a.sent(); | ||
return [4 /*yield*/, configWriter.writePreset(presetConfig)]; | ||
case 2: | ||
_a.sent(); | ||
return [4 /*yield*/, this.selectPackageManager()]; | ||
case 3: | ||
selectedPackageManager = _a.sent(); | ||
this.installNpmDependencies(presetConfig.dependencies, selectedPackageManager); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
StrykerInitializer.prototype.initiateCustom = function (configWriter) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var selectedTestRunner, selectedTestFramework, _a, selectedMutator, selectedTranspilers, selectedReporters, selectedPackageManager, npmDependencies, _b, _c, _d; | ||
return tslib_1.__generator(this, function (_e) { | ||
switch (_e.label) { | ||
case 0: return [4 /*yield*/, this.selectTestRunner()]; | ||
case 1: | ||
selectedTestRunner = _e.sent(); | ||
@@ -76,4 +154,2 @@ if (!(selectedTestRunner && !CommandTestRunner_1.default.is(selectedTestRunner.name))) return [3 /*break*/, 3]; | ||
this.installNpmDependencies(npmDependencies, selectedPackageManager); | ||
this.out('Done configuring stryker. Please review `stryker.conf.js`, you might need to configure transpilers or your test runner correctly.'); | ||
this.out('Let\'s kill some mutants with this command: `stryker run`'); | ||
return [2 /*return*/]; | ||
@@ -84,15 +160,2 @@ } | ||
}; | ||
/** | ||
* The typed rest client works only with the specific HTTP_PROXY and HTTPS_PROXY env settings. | ||
* Let's make sure they are available. | ||
*/ | ||
StrykerInitializer.prototype.patchProxies = function () { | ||
var copyEnvVariable = function (from, to) { | ||
if (process.env[from] && !process.env[to]) { | ||
process.env[to] = process.env[from]; | ||
} | ||
}; | ||
copyEnvVariable('http_proxy', 'HTTP_PROXY'); | ||
copyEnvVariable('https_proxy', 'HTTPS_PROXY'); | ||
}; | ||
StrykerInitializer.prototype.selectTestRunner = function () { | ||
@@ -99,0 +162,0 @@ return tslib_1.__awaiter(this, void 0, void 0, function () { |
import PromptOption from './PromptOption'; | ||
import Preset from './presets/Preset'; | ||
export interface PromptResult { | ||
@@ -7,2 +8,3 @@ additionalNpmDependencies: string[]; | ||
export declare class StrykerInquirer { | ||
promptPresets(options: Preset[]): Promise<Preset | undefined>; | ||
promptTestRunners(options: PromptOption[]): Promise<PromptOption>; | ||
@@ -9,0 +11,0 @@ promptTestFrameworks(options: PromptOption[]): Promise<PromptOption>; |
@@ -9,2 +9,24 @@ "use strict"; | ||
} | ||
StrykerInquirer.prototype.promptPresets = function (options) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var choices, answers; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
choices = options.map(function (_) { return _.name; }); | ||
choices.push(new inquirer.Separator()); | ||
choices.push('None/other'); | ||
return [4 /*yield*/, inquirer.prompt({ | ||
choices: choices, | ||
message: 'Are you using one of these frameworks? Then select a preset configuration.', | ||
name: 'preset', | ||
type: 'list' | ||
})]; | ||
case 1: | ||
answers = _a.sent(); | ||
return [2 /*return*/, options.find(function (_) { return _.name === answers.preset; })]; | ||
} | ||
}); | ||
}); | ||
}; | ||
StrykerInquirer.prototype.promptTestRunners = function (options) { | ||
@@ -11,0 +33,0 @@ return tslib_1.__awaiter(this, void 0, void 0, function () { |
@@ -12,3 +12,3 @@ import { LogLevel } from 'stryker-api/core'; | ||
*/ | ||
static configureMainProcess(consoleLogLevel?: LogLevel, fileLogLevel?: LogLevel): void; | ||
static configureMainProcess(consoleLogLevel?: LogLevel, fileLogLevel?: LogLevel, allowConsoleColors?: boolean): void; | ||
/** | ||
@@ -23,3 +23,3 @@ * Configure the logging for the server. Includes the master configuration. | ||
*/ | ||
static configureLoggingServer(consoleLogLevel: LogLevel, fileLogLevel: LogLevel): Promise<LoggingClientContext>; | ||
static configureLoggingServer(consoleLogLevel: LogLevel, fileLogLevel: LogLevel, allowConsoleColors: boolean): Promise<LoggingClientContext>; | ||
/** | ||
@@ -26,0 +26,0 @@ * Configures the logging for a worker process. Sends all logging to the master process. |
@@ -33,8 +33,9 @@ "use strict"; | ||
} | ||
LogConfigurator.createMainProcessAppenders = function (consoleLogLevel, fileLogLevel) { | ||
LogConfigurator.createMainProcessAppenders = function (consoleLogLevel, fileLogLevel, allowConsoleColors) { | ||
var _a, _b; | ||
// Add the custom "multiAppender": https://log4js-node.github.io/log4js-node/appenders.html#other-appenders | ||
var multiAppender = { type: require.resolve('./MultiAppender'), appenders: [AppenderName.FilteredConsoleLevel] }; | ||
var consoleLayout = allowConsoleColors ? layouts.color : layouts.noColor; | ||
var allAppenders = (_a = {}, | ||
_a[AppenderName.Console] = { type: 'stdout', layout: layouts.color }, | ||
_a[AppenderName.Console] = { type: 'stdout', layout: consoleLayout }, | ||
// Exclude messages like: "ERROR log4js A worker log process hung up unexpectedly" #1245 | ||
@@ -74,7 +75,8 @@ _a[AppenderName.FilteredConsoleCategory] = { type: 'categoryFilter', appender: AppenderName.Console, exclude: 'log4js' }, | ||
*/ | ||
LogConfigurator.configureMainProcess = function (consoleLogLevel, fileLogLevel) { | ||
LogConfigurator.configureMainProcess = function (consoleLogLevel, fileLogLevel, allowConsoleColors) { | ||
if (consoleLogLevel === void 0) { consoleLogLevel = core_1.LogLevel.Information; } | ||
if (fileLogLevel === void 0) { fileLogLevel = core_1.LogLevel.Off; } | ||
if (allowConsoleColors === void 0) { allowConsoleColors = true; } | ||
this.setImplementation(); | ||
var appenders = this.createMainProcessAppenders(consoleLogLevel, fileLogLevel); | ||
var appenders = this.createMainProcessAppenders(consoleLogLevel, fileLogLevel, allowConsoleColors); | ||
log4js.configure(this.createLog4jsConfig(logUtils_1.minLevel(consoleLogLevel, fileLogLevel), appenders)); | ||
@@ -91,3 +93,3 @@ }; | ||
*/ | ||
LogConfigurator.configureLoggingServer = function (consoleLogLevel, fileLogLevel) { | ||
LogConfigurator.configureLoggingServer = function (consoleLogLevel, fileLogLevel, allowConsoleColors) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
@@ -102,3 +104,3 @@ var loggerPort, appenders, multiProcessAppender, defaultLogLevel, context; | ||
loggerPort = _a.sent(); | ||
appenders = this.createMainProcessAppenders(consoleLogLevel, fileLogLevel); | ||
appenders = this.createMainProcessAppenders(consoleLogLevel, fileLogLevel, allowConsoleColors); | ||
multiProcessAppender = { | ||
@@ -105,0 +107,0 @@ appender: AppenderName.All, |
@@ -9,2 +9,3 @@ import { Reporter, MutantResult, ScoreResult } from 'stryker-api/report'; | ||
private writeLine; | ||
private configConsoleColor; | ||
onAllMutantsTested(mutantResults: MutantResult[]): void; | ||
@@ -11,0 +12,0 @@ private logMutantResult; |
@@ -13,2 +13,3 @@ "use strict"; | ||
this.out = process.stdout; | ||
this.configConsoleColor(); | ||
} | ||
@@ -18,2 +19,7 @@ ClearTextReporter.prototype.writeLine = function (output) { | ||
}; | ||
ClearTextReporter.prototype.configConsoleColor = function () { | ||
if (!this.options.allowConsoleColors) { | ||
chalk_1.default.level = 0; // All colors disabled | ||
} | ||
}; | ||
ClearTextReporter.prototype.onAllMutantsTested = function (mutantResults) { | ||
@@ -20,0 +26,0 @@ var _this = this; |
@@ -21,3 +21,3 @@ import { Config } from 'stryker-api/config'; | ||
static create(options: Config, index: number, files: ReadonlyArray<File>, testFramework: TestFramework | null, timeoutOverheadMS: number, loggingContext: LoggingClientContext): Promise<Sandbox>; | ||
run(timeout: number, testHooks: string | undefined): Promise<RunResult>; | ||
run(timeout: number, testHooks: string | undefined, mutatedFileName?: string): Promise<RunResult>; | ||
dispose(): Promise<void>; | ||
@@ -24,0 +24,0 @@ runMutant(transpiledMutant: TranspiledMutant): Promise<RunResult>; |
@@ -43,4 +43,4 @@ "use strict"; | ||
}; | ||
Sandbox.prototype.run = function (timeout, testHooks) { | ||
return this.testRunner.run({ timeout: timeout, testHooks: testHooks }); | ||
Sandbox.prototype.run = function (timeout, testHooks, mutatedFileName) { | ||
return this.testRunner.run({ timeout: timeout, testHooks: testHooks, mutatedFileName: mutatedFileName }); | ||
}; | ||
@@ -64,3 +64,3 @@ Sandbox.prototype.dispose = function () { | ||
_a.sent(); | ||
return [4 /*yield*/, this.run(this.calculateTimeout(transpiledMutant.mutant), this.getFilterTestsHooks(transpiledMutant.mutant))]; | ||
return [4 /*yield*/, this.run(this.calculateTimeout(transpiledMutant.mutant), this.getFilterTestsHooks(transpiledMutant.mutant), this.fileMap[transpiledMutant.mutant.fileName])]; | ||
case 2: | ||
@@ -67,0 +67,0 @@ runResult = _a.sent(); |
@@ -29,10 +29,10 @@ "use strict"; | ||
this.timer = new Timer_1.default(); | ||
LogConfigurator_1.default.configureMainProcess(options.logLevel, options.fileLogLevel); | ||
LogConfigurator_1.default.configureMainProcess(options.logLevel, options.fileLogLevel, options.allowConsoleColors); | ||
this.log = logging_1.getLogger(Stryker.name); | ||
var configReader = new ConfigReader_1.default(options); | ||
this.config = configReader.readConfig(); | ||
LogConfigurator_1.default.configureMainProcess(this.config.logLevel, this.config.fileLogLevel); // logLevel could be changed | ||
LogConfigurator_1.default.configureMainProcess(this.config.logLevel, this.config.fileLogLevel, this.config.allowConsoleColors); // logLevel could be changed | ||
this.loadPlugins(); | ||
this.applyConfigEditors(); | ||
LogConfigurator_1.default.configureMainProcess(this.config.logLevel, this.config.fileLogLevel); // logLevel could be changed | ||
LogConfigurator_1.default.configureMainProcess(this.config.logLevel, this.config.fileLogLevel, this.config.allowConsoleColors); // logLevel could be changed | ||
this.freezeConfig(); | ||
@@ -48,3 +48,3 @@ this.reporter = new ReporterOrchestrator_1.default(this.config).createBroadcastReporter(); | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, LogConfigurator_1.default.configureLoggingServer(this.config.logLevel, this.config.fileLogLevel)]; | ||
case 0: return [4 /*yield*/, LogConfigurator_1.default.configureLoggingServer(this.config.logLevel, this.config.fileLogLevel, this.config.allowConsoleColors)]; | ||
case 1: | ||
@@ -51,0 +51,0 @@ loggingContext = _a.sent(); |
@@ -44,3 +44,9 @@ "use strict"; | ||
.option('--fileLogLevel <level>', 'Set the log4js log level for the "stryker.log" file. Possible values: fatal, error, warn, info, debug, trace, all and off. Default is "off"') | ||
.option('--allowConsoleColors <true/false>', 'Indicates whether or not Stryker should use colors in console.', parseBoolean, true) | ||
.parse(this.argv); | ||
function parseBoolean(val) { | ||
console.log('bool: ', val); | ||
var v = val.toLocaleLowerCase(); | ||
return v !== 'false' && v !== '0'; | ||
} | ||
LogConfigurator_1.default.configureMainProcess(program.logLevel); | ||
@@ -47,0 +53,0 @@ var log = logging_1.getLogger(StrykerCli.name); |
414031
185
7405
353