0
# Plugin Integration
1
2
Core plugin registration and validation schema for Stryker integration. Provides the main entry point for using Jest as a test runner in Stryker mutation testing.
3
4
## Capabilities
5
6
### Stryker Plugin Declaration
7
8
The main plugin export that registers Jest as a test runner with Stryker's plugin system.
9
10
```typescript { .api }
11
/**
12
* Array of Stryker plugin declarations for Jest test runner
13
* Contains the Jest test runner factory plugin registration
14
*/
15
export const strykerPlugins: Array<PluginDeclaration>;
16
```
17
18
**Usage Example:**
19
20
```typescript
21
import { strykerPlugins } from "@stryker-mutator/jest-runner";
22
23
// Plugins are automatically registered when the package is loaded
24
// Used internally by Stryker to discover and load the Jest test runner
25
console.log(strykerPlugins); // [{ kind: 'TestRunner', name: 'jest', factory: ... }]
26
```
27
28
### Validation Schema
29
30
JSON schema for validating Jest runner configuration options.
31
32
```typescript { .api }
33
/**
34
* Validation schema for Jest runner options
35
* Loaded from schema/jest-runner-options.json
36
*/
37
export const strykerValidationSchema: JestRunnerOptionsSchema;
38
```
39
40
**Usage Example:**
41
42
```typescript
43
import { strykerValidationSchema } from "@stryker-mutator/jest-runner";
44
45
// Schema is used internally by Stryker for configuration validation
46
// Contains validation rules for jest configuration options
47
console.log(strykerValidationSchema.properties.jest);
48
```
49
50
## Types
51
52
### Plugin Declaration Types
53
54
```typescript { .api }
55
interface PluginDeclaration {
56
kind: PluginKind.TestRunner;
57
name: 'jest';
58
factory: typeof jestTestRunnerFactory;
59
}
60
61
enum PluginKind {
62
TestRunner = 'TestRunner',
63
// ... other plugin types
64
}
65
```
66
67
### Schema Types
68
69
```typescript { .api }
70
interface JestRunnerOptionsSchema {
71
$schema: string;
72
type: 'object';
73
title: 'JestRunnerOptions';
74
additionalItems: boolean;
75
properties: {
76
jest: JestOptionsSchema;
77
};
78
definitions: {
79
jestProjectType: JestProjectTypeSchema;
80
};
81
}
82
83
interface JestOptionsSchema {
84
title: 'JestOptions';
85
description: string;
86
type: 'object';
87
default: {};
88
properties: {
89
projectType: { $ref: '#/definitions/jestProjectType' };
90
configFile: { description: string; type: 'string' };
91
config: { description: string; type: 'object' };
92
enableFindRelatedTests: { description: string; type: 'boolean'; default: true };
93
};
94
additionalProperties: boolean;
95
}
96
```
97
98
## Environment Setup
99
100
The plugin automatically sets up the testing environment:
101
102
```typescript
103
// Automatically set when the package is loaded
104
process.env.BABEL_ENV = 'test';
105
```
106
107
This ensures that Babel transformations are applied correctly for Jest testing within the Stryker environment.
108
109
## Integration with Stryker Core
110
111
The plugin integrates with Stryker through the dependency injection system:
112
113
- **Plugin Discovery**: Stryker discovers Jest runner through `strykerPlugins` export
114
- **Factory Creation**: Uses `jestTestRunnerFactory` to create test runner instances
115
- **Validation**: Applies `strykerValidationSchema` to validate Jest configuration
116
- **Lifecycle Management**: Handles initialization, execution, and cleanup through the TestRunner interface