|
3 | 3 | var fs = require('fs');
|
4 | 4 | var mkdirp = require('mkdirp');
|
5 | 5 | var path = require('path');
|
| 6 | +var assert = require('assert'); |
6 | 7 | var reporters = require('../../').reporters;
|
7 | 8 | var XUnit = reporters.XUnit;
|
8 | 9 |
|
@@ -313,4 +314,68 @@ describe('XUnit reporter', function () {
|
313 | 314 | });
|
314 | 315 | });
|
315 | 316 | });
|
| 317 | + |
| 318 | + describe('custom suite name', function () { |
| 319 | + // capture the events that the reporter subscribes to |
| 320 | + var events; |
| 321 | + |
| 322 | + // the runner parameter of the reporter |
| 323 | + var runner; |
| 324 | + |
| 325 | + // capture output lines (will contain the resulting XML of the xunit reporter) |
| 326 | + var lines; |
| 327 | + |
| 328 | + // the file stream into which the xunit reporter will write into |
| 329 | + var fileStream; |
| 330 | + |
| 331 | + beforeEach(function () { |
| 332 | + events = {}; |
| 333 | + |
| 334 | + runner = { |
| 335 | + on: function (eventName, eventHandler) { |
| 336 | + // capture the event handler |
| 337 | + events[eventName] = eventHandler; |
| 338 | + } |
| 339 | + }; |
| 340 | + |
| 341 | + lines = []; |
| 342 | + fileStream = { |
| 343 | + write: function (line) { |
| 344 | + // capture the output lines |
| 345 | + lines.push(line); |
| 346 | + } |
| 347 | + }; |
| 348 | + }); |
| 349 | + |
| 350 | + it('should use "Mocha Tests" as the suite name if no custom name is provided', function () { |
| 351 | + // arrange |
| 352 | + var xunit = new XUnit(runner); |
| 353 | + xunit.fileStream = fileStream; |
| 354 | + |
| 355 | + // act (trigger the end event to force xunit reporter to write the output) |
| 356 | + events['end'](); |
| 357 | + |
| 358 | + // assert |
| 359 | + assert(lines[0].indexOf('Mocha Tests') >= 0, 'it should contain the text "Mocha Tests"'); |
| 360 | + }); |
| 361 | + |
| 362 | + it('should use the custom suite name as the suite name when provided in the reporter options', function () { |
| 363 | + // arrange |
| 364 | + var options = { |
| 365 | + reporterOptions: { |
| 366 | + // this time, with a custom suite name |
| 367 | + suiteName: 'Mocha Is Great!' |
| 368 | + } |
| 369 | + }; |
| 370 | + |
| 371 | + var xunit = new XUnit(runner, options); |
| 372 | + xunit.fileStream = fileStream; |
| 373 | + |
| 374 | + // act (trigger the end event to force xunit reporter to write the output) |
| 375 | + events['end'](); |
| 376 | + |
| 377 | + // assert |
| 378 | + assert(lines[0].indexOf('<testsuite name="Mocha Is Great!"') === 0, '"' + lines[0] + '" should contain the text "Mocha Is Great"'); |
| 379 | + }); |
| 380 | + }); |
316 | 381 | });
|
0 commit comments