You can extend Stryker with the following plugin kinds:
They are loaded using the
plugins configuration option
Each plugin has it's own job to do. For inspiration, check out the stryker monorepo.
Creating plugins is best done with typescript, as that will help you a lot with type safety and intellisense.
We provide the
@stryker-mutator/api dependency on the types and basic helper functionality. This should be installed as a
dependency of your plugin.
Next, you need to create a class that is the actual plugin. For example:
In this example, a
TestRunner plugin is constructed. Each plugin kind has it's own interface, so it is easy to get started with a skeleton implementation.
After you've created your skeleton plugin, you're ready to declare it.
In order to make your plugin known to Stryker, you should export the declaration of your plugin. You can either declare it as a factory method or a class. Stryker will take care of creating your plugin implementation at the correct moment in the Stryker lifecycle.
A class example:
A factory method example (useful when you want to inject additional values/classes into the DI system):
Now you're ready to test out your plugin!
It is easy to test your plugin on a test project by loading it via the plugins section.
For example, when your test project resides next to your plugin implementation:
Note: Be sure you have compiled your TypeScript correctly.
You can test it out with Stryker:
Test runner and checker plugins are actually created in its own child process. Therefore you cannot debug them directly. Instead you can use the
testRunnerNodeArgs: ['--inspect'] to debug your test runner plugin (an equivalent for the checker plugin isn't created yet, please let us know if you need it).
After you've verified that your plugin loads correctly, it is recommended to create your own integration tests and not rely on Stryker to test it out each time. This will allow you to develop your plugin faster.
See this example below.
In this example, you can see that some tokens are loaded from
commonTokens and some are loaded from
commonTokens: These contain the tokens belonging to values Stryker itself provide.
pluginTokens: These are an example of tokens you can provide yourself in your plugin. The
fooTestRunnerFactoryfactory method is an example of where the tokens are provided.
This is type-safe. When you declare your plugin, TypedInject will validate that you don't inject something that cannot be resolved at runtime.
If you have a plugin that you think other users might be able to benefit from, or you simply need some help, please let us know on Slack.
We're always looking to promote user-created plugins 💗