What is @stryker-mutator/api?
@stryker-mutator/api is a part of the Stryker Mutator framework, which is used for mutation testing in JavaScript and TypeScript projects. It provides a set of APIs that allow developers to integrate and extend the mutation testing capabilities of Stryker.
What are @stryker-mutator/api's main functionalities?
Mutator API
The Mutator API allows developers to create custom mutators that define how code should be mutated during testing. This is useful for extending the mutation testing capabilities to cover more specific or custom scenarios.
const { Mutator } = require('@stryker-mutator/api/mutant');
class MyMutator extends Mutator {
mutate(node) {
// Custom mutation logic
}
}
Reporter API
The Reporter API provides a way to create custom reporters that can handle and display the results of mutation testing. This allows for customized reporting formats and integration with other tools.
const { Reporter } = require('@stryker-mutator/api/report');
class MyReporter extends Reporter {
onMutantTested(result) {
console.log(`Mutant ${result.id} tested with status ${result.status}`);
}
}
Test Framework API
The Test Framework API allows developers to integrate custom test frameworks with Stryker. This is useful for supporting additional testing frameworks that are not natively supported by Stryker.
const { TestFramework } = require('@stryker-mutator/api/test_framework');
class MyTestFramework extends TestFramework {
constructor() {
super();
// Custom test framework initialization
}
}
Other packages similar to @stryker-mutator/api
jest
Jest is a popular JavaScript testing framework with built-in support for snapshot testing, mocking, and more. While it does not focus on mutation testing like Stryker, it provides a comprehensive testing solution that can be used alongside Stryker for a complete testing strategy.
mocha
Mocha is a flexible JavaScript test framework for Node.js programs. It provides a simple and extensible interface for writing tests, but does not include mutation testing capabilities. Mocha can be used with Stryker to perform mutation testing on tests written in Mocha.
karma
Karma is a test runner that allows you to execute JavaScript code in multiple real browsers. It is often used in conjunction with other testing frameworks like Jasmine or Mocha. While Karma itself does not provide mutation testing, it can be integrated with Stryker to run mutation tests in a browser environment.
StrykerJS API
This is the repository for maintaining the API of the StrykerJS mutation testing framework.
Plugin creators should depend on this API rather than on the main Stryker repository directly.
Extension use cases
You can extend Stryker in a number of ways.
- Create your own
Mutator
- Create a custom
Reporter
- Create a
TestFramework
for a test framework - Create a
TestRunner
to bridge the gap between your test runner and Stryker - Create a custom way of configuring Stryker by creating an
OptionsEditor
All extension points work in the same basic way.
- Create a
constructor function
(or class
) - Register the
constructor function
to the correct Factory
.
For more info, please take a look at the Stryker handbook.