0
# Reporters and Output
1
2
Multiple reporter formats and output options for different environments including terminal output, CI integration, XML reports, and desktop notifications.
3
4
## Capabilities
5
6
### Terminal Reporter
7
8
Basic terminal output reporter with pass/fail indicators and summary information.
9
10
```javascript { .api }
11
/**
12
* Basic terminal reporter with colored output and failure details
13
* @param config - Reporter configuration object
14
*/
15
class TerminalReporter {
16
constructor(config: ReporterConfig);
17
reportRunnerStarting(runner: jasmine.Runner): void;
18
reportRunnerResults(runner: jasmine.Runner): void;
19
reportSuiteResults(suite: jasmine.Suite): void;
20
reportSpecResults(spec: jasmine.Spec): void;
21
}
22
23
interface ReporterConfig {
24
/** Function for output printing (defaults to process.stdout.write) */
25
print?: (str: string) => void;
26
/** Enable colored output (green/red for pass/fail) */
27
color?: boolean;
28
/** Callback function when test run completes */
29
onComplete?: (passed: boolean) => void;
30
/** Include stack traces in failure output */
31
includeStackTrace?: boolean;
32
/** Function to filter stack trace lines */
33
stackFilter?: (trace: string) => string;
34
}
35
```
36
37
**Usage Examples:**
38
39
```javascript
40
const jasmine = require("jasmine-node");
41
42
// Basic terminal reporter
43
const reporter = new jasmine.TerminalReporter({
44
color: true,
45
includeStackTrace: true
46
});
47
48
jasmine.getEnv().addReporter(reporter);
49
50
// Custom print function
51
const reporter2 = new jasmine.TerminalReporter({
52
print: function(str) {
53
console.log("[TEST] " + str);
54
},
55
color: false
56
});
57
58
// With completion callback
59
const reporter3 = new jasmine.TerminalReporter({
60
color: true,
61
onComplete: function(passed) {
62
if (passed) {
63
console.log("All tests passed!");
64
process.exit(0);
65
} else {
66
console.log("Some tests failed!");
67
process.exit(1);
68
}
69
}
70
});
71
```
72
73
### Verbose Terminal Reporter
74
75
Extended terminal reporter with detailed progress information and timing data.
76
77
```javascript { .api }
78
/**
79
* Verbose terminal reporter with detailed test progress and timing
80
* @param config - Reporter configuration object
81
*/
82
class TerminalVerboseReporter {
83
constructor(config: VerboseReporterConfig);
84
reportRunnerStarting(runner: jasmine.Runner): void;
85
reportRunnerResults(runner: jasmine.Runner): void;
86
reportSuiteResults(suite: jasmine.Suite): void;
87
reportSpecStarting(spec: jasmine.Spec): void;
88
reportSpecResults(spec: jasmine.Spec): void;
89
}
90
91
interface VerboseReporterConfig extends ReporterConfig {
92
/** Additional configuration for verbose reporter (extends basic ReporterConfig) */
93
}
94
```
95
96
**Usage Examples:**
97
98
```javascript
99
const jasmine = require("jasmine-node");
100
101
// Verbose reporter with color support
102
const verboseReporter = new jasmine.TerminalVerboseReporter({
103
color: true,
104
onComplete: function(passed) {
105
console.log("Verbose test run completed: " + (passed ? "PASSED" : "FAILED"));
106
}
107
});
108
109
jasmine.getEnv().addReporter(verboseReporter);
110
111
// Custom stack filtering
112
const verboseReporter2 = new jasmine.TerminalVerboseReporter({
113
color: true,
114
stackFilter: function(trace) {
115
// Remove node_modules lines from stack trace
116
return trace.split('\n')
117
.filter(line => !line.includes('node_modules'))
118
.join('\n');
119
}
120
});
121
```
122
123
### TeamCity Reporter
124
125
Specialized reporter for JetBrains TeamCity continuous integration platform.
126
127
```javascript { .api }
128
/**
129
* TeamCity-compatible reporter with service messages
130
* @param config - TeamCity reporter configuration
131
*/
132
class TeamcityReporter {
133
constructor(config: TeamcityReporterConfig);
134
reportRunnerStarting(runner: jasmine.Runner): void;
135
reportRunnerResults(runner: jasmine.Runner): void;
136
reportSuiteStarting(suite: jasmine.Suite): void;
137
reportSuiteResults(suite: jasmine.Suite): void;
138
reportSpecStarting(spec: jasmine.Spec): void;
139
reportSpecResults(spec: jasmine.Spec): void;
140
}
141
142
interface TeamcityReporterConfig {
143
/** Callback function when test run completes */
144
onComplete?: (passed: boolean) => void;
145
/** Custom print function for service messages */
146
print?: (str: string) => void;
147
}
148
```
149
150
**Usage Examples:**
151
152
```javascript
153
const jasmine = require("jasmine-node");
154
155
// Basic TeamCity reporter
156
const teamcityReporter = new jasmine.TeamcityReporter({
157
onComplete: function(passed) {
158
process.exit(passed ? 0 : 1);
159
}
160
});
161
162
jasmine.getEnv().addReporter(teamcityReporter);
163
164
// TeamCity with custom output
165
const teamcityReporter2 = new jasmine.TeamcityReporter({
166
print: function(message) {
167
// Log to file or custom output stream
168
fs.appendFileSync('teamcity-output.log', message + '\n');
169
}
170
});
171
```
172
173
### JUnit XML Reporter
174
175
Generate JUnit-compatible XML reports for CI/CD integration and test result archiving.
176
177
```javascript { .api }
178
/**
179
* JUnit XML reporter for CI/CD integration
180
* @param savePath - Directory to save XML reports
181
* @param consolidate - Combine all results into single XML file
182
* @param useDotNotation - Use dot notation for nested describe blocks
183
*/
184
class JUnitXmlReporter {
185
constructor(savePath: string, consolidate?: boolean, useDotNotation?: boolean);
186
reportRunnerStarting(runner: jasmine.Runner): void;
187
reportRunnerResults(runner: jasmine.Runner): void;
188
reportSuiteResults(suite: jasmine.Suite): void;
189
reportSpecResults(spec: jasmine.Spec): void;
190
}
191
```
192
193
**Usage Examples:**
194
195
```javascript
196
const jasmine = require("jasmine-node");
197
198
// Basic JUnit XML reporter
199
const junitReporter = new jasmine.JUnitXmlReporter('./reports/');
200
jasmine.getEnv().addReporter(junitReporter);
201
202
// Consolidated single XML file
203
const junitReporter2 = new jasmine.JUnitXmlReporter(
204
'./reports/',
205
true, // consolidate into single file
206
true // use dot notation for test names
207
);
208
209
// Multiple reporters combination
210
jasmine.getEnv().addReporter(new jasmine.TerminalReporter({ color: true }));
211
jasmine.getEnv().addReporter(junitReporter2);
212
```
213
214
### Growl Reporter
215
216
Desktop notification reporter using Growl for test result summaries.
217
218
```javascript { .api }
219
/**
220
* Growl notification reporter for desktop alerts
221
* Requires Growl to be installed on the system
222
*/
223
class GrowlReporter {
224
constructor();
225
reportRunnerResults(runner: jasmine.Runner): void;
226
}
227
```
228
229
**Usage Examples:**
230
231
```javascript
232
const jasmine = require("jasmine-node");
233
234
// Basic Growl notifications
235
const growlReporter = new jasmine.GrowlReporter();
236
jasmine.getEnv().addReporter(growlReporter);
237
238
// Combined with terminal output
239
jasmine.getEnv().addReporter(new jasmine.TerminalReporter({ color: true }));
240
jasmine.getEnv().addReporter(growlReporter);
241
```
242
243
### Custom Reporter Implementation
244
245
Create custom reporters by implementing the reporter interface.
246
247
```javascript { .api }
248
/**
249
* Custom reporter interface - implement any or all methods
250
*/
251
interface CustomReporter {
252
/** Called when test runner starts */
253
reportRunnerStarting?(runner: jasmine.Runner): void;
254
/** Called when test runner completes */
255
reportRunnerResults?(runner: jasmine.Runner): void;
256
/** Called when a test suite starts */
257
reportSuiteStarting?(suite: jasmine.Suite): void;
258
/** Called when a test suite completes */
259
reportSuiteResults?(suite: jasmine.Suite): void;
260
/** Called when a test spec starts */
261
reportSpecStarting?(spec: jasmine.Spec): void;
262
/** Called when a test spec completes */
263
reportSpecResults?(spec: jasmine.Spec): void;
264
/** Called for general log messages */
265
log?(str: string): void;
266
}
267
268
// Jasmine runner and suite objects
269
interface jasmine.Runner {
270
topLevelSuites(): jasmine.Suite[];
271
results(): jasmine.NestedResults;
272
specs(): jasmine.Spec[];
273
}
274
275
interface jasmine.Suite {
276
id: number;
277
description: string;
278
parentSuite: jasmine.Suite | null;
279
children(): (jasmine.Suite | jasmine.Spec)[];
280
results(): jasmine.NestedResults;
281
}
282
283
interface jasmine.Spec {
284
id: number;
285
description: string;
286
suite: jasmine.Suite;
287
results(): jasmine.NestedResults;
288
}
289
290
interface jasmine.NestedResults {
291
passed(): boolean;
292
totalCount: number;
293
passedCount: number;
294
failedCount: number;
295
skippedCount: number;
296
getItems(): jasmine.Result[];
297
}
298
```
299
300
**Usage Examples:**
301
302
```javascript
303
// Custom JSON reporter
304
const JsonReporter = function() {
305
let testResults = [];
306
307
this.reportSpecResults = function(spec) {
308
const result = {
309
id: spec.id,
310
description: spec.description,
311
suite: spec.suite.description,
312
passed: spec.results().passed(),
313
runtime: spec.results().runtime || 0
314
};
315
testResults.push(result);
316
};
317
318
this.reportRunnerResults = function(runner) {
319
const summary = {
320
total: runner.results().totalCount,
321
passed: runner.results().passedCount,
322
failed: runner.results().failedCount,
323
results: testResults
324
};
325
326
require('fs').writeFileSync(
327
'./test-results.json',
328
JSON.stringify(summary, null, 2)
329
);
330
};
331
};
332
333
jasmine.getEnv().addReporter(new JsonReporter());
334
335
// Custom console reporter with emojis
336
const EmojiReporter = function() {
337
this.reportSpecResults = function(spec) {
338
const emoji = spec.results().passed() ? 'β ' : 'β';
339
console.log(`${emoji} ${spec.description}`);
340
};
341
342
this.reportRunnerResults = function(runner) {
343
const results = runner.results();
344
console.log(`\nπ― Total: ${results.totalCount}`);
345
console.log(`β Passed: ${results.passedCount}`);
346
console.log(`β Failed: ${results.failedCount}`);
347
};
348
};
349
350
jasmine.getEnv().addReporter(new EmojiReporter());
351
352
// Database logging reporter
353
const DatabaseReporter = function(database) {
354
this.reportRunnerResults = function(runner) {
355
const testRun = {
356
timestamp: new Date(),
357
total: runner.results().totalCount,
358
passed: runner.results().passedCount,
359
failed: runner.results().failedCount,
360
duration: Date.now() - this.startTime
361
};
362
363
database.saveTestRun(testRun);
364
};
365
366
this.reportRunnerStarting = function(runner) {
367
this.startTime = Date.now();
368
};
369
};
370
371
const db = require('./test-database');
372
jasmine.getEnv().addReporter(new DatabaseReporter(db));
373
```
374
375
## Reporter Color Configuration
376
377
```javascript { .api }
378
// ANSI color codes used by reporters
379
interface ANSIColors {
380
pass(): string; // Green - '\033[32m'
381
fail(): string; // Red - '\033[31m'
382
specTiming(): string; // Blue - '\033[34m'
383
suiteTiming(): string; // Yellow - '\033[33m'
384
ignore(): string; // Light Gray - '\033[37m'
385
neutral(): string; // Normal - '\033[0m'
386
}
387
388
interface NoColors {
389
pass(): string; // Empty string ''
390
fail(): string; // Empty string ''
391
specTiming(): string; // Empty string ''
392
suiteTiming(): string; // Empty string ''
393
ignore(): string; // Empty string ''
394
neutral(): string; // Empty string ''
395
}
396
```
397
398
## Multi-Reporter Configuration
399
400
```javascript
401
const jasmine = require("jasmine-node");
402
403
// Configure multiple reporters for comprehensive output
404
const env = jasmine.getEnv();
405
406
// Terminal output for development
407
env.addReporter(new jasmine.TerminalVerboseReporter({
408
color: true,
409
showTiming: true
410
}));
411
412
// JUnit XML for CI/CD
413
env.addReporter(new jasmine.JUnitXmlReporter('./reports/', true, true));
414
415
// Growl notifications for desktop alerts
416
env.addReporter(new jasmine.GrowlReporter());
417
418
// Custom completion handler
419
env.addReporter({
420
reportRunnerResults: function(runner) {
421
const passed = runner.results().passed();
422
console.log(`\nπ― Test run ${passed ? 'PASSED' : 'FAILED'}`);
423
process.exit(passed ? 0 : 1);
424
}
425
});
426
```