Skip to content

Commit 26bb6c9

Browse files
committed
Added a onfig option to disable listing pending specs when there are failures
This can make failure output easier to read when there are also a number of pending specs. To use this feature, add `alwaysListPendingSpecs: false` to the config file or call `.alwaysListPendingSpecs(false)` on the `Jasmine` instance.
1 parent 86c3d6f commit 26bb6c9

File tree

5 files changed

+166
-24
lines changed

5 files changed

+166
-24
lines changed

lib/jasmine.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Jasmine {
6666
this.reportersCount = 0;
6767
this.exit = process.exit;
6868
this.showingColors = true;
69+
this.alwaysListPendingSpecs_ = true;
6970
this.reporter = new module.exports.ConsoleReporter();
7071
this.addReporter(this.reporter);
7172
this.defaultReporterConfigured = false;
@@ -119,6 +120,16 @@ class Jasmine {
119120
this.showingColors = value;
120121
}
121122

123+
/**
124+
* Sets whether the console reporter should list pending specs even when there
125+
* are failures.
126+
* @name Jasmine#alwaysListPendingSpecs
127+
* @param value {boolean}
128+
*/
129+
alwaysListPendingSpecs(value) {
130+
this.alwaysListPendingSpecs_ = value;
131+
}
132+
122133
/**
123134
* Adds a spec file to the list that will be loaded when the suite is executed.
124135
* @function
@@ -295,6 +306,17 @@ class Jasmine {
295306
envConfig.stopOnSpecFailure = config.stopOnSpecFailure;
296307
}
297308

309+
/**
310+
* Whether the default reporter should list pending specs even if there are
311+
* failures.
312+
* @name Configuration#alwaysListPendingSpecs
313+
* @type boolean | undefined
314+
* @default false
315+
*/
316+
if (config.alwaysListPendingSpecs !== undefined) {
317+
this.alwaysListPendingSpecs(config.alwaysListPendingSpecs);
318+
}
319+
298320
/**
299321
* Whether to run specs in a random order.
300322
* @name Configuration#random
@@ -422,7 +444,10 @@ class Jasmine {
422444
await this.loadRequires();
423445
await this.loadHelpers();
424446
if (!this.defaultReporterConfigured) {
425-
this.configureDefaultReporter({ showColors: this.showingColors });
447+
this.configureDefaultReporter({
448+
showColors: this.showingColors,
449+
alwaysListPendingSpecs: this.alwaysListPendingSpecs_
450+
});
426451
}
427452

428453
if (filterString) {

lib/reporters/console_reporter.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function ConsoleReporter() {
1717
failureCount,
1818
failedSpecs = [],
1919
pendingSpecs = [],
20+
alwaysListPendingSpecs = true,
2021
ansi = {
2122
green: '\x1B[32m',
2223
red: '\x1B[31m',
@@ -60,6 +61,16 @@ function ConsoleReporter() {
6061
if (options.randomSeedReproductionCmd) {
6162
this.randomSeedReproductionCmd = options.randomSeedReproductionCmd;
6263
}
64+
65+
/**
66+
* Whether to list pending specs even if there are failures.
67+
* @name ConsoleReporterOptions#alwaysListPendingSpecs
68+
* @type Boolean|undefined
69+
* @default true
70+
*/
71+
if (options.alwaysListPendingSpecs !== undefined) {
72+
alwaysListPendingSpecs = options.alwaysListPendingSpecs;
73+
}
6374
};
6475

6576
this.jasmineStarted = function(options) {
@@ -96,11 +107,13 @@ function ConsoleReporter() {
96107
suiteFailureDetails({ fullName: 'top suite', ...result });
97108
}
98109

99-
if (pendingSpecs.length > 0) {
100-
print("Pending:");
101-
}
102-
for (let i = 0; i < pendingSpecs.length; i++) {
103-
pendingSpecDetails(pendingSpecs[i], i + 1);
110+
if (alwaysListPendingSpecs || result.overallStatus === 'passed') {
111+
if (pendingSpecs.length > 0) {
112+
print("Pending:");
113+
}
114+
for (let i = 0; i < pendingSpecs.length; i++) {
115+
pendingSpecDetails(pendingSpecs[i], i + 1);
116+
}
104117
}
105118

106119
if(specCount > 0) {

spec/jasmine_spec.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,22 @@ describe('Jasmine', function() {
369369
expect(this.loader.alwaysImport).toBeTrue();
370370
});
371371
});
372+
373+
it('sets alwaysListPendingSpecs when present', function() {
374+
this.configObject.alwaysListPendingSpecs = false;
375+
376+
this.fixtureJasmine.loadConfig(this.configObject);
377+
378+
expect(this.fixtureJasmine.alwaysListPendingSpecs_).toBeFalse();
379+
});
380+
381+
it('does not set alwaysListPendingSpecs when absent', function() {
382+
delete this.configObject.alwaysListPendingSpecs;
383+
384+
this.fixtureJasmine.loadConfig(this.configObject);
385+
386+
expect(this.fixtureJasmine.alwaysListPendingSpecs_).toBeTrue();
387+
});
372388
});
373389

374390
describe('from a file', function() {
@@ -488,19 +504,26 @@ describe('Jasmine', function() {
488504

489505
await this.execute();
490506

491-
expect(this.testJasmine.configureDefaultReporter).toHaveBeenCalledWith({showColors: true});
507+
expect(this.testJasmine.configureDefaultReporter).toHaveBeenCalledWith({
508+
showColors: true,
509+
alwaysListPendingSpecs: true
510+
});
492511
expect(this.testJasmine.loadSpecs).toHaveBeenCalled();
493512
expect(this.testJasmine.env.execute).toHaveBeenCalled();
494513
});
495514

496-
it('configures the default console reporter with the right color settings', async function() {
515+
it('configures the default console reporter with the right settings', async function() {
497516
spyOn(this.testJasmine, 'configureDefaultReporter');
498517
spyOn(this.testJasmine, 'loadSpecs');
499518
this.testJasmine.showColors(false);
519+
this.testJasmine.alwaysListPendingSpecs(false);
500520

501521
await this.execute();
502522

503-
expect(this.testJasmine.configureDefaultReporter).toHaveBeenCalledWith({showColors: false});
523+
expect(this.testJasmine.configureDefaultReporter).toHaveBeenCalledWith({
524+
showColors: false,
525+
alwaysListPendingSpecs: false
526+
});
504527
expect(this.testJasmine.loadSpecs).toHaveBeenCalled();
505528
expect(this.testJasmine.env.execute).toHaveBeenCalled();
506529
});

spec/reporters/console_reporter_spec.js

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -415,27 +415,107 @@ describe("ConsoleReporter", function() {
415415
expect(this.out.getOutput()).toMatch(stackLine);
416416
});
417417

418-
it("reports a summary when done that includes which specs are pending and their reasons", function() {
419-
const reporter = new ConsoleReporter();
420-
reporter.setOptions({
421-
print: this.out.print,
418+
describe('When the overall status is passed', function() {
419+
it('includes pending specs in the summary even if alwaysListPendingSpecs is false', function() {
420+
const reporter = new ConsoleReporter();
421+
reporter.setOptions({
422+
print: this.out.print,
423+
alwaysListPendingSpecs: false
424+
});
425+
426+
reporter.jasmineStarted();
427+
428+
reporter.specDone({
429+
status: "pending",
430+
description: "with a pending spec",
431+
fullName: "A suite with a pending spec",
432+
pendingReason: "It's not ready yet!"
433+
});
434+
435+
this.out.clear();
436+
437+
reporter.jasmineDone({overallStatus: 'passed'});
438+
439+
expect(this.out.getOutput()).toContain("Pending:");
440+
expect(this.out.getOutput()).toContain("A suite with a pending spec");
441+
expect(this.out.getOutput()).toContain("It's not ready yet!");
422442
});
443+
});
423444

424-
reporter.jasmineStarted();
445+
describe('When the overall status is failed', function() {
446+
it('includes pending specs in the summary when alwaysListPendingSpecs is true', function() {
447+
const reporter = new ConsoleReporter();
448+
reporter.setOptions({
449+
print: this.out.print,
450+
alwaysListPendingSpecs: true
451+
});
425452

426-
reporter.specDone({
427-
status: "pending",
428-
description: "with a pending spec",
429-
fullName: "A suite with a pending spec",
430-
pendingReason: "It's not ready yet!"
453+
reporter.jasmineStarted();
454+
455+
reporter.specDone({
456+
status: "pending",
457+
description: "with a pending spec",
458+
fullName: "A suite with a pending spec",
459+
pendingReason: "It's not ready yet!"
460+
});
461+
462+
this.out.clear();
463+
464+
reporter.jasmineDone({overallStatus: 'failed'});
465+
466+
expect(this.out.getOutput()).toContain("Pending:");
467+
expect(this.out.getOutput()).toContain("A suite with a pending spec");
468+
expect(this.out.getOutput()).toContain("It's not ready yet!");
431469
});
432470

433-
this.out.clear();
471+
it('omits pending specs in the summary when alwaysListPendingSpecs is false', function() {
472+
const reporter = new ConsoleReporter();
473+
reporter.setOptions({
474+
print: this.out.print,
475+
alwaysListPendingSpecs: false
476+
});
434477

435-
reporter.jasmineDone({});
478+
reporter.jasmineStarted();
479+
480+
reporter.specDone({
481+
status: "pending",
482+
description: "with a pending spec",
483+
fullName: "A suite with a pending spec",
484+
pendingReason: "It's not ready yet!"
485+
});
486+
487+
this.out.clear();
488+
489+
reporter.jasmineDone({overallStatus: 'failed'});
490+
491+
expect(this.out.getOutput()).not.toContain("Pending:");
492+
expect(this.out.getOutput()).not.toContain("A suite with a pending spec");
493+
expect(this.out.getOutput()).not.toContain("It's not ready yet!");
494+
});
436495

437-
expect(this.out.getOutput()).toContain("A suite with a pending spec");
438-
expect(this.out.getOutput()).toContain("It's not ready yet!");
496+
it('includes pending specs in the summary when alwaysListPendingSpecs is unspecified', function() {
497+
const reporter = new ConsoleReporter();
498+
reporter.setOptions({
499+
print: this.out.print,
500+
});
501+
502+
reporter.jasmineStarted();
503+
504+
reporter.specDone({
505+
status: "pending",
506+
description: "with a pending spec",
507+
fullName: "A suite with a pending spec",
508+
pendingReason: "It's not ready yet!"
509+
});
510+
511+
this.out.clear();
512+
513+
reporter.jasmineDone({overallStatus: 'failed'});
514+
515+
expect(this.out.getOutput()).toContain("Pending:");
516+
expect(this.out.getOutput()).toContain("A suite with a pending spec");
517+
expect(this.out.getOutput()).toContain("It's not ready yet!");
518+
});
439519
});
440520

441521
it("reports a summary when done that includes the reason for an incomplete suite", function() {

spec/support/jasmine.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"helpers": [
99
"helpers/**/*.js"
1010
],
11-
"random": true
11+
"random": true,
12+
"alwaysListPendingSpecs": false
1213
}

0 commit comments

Comments
 (0)