diff --git a/README.md b/README.md index 5de2abf123..801bf0dfe0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![Build Status](https://travis-ci.org/infosupport/stryker.svg?branch=master)](https://travis-ci.org/infosupport/stryker) +[![NPM](https://img.shields.io/npm/dm/stryker.svg)](https://www.npmjs.com/package/stryker) [![Gitter](https://badges.gitter.im/infosupport/stryker.svg)](https://gitter.im/infosupport/stryker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) # Stryker @@ -12,15 +13,17 @@ This repository is a work in progress. As of now, stryker is not published on NP ## Getting started Stryker is a mutation testing framework for JavaScript. It allows you to test your test by temporarily inserting bugs. -To install stryker, do the following: - -1. Download or clone the repository -2. Add `"stryker": "^0.0.1"` to devDependencies in your `package.json` -3. Run the command `npm link ../path/to/styker/` from the root of your project -4. Run the command `node node_modules/stryker/src/Stryker.js --help` to test if stryker works - +To install stryker, execute the command: +``` +npm install stryker --save-dev +``` ***Note****: During the installation you may run into errors caused by [node-gyp](https://github.com/nodejs/node-gyp). It is safe to ignore these errors.* +To test if stryker is working, execute the command: +``` +node node_modules/stryker/dist/src/Stryker.js --help +``` + ## Configuration ### Available options #### Source files @@ -31,51 +34,13 @@ To install stryker, do the following: The list of source files which should be mutated, separated by comma's. **Example:** -s src/a.js,src/b.js -#### Test files -**Short notation:** -t -**Full notation:** --tests +#### Other files +**Short notation:** -o +**Full notation:** --other-files **Optional:** **No** **Description:** -The list of test files which should be tested, separated by comma's. -**Example:** -t test/a.js,test/b.js - -#### Library files -**Short notation:** -l -**Full notation:** --libs -**Optional:** Yes -**Description:** -The list of library files which are required to run the tests, separated by comma's. These files will not be mutated. -**Example:** -l lib/a.js,src/b.js - -#### Constant timeout -**Short notation:** -m -**Full notation:** --timeout-ms -**Optional:** Yes -**Default:** 3000 -**Description:** -The amount of extra time (in milliseconds) a mutation test may take compared to the original test before a timeout occcurs. -**Example:** -m 5000 - -#### Timeout factor -**Short notation:** -f -**Full notation:** --timeout-factor -**Optional:** Yes -**Default:** 1.25 -**Description:** -A factor which is applied to the time a mutation-test may take. This factor is applied after the constant timeout. -For example, if the normal test took 100ms, the constant timeout is 500ms and the timeout factor is 2.0, a mutation test will timeout if it takes longer than 1200ms. -**Example:** -f 1.50 - -#### Individual tests -**Short notation:** -i -**Full notation:** --individual-tests -**Optional:** Yes -**Default:** false -**Description:** -Stryker will always attempt to run the least amount of tests when testing a mutant to ensure the best performance. -By default Stryker does not select individual tests but instead it selects entire test files. -Splitting these test files into separate tests *can* cause a performance gain in certain projects, but it *can* also slow Stryker down. -**Example:** -i +The list of other files which are needed, separated by comma's. These should be: test files, library files and any other file you need to run your project. +**Example:** -o test/a.js,test/b.js ### Default config By default, stryker requires two arguments: the source and test files. @@ -83,13 +48,7 @@ When calling stryker with multiple source and/or test files, they have to be sep A basic usage of stryker is: ``` -node node_modules/stryker/src/Stryker.js –s src/myFirstFile.js,src/mySecondFile.js –t test/myFirstFileSpec.js,test/mySecondsFileSpec.js -``` - -### Complete config -The configuration below uses all available options for demonstration purposes: -``` -node node_modules/stryker/src/Stryker.js –s src/myFirstFile.js,src/mySecondFile.js –t test/myFirstFileSpec.js,test/mySecondsFileSpec.js -m 5000 -f 1.50 --individual-tests +node node_modules/stryker/src/Stryker.js –s src/myFirstFile.js,src/mySecondFile.js –o test/myFirstFileSpec.js,test/mySecondsFileSpec.js,libs/externalLibrary.js ``` ## Supported mutations diff --git a/package.json b/package.json index be7a4c537d..c415043ffb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stryker", - "version": "1.0.0", + "version": "1.1.0", "description": "The extendable JavaScript mutation testing framwork", "main": "src/Stryker.js", "scripts": { diff --git a/src/Stryker.ts b/src/Stryker.ts index 3d46562517..22ca1a8897 100644 --- a/src/Stryker.ts +++ b/src/Stryker.ts @@ -25,33 +25,19 @@ export default class Stryker { * The Stryker mutation tester. * @constructor * @param {String[]} sourceFiles - The list of source files which should be mutated. - * @param {String[]} testFiles - The list of test files. + * @param {String[]} otherFiles - The list of test files. * @param {Object} [options] - Optional options. - * @param {Number} [options].[timeoutMs] - Amount of additional time, in milliseconds, the mutation test is allowed to run. - * @param {Number} [options].[timeoutFactor] - A factor which is applied to the timeout. */ - constructor(private sourceFiles: string[], private testFiles: string[], options?: StrykerOptions) { + constructor(private sourceFiles: string[], private otherFiles: string[], options?: StrykerOptions) { this.fileUtils.normalize(sourceFiles); - this.fileUtils.normalize(testFiles); + this.fileUtils.normalize(otherFiles); this.fileUtils.createBaseTempFolder(); - - if (options) { - options = { - timeoutMs: options.timeoutMs || 3000, - timeoutFactor: options.timeoutFactor || 1.25, - }; - } else { - options = { - libs: [], - timeoutMs: 3000, - timeoutFactor: 1.25, - individualTests: false - }; - } + + options = options || {}; options.testFramework = 'jasmine'; options.testRunner = 'karma'; options.port = 1234; - this.testRunnerOrchestrator = new TestRunnerOrchestrator(options, sourceFiles, testFiles); + this.testRunnerOrchestrator = new TestRunnerOrchestrator(options, sourceFiles, otherFiles); var reporterFactory = new ReporterFactory(); this.reporter = reporterFactory.getReporter('console'); @@ -119,20 +105,11 @@ export default class Stryker { program .usage('-s -t [other options]') .option('-s, --src ', 'A list of source files. Example: a.js,b.js', list) - .option('-t, --tests ', 'A list of test files. Example: a.js,b.js', list) - .option('-m, --timeout-ms [amount]', 'Amount of additional time, in milliseconds, the mutation test is allowed to run') - .option('-f, --timeout-factor [amount]', 'The factor is applied on top of the other timeouts when during mutation testing') + .option('-o, --other-files ', 'A list of other files, such as test files or library files. Example: a.js,b.js', list) .parse(process.argv); - if (program.src && program.tests) { - var options: StrykerOptions = { - libs: program.libs, - timeoutMs: Number(program.timeoutMs), - timeoutFactor: Number(program.timeoutFactor), - individualTests: program.individualTests - }; - - var stryker = new Stryker(program.src, program.tests, options); + if (program.src && program.otherFiles) { + var stryker = new Stryker(program.src, program.otherFiles); stryker.runMutationTest(function() { }); } })();