Skip to content

Commit

Permalink
Merge pull request #56 from infosupport/v0.1-preparation
Browse files Browse the repository at this point in the history
V1.1.0 preparation
  • Loading branch information
nicojs committed Mar 18, 2016
2 parents 67d6946 + 24e81d0 commit 3ab7f4f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 90 deletions.
73 changes: 16 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -31,65 +34,21 @@ 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.
When calling stryker with multiple source and/or test files, they have to be separated using comma's.

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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
41 changes: 9 additions & 32 deletions src/Stryker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -119,20 +105,11 @@ export default class Stryker {
program
.usage('-s <items> -t <items> [other options]')
.option('-s, --src <items>', 'A list of source files. Example: a.js,b.js', list)
.option('-t, --tests <items>', '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 <items>', '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() { });
}
})();

0 comments on commit 3ab7f4f

Please sign in to comment.