Suite result status added when suite is complete

- This makes it easier to detect afterAll failures, because we can
  rely only complete runnables having statuses

[#78306786 & #73741654]
This commit is contained in:
Greg Cobb
2014-09-09 11:10:30 -07:00
committed by Greg Cobb
parent 3332f93a24
commit 1290d93b6a
4 changed files with 121 additions and 91 deletions

View File

@@ -643,12 +643,14 @@ getJasmineRequireObj().Env = function(j$) {
return suite;
};
var focusedRunnables = [];
this.fdescribe = function(description, specDefinitions) {
var suite = suiteFactory(description);
suite.isFocused = true;
focusedRunnables.push(suite.id);
unfocusAncestors();
unfocusAncestor();
addSpecsToSuite(suite, specDefinitions);
return suite;
@@ -686,7 +688,7 @@ getJasmineRequireObj().Env = function(j$) {
return null;
}
function unfocusAncestors() {
function unfocusAncestor() {
var focusedAncestor = findFocusedAncestor(currentDeclarationSuite);
if (focusedAncestor) {
for (var i = 0; i < focusedRunnables.length; i++) {
@@ -755,13 +757,11 @@ getJasmineRequireObj().Env = function(j$) {
return spec;
};
var focusedRunnables = [];
this.fit = function(description, fn ){
var spec = this.it(description, fn);
focusedRunnables.push(spec.id);
unfocusAncestors();
unfocusAncestor();
return spec;
};
@@ -1877,7 +1877,6 @@ getJasmineRequireObj().Suite = function() {
this.result = {
id: this.id,
status: this.disabled ? 'disabled' : '',
description: this.description,
fullName: this.getFullName(),
failedExpectations: []
@@ -1951,6 +1950,7 @@ getJasmineRequireObj().Suite = function() {
});
function complete() {
self.result.status = self.disabled ? 'disabled' : 'finished';
self.resultCallback(self.result);
if (onComplete) {

View File

@@ -260,7 +260,7 @@ describe("Suite", function() {
expect(suiteResultsCallback).toHaveBeenCalledWith({
id: suite.id,
status: '',
status: 'finished',
description: "with a child suite",
fullName: "with a child suite",
failedExpectations: []

View File

@@ -368,110 +368,140 @@ describe("Env integration", function() {
env.execute();
});
it("reports when an afterAll fails an expectation", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
describe('suiteDone reporting', function(){
it("reports when an afterAll fails an expectation", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
'Expected 1 to equal 2.',
'Expected 2 to equal 3.'
]);
done();
});
env.addReporter(reporter);
env.describe('my suite', function() {
env.it('my spec', function() {
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
'Expected 1 to equal 2.',
'Expected 2 to equal 3.'
]);
done();
});
env.afterAll(function() {
env.expect(1).toEqual(2);
env.expect(2).toEqual(3);
});
});
env.addReporter(reporter);
env.execute();
});
env.describe('my suite', function() {
env.it('my spec', function() {
});
it("reports when afterAll throws an exception", function(done) {
var env = new j$.Env(),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
(/^Error: After All Exception/)
]);
done();
});
env.addReporter(reporter);
env.describe('my suite', function() {
env.it('my spec', function() {
env.afterAll(function() {
env.expect(1).toEqual(2);
env.expect(2).toEqual(3);
});
});
env.afterAll(function() {
throw error;
});
env.execute();
});
env.execute();
});
it("if there are no specs, it still reports correctly", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
it("reports when an async afterAll fails an expectation", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('outer suite', [
'Expected 1 to equal 2.',
'Expected 2 to equal 3.'
]);
done();
});
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
'Expected 1 to equal 2.'
]);
done();
});
env.addReporter(reporter);
env.addReporter(reporter);
env.describe('outer suite', function() {
env.describe('inner suite', function() {
env.it('spec', function(){ });
});
env.describe('my suite', function() {
env.it('my spec', function() {
env.afterAll(function() {
env.expect(1).toEqual(2);
env.expect(2).toEqual(3);
});
});
env.execute();
});
env.afterAll(function(afterAllDone) {
env.expect(1).toEqual(2);
afterAllDone();
});
});
it("reports when afterAll throws an exception", function(done) {
var env = new j$.Env(),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
env.execute();
});
it("reports when an async afterAll throws an exception", function(done) {
var env = new j$.Env(),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
(/^Error: After All Exception/)
]);
done();
});
env.addReporter(reporter);
env.describe('my suite', function() {
env.it('my spec', function() {
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
(/^Error: After All Exception/)
]);
done();
});
env.afterAll(function(afterAllDone) {
throw error;
env.addReporter(reporter);
env.describe('my suite', function() {
env.it('my spec', function() {
});
env.afterAll(function() {
throw error;
});
});
env.execute();
});
env.execute();
it("reports when an async afterAll fails an expectation", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
'Expected 1 to equal 2.'
]);
done();
});
env.addReporter(reporter);
env.describe('my suite', function() {
env.it('my spec', function() {
});
env.afterAll(function(afterAllDone) {
env.expect(1).toEqual(2);
afterAllDone();
});
});
env.execute();
});
it("reports when an async afterAll throws an exception", function(done) {
var env = new j$.Env(),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
(/^Error: After All Exception/)
]);
done();
});
env.addReporter(reporter);
env.describe('my suite', function() {
env.it('my spec', function() {
});
env.afterAll(function(afterAllDone) {
throw error;
});
});
env.execute();
});
});
it("Allows specifying which specs and suites to run", function(done) {

View File

@@ -21,7 +21,6 @@ getJasmineRequireObj().Suite = function() {
this.result = {
id: this.id,
status: this.disabled ? 'disabled' : '',
description: this.description,
fullName: this.getFullName(),
failedExpectations: []
@@ -95,6 +94,7 @@ getJasmineRequireObj().Suite = function() {
});
function complete() {
self.result.status = self.disabled ? 'disabled' : 'finished';
self.resultCallback(self.result);
if (onComplete) {