Skip to content

Commit

Permalink
Added a onfig option to disable listing pending specs when there are …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
sgravrock committed Jul 9, 2022
1 parent 86c3d6f commit 26bb6c9
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 24 deletions.
27 changes: 26 additions & 1 deletion lib/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Jasmine {
this.reportersCount = 0;
this.exit = process.exit;
this.showingColors = true;
this.alwaysListPendingSpecs_ = true;
this.reporter = new module.exports.ConsoleReporter();
this.addReporter(this.reporter);
this.defaultReporterConfigured = false;
Expand Down Expand Up @@ -119,6 +120,16 @@ class Jasmine {
this.showingColors = value;
}

/**
* Sets whether the console reporter should list pending specs even when there
* are failures.
* @name Jasmine#alwaysListPendingSpecs
* @param value {boolean}
*/
alwaysListPendingSpecs(value) {
this.alwaysListPendingSpecs_ = value;
}

/**
* Adds a spec file to the list that will be loaded when the suite is executed.
* @function
Expand Down Expand Up @@ -295,6 +306,17 @@ class Jasmine {
envConfig.stopOnSpecFailure = config.stopOnSpecFailure;
}

/**
* Whether the default reporter should list pending specs even if there are
* failures.
* @name Configuration#alwaysListPendingSpecs
* @type boolean | undefined
* @default false
*/
if (config.alwaysListPendingSpecs !== undefined) {
this.alwaysListPendingSpecs(config.alwaysListPendingSpecs);
}

/**
* Whether to run specs in a random order.
* @name Configuration#random
Expand Down Expand Up @@ -422,7 +444,10 @@ class Jasmine {
await this.loadRequires();
await this.loadHelpers();
if (!this.defaultReporterConfigured) {
this.configureDefaultReporter({ showColors: this.showingColors });
this.configureDefaultReporter({
showColors: this.showingColors,
alwaysListPendingSpecs: this.alwaysListPendingSpecs_
});
}

if (filterString) {
Expand Down
23 changes: 18 additions & 5 deletions lib/reporters/console_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function ConsoleReporter() {
failureCount,
failedSpecs = [],
pendingSpecs = [],
alwaysListPendingSpecs = true,
ansi = {
green: '\x1B[32m',
red: '\x1B[31m',
Expand Down Expand Up @@ -60,6 +61,16 @@ function ConsoleReporter() {
if (options.randomSeedReproductionCmd) {
this.randomSeedReproductionCmd = options.randomSeedReproductionCmd;
}

/**
* Whether to list pending specs even if there are failures.
* @name ConsoleReporterOptions#alwaysListPendingSpecs
* @type Boolean|undefined
* @default true
*/
if (options.alwaysListPendingSpecs !== undefined) {
alwaysListPendingSpecs = options.alwaysListPendingSpecs;
}
};

this.jasmineStarted = function(options) {
Expand Down Expand Up @@ -96,11 +107,13 @@ function ConsoleReporter() {
suiteFailureDetails({ fullName: 'top suite', ...result });
}

if (pendingSpecs.length > 0) {
print("Pending:");
}
for (let i = 0; i < pendingSpecs.length; i++) {
pendingSpecDetails(pendingSpecs[i], i + 1);
if (alwaysListPendingSpecs || result.overallStatus === 'passed') {
if (pendingSpecs.length > 0) {
print("Pending:");
}
for (let i = 0; i < pendingSpecs.length; i++) {
pendingSpecDetails(pendingSpecs[i], i + 1);
}
}

if(specCount > 0) {
Expand Down
29 changes: 26 additions & 3 deletions spec/jasmine_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,22 @@ describe('Jasmine', function() {
expect(this.loader.alwaysImport).toBeTrue();
});
});

it('sets alwaysListPendingSpecs when present', function() {
this.configObject.alwaysListPendingSpecs = false;

this.fixtureJasmine.loadConfig(this.configObject);

expect(this.fixtureJasmine.alwaysListPendingSpecs_).toBeFalse();
});

it('does not set alwaysListPendingSpecs when absent', function() {
delete this.configObject.alwaysListPendingSpecs;

this.fixtureJasmine.loadConfig(this.configObject);

expect(this.fixtureJasmine.alwaysListPendingSpecs_).toBeTrue();
});
});

describe('from a file', function() {
Expand Down Expand Up @@ -488,19 +504,26 @@ describe('Jasmine', function() {

await this.execute();

expect(this.testJasmine.configureDefaultReporter).toHaveBeenCalledWith({showColors: true});
expect(this.testJasmine.configureDefaultReporter).toHaveBeenCalledWith({
showColors: true,
alwaysListPendingSpecs: true
});
expect(this.testJasmine.loadSpecs).toHaveBeenCalled();
expect(this.testJasmine.env.execute).toHaveBeenCalled();
});

it('configures the default console reporter with the right color settings', async function() {
it('configures the default console reporter with the right settings', async function() {
spyOn(this.testJasmine, 'configureDefaultReporter');
spyOn(this.testJasmine, 'loadSpecs');
this.testJasmine.showColors(false);
this.testJasmine.alwaysListPendingSpecs(false);

await this.execute();

expect(this.testJasmine.configureDefaultReporter).toHaveBeenCalledWith({showColors: false});
expect(this.testJasmine.configureDefaultReporter).toHaveBeenCalledWith({
showColors: false,
alwaysListPendingSpecs: false
});
expect(this.testJasmine.loadSpecs).toHaveBeenCalled();
expect(this.testJasmine.env.execute).toHaveBeenCalled();
});
Expand Down
108 changes: 94 additions & 14 deletions spec/reporters/console_reporter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,27 +415,107 @@ describe("ConsoleReporter", function() {
expect(this.out.getOutput()).toMatch(stackLine);
});

it("reports a summary when done that includes which specs are pending and their reasons", function() {
const reporter = new ConsoleReporter();
reporter.setOptions({
print: this.out.print,
describe('When the overall status is passed', function() {
it('includes pending specs in the summary even if alwaysListPendingSpecs is false', function() {
const reporter = new ConsoleReporter();
reporter.setOptions({
print: this.out.print,
alwaysListPendingSpecs: false
});

reporter.jasmineStarted();

reporter.specDone({
status: "pending",
description: "with a pending spec",
fullName: "A suite with a pending spec",
pendingReason: "It's not ready yet!"
});

this.out.clear();

reporter.jasmineDone({overallStatus: 'passed'});

expect(this.out.getOutput()).toContain("Pending:");
expect(this.out.getOutput()).toContain("A suite with a pending spec");
expect(this.out.getOutput()).toContain("It's not ready yet!");
});
});

reporter.jasmineStarted();
describe('When the overall status is failed', function() {
it('includes pending specs in the summary when alwaysListPendingSpecs is true', function() {
const reporter = new ConsoleReporter();
reporter.setOptions({
print: this.out.print,
alwaysListPendingSpecs: true
});

reporter.specDone({
status: "pending",
description: "with a pending spec",
fullName: "A suite with a pending spec",
pendingReason: "It's not ready yet!"
reporter.jasmineStarted();

reporter.specDone({
status: "pending",
description: "with a pending spec",
fullName: "A suite with a pending spec",
pendingReason: "It's not ready yet!"
});

this.out.clear();

reporter.jasmineDone({overallStatus: 'failed'});

expect(this.out.getOutput()).toContain("Pending:");
expect(this.out.getOutput()).toContain("A suite with a pending spec");
expect(this.out.getOutput()).toContain("It's not ready yet!");
});

this.out.clear();
it('omits pending specs in the summary when alwaysListPendingSpecs is false', function() {
const reporter = new ConsoleReporter();
reporter.setOptions({
print: this.out.print,
alwaysListPendingSpecs: false
});

reporter.jasmineDone({});
reporter.jasmineStarted();

reporter.specDone({
status: "pending",
description: "with a pending spec",
fullName: "A suite with a pending spec",
pendingReason: "It's not ready yet!"
});

this.out.clear();

reporter.jasmineDone({overallStatus: 'failed'});

expect(this.out.getOutput()).not.toContain("Pending:");
expect(this.out.getOutput()).not.toContain("A suite with a pending spec");
expect(this.out.getOutput()).not.toContain("It's not ready yet!");
});

expect(this.out.getOutput()).toContain("A suite with a pending spec");
expect(this.out.getOutput()).toContain("It's not ready yet!");
it('includes pending specs in the summary when alwaysListPendingSpecs is unspecified', function() {
const reporter = new ConsoleReporter();
reporter.setOptions({
print: this.out.print,
});

reporter.jasmineStarted();

reporter.specDone({
status: "pending",
description: "with a pending spec",
fullName: "A suite with a pending spec",
pendingReason: "It's not ready yet!"
});

this.out.clear();

reporter.jasmineDone({overallStatus: 'failed'});

expect(this.out.getOutput()).toContain("Pending:");
expect(this.out.getOutput()).toContain("A suite with a pending spec");
expect(this.out.getOutput()).toContain("It's not ready yet!");
});
});

it("reports a summary when done that includes the reason for an incomplete suite", function() {
Expand Down
3 changes: 2 additions & 1 deletion spec/support/jasmine.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"helpers": [
"helpers/**/*.js"
],
"random": true
"random": true,
"alwaysListPendingSpecs": false
}

0 comments on commit 26bb6c9

Please sign in to comment.