Skip to content

Commit

Permalink
docs: setup docs for new website (#2578)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo-vrijswijk committed Oct 23, 2020
1 parent 1fb03af commit 59f39ee
Show file tree
Hide file tree
Showing 9 changed files with 532 additions and 0 deletions.
94 changes: 94 additions & 0 deletions docs/api/plugins.md
@@ -0,0 +1,94 @@
---
title: Plugins
custom_edit_url: https://github.com/stryker-mutator/stryker4s/edit/master/docs/api/plugins.md
---

You can extend Stryker with 6 plugin kinds:

```ts
export enum PluginKind {
ConfigEditor = 'ConfigEditor',
TestRunner = 'TestRunner',
TestFramework = 'TestFramework',
Transpiler = 'Transpiler',
Mutator = 'Mutator',
Reporter = 'Reporter',
}
```

They are loaded using the [`plugins` configuration option](https://github.com/stryker-mutator/stryker/tree/master/packages/core#plugins-string)

Each plugin has it's own job to do. For inspiration, check out the [stryker monorepo](https://github.com/stryker-mutator/stryker/tree/master/packages).

## Creating a plugin

Creating plugins is best done with typescript, as that will help you a lot with type safety.
We provide the `@stryker-mutator/api` dependency on the types and basic helper functionality. Install it with: `npm install @stryker-mutator/api`.

Next, you need to create a class that _is the actual plugin_. For example:

```ts
import { Transpiler } from '@stryker-mutator/api/transpile';
import { File, StrykerOptions } from '@stryker-mutator/api/core';

class FooTranspiler implements Transpiler {
public transpile(files: ReadonlyArray<File>): Promise<ReadonlyArray<File>> {
// TODO: implement
}
}
```

In this example, a Transpiler plugin is constructed. Each plugin kind has it's own interface, so it's easy to create.

After that, you're ready to declare your plugin.

## Declaring your plugin

You can either declare it as a factory method or a class.

A class example:

```ts
import HtmlReporter from './HtmlReporter';
import { PluginKind, declareClassPlugin } from '@stryker-mutator/api/plugin';

export const strykerPlugins = [declareClassPlugin(PluginKind.Reporter, 'html', HtmlReporter)];
```

A factory method example:

```ts
import { declareFactoryPlugin, PluginKind } from '@stryker-mutator/api/plugin';
import { babelTranspilerFactory } from './BabelTranspiler';

export const strykerPlugins = [declareFactoryPlugin(PluginKind.Transpiler, 'babel', babelTranspilerFactory)];
```

## Dependency injection

Stryker uses [typed-inject](https://github.com/nicojs/typed-inject#readme) as a [dependency injection framework](https://medium.com/@jansennico/advanced-typescript-type-safe-dependency-injection-873426e2cc96).
You can use it as well in your plugin.

See this example below. Here, a `Logger`, `StrykerOptions` and the `produceSourceMaps` boolean is injected.

```ts
import { Transpiler } from '@stryker-mutator/api/transpile';
import { File, StrykerOptions } from '@stryker-mutator/api/core';
import { tokens, commonTokens } from '@stryker-mutator/api/plugin';

class PassThroughTranspiler implements Transpiler {
public static inject = tokens(commonTokens.options, commonTokens.produceSourceMaps);
public constructor(private log: Logger, options: StrykerOptions, produceSourceMaps: boolean) {

public transpile(files: ReadonlyArray<File>): Promise<ReadonlyArray<File>> {
this.log.info('called with %s', files);
return files;
}
}
```
This is type-safe. When you declare your plugin, TypedInject will validate that you don't inject something that cannot be resolved at runtime.
## What's next?
If you need some help, please let us know on [Slack](https://join.slack.com/t/stryker-mutator/shared_invite/enQtOTUyMTYyNTg1NDQ0LTU4ODNmZDlmN2I3MmEyMTVhYjZlYmJkOThlNTY3NTM1M2QxYmM5YTM3ODQxYmJjY2YyYzllM2RkMmM1NjNjZjM).
72 changes: 72 additions & 0 deletions docs/getting-started.md
@@ -0,0 +1,72 @@
---
title: Getting started
custom_edit_url: https://github.com/stryker-mutator/stryker4s/edit/master/docs/getting-started.md
---

Install Stryker using [npm](https://nodejs.org).

![stryker-install](./images/stryker-install.gif)

## 1 Prepare

Make sure you have npm and nodejs installed. Open a terminal / command prompt and cd to the root of your project you want to mutation test.

```bash
$ cd my-project
```

---

## 2 Install

The easiest way to get started with Stryker is by installing the stryker-cli globally.
It is a small package which forwards commands to your local stryker instance.

```bash
$ npm install -g stryker-cli
```

Optionally, you could also install stryker directly yourself.

```bash
$ npm install --save-dev @stryker-mutator/core
```

If you choose to not install the stryker-cli, use `npx stryker` (after installing `@stryker-mutator/core` locally) instead of `stryker` for the rest of the quickstart.

---

## 3 Configure

Run this command the configure stryker.

```bash
$ stryker init
```

If you're asked to install stryker, choose **Yes**. Follow the questionnaire.

Please let us know if your option is missing here [by opening an issue](https://github.com/stryker-mutator/stryker/issues/new).

After the init is done, inspect the `stryker.conf.js` file.

For more information on what these options mean, take a look at the [Stryker readme](https://github.com/stryker-mutator/stryker/tree/master/packages/core#readme)

---

## 4 Let's kill some mutants

Run stryker to mutation test your project

```bash
$ stryker run
```

---

## 5 What's next?

Are you having troubles? Try enabling debug logging by adding `logLevel: 'debug'` to your stryker.conf.js.
To also see the output of your test runner, use `logLevel: 'trace'`.
You can also have a look at the [readme file of stryker](https://github.com/stryker-mutator/stryker/tree/master/packages/core#readme) for more information about the configuration.
Please [report any issues](http://github.com/stryker-mutator/stryker/issues) you have or let us know [via Slack](https://join.slack.com/t/stryker-mutator/shared_invite/enQtOTUyMTYyNTg1NDQ0LTU4ODNmZDlmN2I3MmEyMTVhYjZlYmJkOThlNTY3NTM1M2QxYmM5YTM3ODQxYmJjY2YyYzllM2RkMmM1NjNjZjM).
66 changes: 66 additions & 0 deletions docs/guides/angular.md
@@ -0,0 +1,66 @@
---
title: Angular
custom_edit_url: https://github.com/stryker-mutator/stryker4s/edit/master/docs/guides/angular.md
---

Stryker 4.0 and higher supports Angular projects using the Angular CLI starting from @angular/cli v9.0.0. Are you using an older version? Then there are some tips later in this document.

## @angular/cli 9.0.0 and higher

This setup only works with @angular/cli 9.0.0 or higher. Are you using an older version of Angular? Then we highly suggest upgrading to at least version 9.0.0 of the cli. You can use the [Angular Update Guide](https://update.angular.io/) to help you with this. If it's not possible for you to upgrade your Angular version, please check out [the legacy guide for Stryker 3 and Angular CLI 6.1-8.2](./legacy/stryker-3/angular.md).

## Install

Either install the Stryker CLI globally using `npm install --global stryker-cli`, or use `npx` in front of every Stryker command.
Install the Stryker packages using the command `stryker init`.

Recommended other packages:

- @angular/cli 9.0.0 or higher
- @angular-devkit/build-angular 0.900.0 or higher
- karma 4.3.0 or higher
- typescript 3.7.2 or higher

### Configuration

The `stryker init` command also creates a `stryker.conf.json` or `stryker.conf.js` configuration in your repository
like the one below which is a good starting point for Angular projects.
You may have to change some paths or config settings like the selected browsers.
We highly suggest using a headless browser when testing using Stryker.

```json
{
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"_comment": "This config was generated using a preset. Please see website for more information: https://stryker-mutator.io/docs/guides/angular",
"mutate": ["src/**/*.ts", "!src/**/*.spec.ts", "!src/test.ts", "!src/environments/*.ts"],
"testRunner": "karma",
"karma": {
"configFile": "karma.conf.js",
"projectType": "angular-cli",
"config": {
"browsers": ["ChromeHeadless"]
}
},
"reporters": ["progress", "clear-text", "html"],
"concurrency": 2,
"concurrency_comment": "Recommended to use about half of your available cores when running stryker with angular",
"coverageAnalysis": "perTest"
}
```

Consider adding the Stryker TypeScript checker to increase mutation testing performance and kill mutants that would result in compilation errors:

1. Install `@stryker-mutator/typescript-checker` as a development dependency:
`npm install --save-dev @stryker-mutator/typescript-checker`
1. Configure the TypeScript checker in `stryker.conf.json`:
```json
{
"checkers": ["typescript"],
"tsconfigFile": "tsconfig.json"
}
```
If you experience issues, try setting the `tsconfigFile` option to `tsconfig.app.json`.

### Run

Run Stryker using `stryker run`.
56 changes: 56 additions & 0 deletions docs/guides/legacy/stryker-3/angular.md
@@ -0,0 +1,56 @@
---
title: Angular
custom_edit_url: https://github.com/stryker-mutator/stryker4s/edit/master/docs/guides/legacy/stryker-3/angular.md
---

Stryker supports Angular projects using the Angular CLI between @angular/cli 6.1.0 and 8.3.29. Are you using an older version? Then there are some tips later in this document.

## @angular/cli 6.1.0-8.3.29

This setup only works with @angular/cli 6.1.0-8.3.29. Are you using an older version of Angular? Then we highly suggest upgrading to at least version 6.1.0 of the cli. You can use the [Angular Update Guide](https://update.angular.io/) to help you with this. If it's not possible for you to upgrade your Angular version, please check out [this repo and its commits](https://github.com/nicojs/angular-stryker-example).

## Install

Install the Stryker packages using this command: `npm i -D @stryker-mutator/core@3 @stryker-mutator/karma-runner@3 @stryker-mutator/typescript@3 @stryker-mutator/html-reporter@3`

Recommended other packages:

- @angular/cli 6.1.0-8.3.29
- @angular-devkit/build-angular 0.7.2-0.803.29
- karma 2.0.4 or higher
- typescript 2.4.2 or higher

### Configuration

After installing the recommended packages, create the `stryker.conf.js` file in your repository.
The configuration below contains a good starting point for Angular projects.
You may have to change some paths or config settings like the selected browsers.
We highly suggest using a headless browser when testing using stryker.

Coverage analysis with [@stryker-mutator/jasmine-framework](http://npmjs.com/package/@stryker-mutator/jasmine-framework) is unfortunately not supported as of right now.

```js
module.exports = function (config) {
config.set({
mutate: ['src/**/*.ts', '!src/**/*.spec.ts', '!src/test.ts', '!src/environments/*.ts'],
mutator: 'typescript',
testRunner: 'karma',
karma: {
configFile: 'src/karma.conf.js',
projectType: 'angular-cli',
config: {
browsers: ['ChromeHeadless'],
},
},
reporters: ['progress', 'clear-text', 'html'],
// maxConcurrentTestRunners: 2, // Recommended to not use all cores when running stryker with angular.
coverageAnalysis: 'off',
});
};
```

It is recommended to configure the `maxConcurrentTestRunners` option and configure about half of your available cores there.

### Run

Run Stryker using `npx stryker run`
50 changes: 50 additions & 0 deletions docs/guides/react.md
@@ -0,0 +1,50 @@
---
title: React
custom_edit_url: https://github.com/stryker-mutator/stryker4s/edit/master/docs/guides/react.md
---

Stryker supports React projects using Jest with both JSX and TSX code.

## JSX project

Recommended stryker packages: `npm i -D @stryker-mutator/core @stryker-mutator/jest-runner @stryker-mutator/javascript-mutator @stryker-mutator/html-reporter`

Recommended other packages:

- jest 23.0.0 or higher

### Configuration

After installing the recommended packages, create the `stryker.conf.js` file in your repository.
The configuration below contains a good starting point for React projects.
You may have to change some paths like the mutate array.

Coverage analysis is unfortunately not supported as of right now.

```js
module.exports = function (config) {
config.set({
mutate: ['src/**/*.js?(x)', '!src/**/*@(.test|.spec|Spec).js?(x)'],
mutator: 'javascript',
testRunner: 'jest',
reporter: ['progress', 'clear-text', 'html'],
coverageAnalysis: 'off',
jest: {
project: 'react',
},
});
};
```

## TSX projects

For projects using TypeScript and TSX, you can follow the JSX guide but with a few differences:

Recommended stryker packages: `npm i -D @stryker-mutator/core @stryker-mutator/jest-runner @stryker-mutator/typescript @stryker-mutator/html-reporter`

Configuration:

```js
mutate: ['src/**/*.ts?(x)', '!src/**/*@(.test|.spec|Spec).ts?(x)'],
mutator: 'typescript',
```

0 comments on commit 59f39ee

Please sign in to comment.