0
# Test Runner
1
2
The main test runner function that executes Jasmine tests within Jest's environment, handling configuration, setup, and result reporting.
3
4
## Capabilities
5
6
### Main Test Runner Function
7
8
The primary export that orchestrates test execution by integrating Jest configuration with Jasmine's test framework.
9
10
```typescript { .api }
11
/**
12
* Main test runner function that executes Jasmine tests within Jest environment
13
* @param globalConfig - Jest global configuration
14
* @param config - Jest project-specific configuration
15
* @param environment - Jest test environment (jsdom, node, etc.)
16
* @param runtime - Jest runtime instance for module resolution and execution
17
* @param testPath - Absolute path to the test file being executed
18
* @returns Promise resolving to Jest TestResult
19
*/
20
function jasmine2(
21
globalConfig: Config.GlobalConfig,
22
config: Config.ProjectConfig,
23
environment: JestEnvironment,
24
runtime: Runtime,
25
testPath: string,
26
): Promise<TestResult>;
27
```
28
29
**Usage Example:**
30
31
```typescript
32
import jasmine2 from "jest-jasmine2";
33
34
// Typically called by Jest's test runner infrastructure
35
const testResult = await jasmine2(
36
globalConfig,
37
projectConfig,
38
testEnvironment,
39
jestRuntime,
40
"/path/to/test.spec.js"
41
);
42
43
console.log(`Tests: ${testResult.numPassingTests} passed, ${testResult.numFailingTests} failed`);
44
```
45
46
### Test Result Integration
47
48
The function returns Jest's standardized TestResult format with complete test execution information.
49
50
```typescript { .api }
51
interface TestResult {
52
console?: ConsoleBuffer;
53
coverage?: CoverageMapData;
54
displayName?: Config.DisplayName;
55
failureMessage?: string | null;
56
leaks: boolean;
57
memoryUsage?: Bytes;
58
numFailingTests: number;
59
numPassingTests: number;
60
numPendingTests: number;
61
numTodoTests: number;
62
openHandles: Array<Error>;
63
perfStats: {
64
end: Milliseconds;
65
runtime: Milliseconds;
66
slow: boolean;
67
start: Milliseconds;
68
};
69
skipped: boolean;
70
snapshot: {
71
added: number;
72
fileDeleted: boolean;
73
matched: number;
74
unchecked: number;
75
uncheckedKeys: Array<string>;
76
unmatched: number;
77
updated: number;
78
};
79
sourceMaps: {[sourcePath: string]: string};
80
testExecError?: SerializableError;
81
testFilePath: string;
82
testResults: Array<AssertionResult>;
83
}
84
```
85
86
## Test Execution Flow
87
88
The test runner follows this execution sequence:
89
90
1. **Environment Setup**: Creates Jasmine reporter and factory instances
91
2. **Global Installation**: Installs BDD interface (describe, it, etc.) into test environment
92
3. **Jest Integration**: Sets up Jest-specific features (expect, snapshots, mocks)
93
4. **Async Support**: Installs Promise/async support for test functions
94
5. **Test File Loading**: Loads and executes the test file
95
6. **Test Execution**: Runs all registered tests through Jasmine
96
7. **Result Collection**: Gathers results and converts to Jest format
97
8. **Snapshot Processing**: Handles snapshot state and cleanup
98
99
## Configuration Integration
100
101
The test runner integrates with Jest's configuration system:
102
103
### Global Configuration
104
105
- `testTimeout`: Default timeout for test functions
106
- `maxConcurrency`: Maximum concurrent tests for `it.concurrent`
107
- `expand`: Expand diff output in test results
108
- `testNamePattern`: Filter tests by name pattern
109
- `errorOnDeprecated`: Throw errors on deprecated Jasmine APIs
110
111
### Project Configuration
112
113
- `testLocationInResults`: Include test location in results
114
- `fakeTimers.enableGlobally`: Enable fake timers globally
115
- `fakeTimers.legacyFakeTimers`: Use legacy fake timer implementation
116
- `resetModules`: Reset module registry between tests
117
- `clearMocks`/`resetMocks`/`restoreMocks`: Mock management settings
118
- `setupFilesAfterEnv`: Setup files to run after environment setup
119
- `snapshotSerializers`: Custom snapshot serializers
120
121
**Usage Example:**
122
123
```typescript
124
// Jest configuration affecting jest-jasmine2 behavior
125
module.exports = {
126
testRunner: "jest-jasmine2",
127
testTimeout: 10000,
128
testEnvironment: "node",
129
setupFilesAfterEnv: ["<rootDir>/setup-tests.js"],
130
fakeTimers: {
131
enableGlobally: true,
132
legacyFakeTimers: false
133
}
134
};
135
```