0
# Reporting
1
2
Jasmine to Jest test result reporting system that converts Jasmine's test results into Jest's standardized format.
3
4
## Capabilities
5
6
### JasmineReporter Class
7
8
Main reporter class that implements the Jasmine Reporter interface and converts results to Jest format.
9
10
```typescript { .api }
11
/**
12
* Jasmine to Jest test result reporter
13
* Implements Jasmine's Reporter interface and converts results to Jest format
14
*/
15
class JasmineReporter implements Reporter {
16
/**
17
* Creates a new Jasmine reporter instance
18
* @param globalConfig - Jest global configuration
19
* @param config - Jest project configuration
20
* @param testPath - Path to the test file being executed
21
*/
22
constructor(
23
globalConfig: Config.GlobalConfig,
24
config: Config.ProjectConfig,
25
testPath: string,
26
);
27
28
/**
29
* Called when Jasmine starts running tests
30
* @param runDetails - Details about the test run
31
*/
32
jasmineStarted(runDetails: RunDetails): void;
33
34
/**
35
* Called when an individual test starts
36
* @param spec - The test specification that started
37
*/
38
specStarted(spec: SpecResult): void;
39
40
/**
41
* Called when an individual test completes
42
* @param result - The completed test result
43
*/
44
specDone(result: SpecResult): void;
45
46
/**
47
* Called when a test suite starts
48
* @param suite - The test suite that started
49
*/
50
suiteStarted(suite: SuiteResult): void;
51
52
/**
53
* Called when a test suite completes
54
* @param _result - The completed suite result (unused)
55
*/
56
suiteDone(_result: SuiteResult): void;
57
58
/**
59
* Called when all tests complete
60
* @param _runDetails - Details about the completed test run
61
*/
62
jasmineDone(_runDetails: RunDetails): void;
63
64
/**
65
* Gets the final test results in Jest format
66
* @returns Promise resolving to Jest TestResult
67
*/
68
getResults(): Promise<TestResult>;
69
}
70
```
71
72
### Reporter Interface
73
74
The standard Jasmine Reporter interface that defines the lifecycle hooks.
75
76
```typescript { .api }
77
/**
78
* Standard Jasmine Reporter interface for test lifecycle events
79
*/
80
interface Reporter {
81
/** Called when all tests complete */
82
jasmineDone(runDetails: RunDetails): void;
83
/** Called when Jasmine starts running tests */
84
jasmineStarted(runDetails: RunDetails): void;
85
/** Called when an individual test completes */
86
specDone(result: SpecResult): void;
87
/** Called when an individual test starts */
88
specStarted(spec: SpecResult): void;
89
/** Called when a test suite completes */
90
suiteDone(result: SuiteResult): void;
91
/** Called when a test suite starts */
92
suiteStarted(result: SuiteResult): void;
93
}
94
```
95
96
### Run Details
97
98
Information about test run execution provided to reporter lifecycle methods.
99
100
```typescript { .api }
101
/**
102
* Details about test run execution
103
*/
104
interface RunDetails {
105
/** Total number of specs defined in the test run */
106
totalSpecsDefined?: number;
107
/** Failed expectations from suite-level failures */
108
failedExpectations?: SuiteResult['failedExpectations'];
109
}
110
```
111
112
### Spec Result
113
114
Individual test result information from Jasmine.
115
116
```typescript { .api }
117
/**
118
* Result information for an individual test specification
119
*/
120
interface SpecResult {
121
/** Unique identifier for the spec */
122
id: string;
123
/** Test description/name */
124
description: string;
125
/** Full test name including suite hierarchy */
126
fullName: string;
127
/** Test execution status */
128
status: 'passed' | 'failed' | 'pending' | 'disabled' | 'todo';
129
/** Array of failed expectations with error details */
130
failedExpectations: Array<{
131
/** Actual value in failed assertion */
132
actual: string;
133
/** Expected value in failed assertion */
134
expected: string;
135
/** Matcher name that failed */
136
matcherName: string;
137
/** Error message */
138
message: string;
139
/** Whether the expectation passed */
140
passed: boolean;
141
/** Stack trace */
142
stack: string;
143
}>;
144
/** Call site information for test location */
145
__callsite?: NodeJS.CallSite;
146
}
147
```
148
149
### Suite Result
150
151
Test suite result information from Jasmine.
152
153
```typescript { .api }
154
/**
155
* Result information for a test suite
156
*/
157
interface SuiteResult {
158
/** Unique identifier for the suite */
159
id: string;
160
/** Suite description/name */
161
description: string;
162
/** Full suite name including parent hierarchy */
163
fullName: string;
164
/** Suite execution status */
165
status: 'finished' | 'disabled';
166
/** Array of failed expectations at suite level */
167
failedExpectations: Array<{
168
actual: string;
169
expected: string;
170
matcherName: string;
171
message: string;
172
passed: boolean;
173
stack: string;
174
}>;
175
}
176
```
177
178
## Result Conversion Process
179
180
The reporter handles conversion from Jasmine's result format to Jest's TestResult:
181
182
### Status Mapping
183
184
- `passed` → `passed`
185
- `failed` → `failed`
186
- `pending`/`disabled` → `pending`
187
- `todo` → `todo`
188
189
### Error Processing
190
191
- Extracts failure messages and stack traces
192
- Handles missing error messages in stack traces
193
- Preserves failure details for Jest's error reporting
194
195
### Timing Information
196
197
- Tracks test start times
198
- Calculates test duration
199
- Excludes timing for pending/skipped tests
200
201
### Location Information
202
203
- Preserves test location from call sites
204
- Includes line and column numbers when available
205
206
**Usage Example:**
207
208
```typescript
209
import JasmineReporter from "jest-jasmine2/build/reporter";
210
211
// Create reporter instance
212
const reporter = new JasmineReporter(
213
globalConfig,
214
projectConfig,
215
"/path/to/test.spec.js"
216
);
217
218
// Add to Jasmine environment
219
env.addReporter(reporter);
220
221
// After tests complete, get Jest-formatted results
222
const testResult = await reporter.getResults();
223
console.log(`${testResult.numPassingTests} tests passed`);
224
```