Allow reporter callbacks to be asynchronous

[finishes #154673961]
- Fixes #842

Signed-off-by: Elenore Bastian <ebastian@pivotal.io>
This commit is contained in:
Gregg Van Hove
2018-01-26 18:00:46 -08:00
parent 341c6df6ea
commit 50cd6fdd68
10 changed files with 434 additions and 272 deletions

View File

@@ -284,19 +284,20 @@ describe("TreeProcessor", function() {
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn(nodeDone);
expect(nodeStart).toHaveBeenCalledWith(node);
expect(queueRunner).toHaveBeenCalledWith({
onComplete: jasmine.any(Function),
queueableFns: [],
queueableFns: [{ fn: jasmine.any(Function) }],
userContext: { node: 'context' },
onException: jasmine.any(Function)
});
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
expect(nodeStart).toHaveBeenCalledWith(node, 'foo');
node.getResult.and.returnValue({ my: 'result' });
queueRunner.calls.mostRecent().args[0].onComplete();
expect(nodeComplete).toHaveBeenCalledWith(node, { my: 'result' });
expect(nodeDone).toHaveBeenCalled();
expect(nodeComplete).toHaveBeenCalledWith(node, { my: 'result' }, nodeDone);
});
it("runs a node with children", function() {
@@ -318,12 +319,12 @@ describe("TreeProcessor", function() {
queueableFns[0].fn(nodeDone);
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
expect(queueableFns.length).toBe(2);
expect(queueableFns.length).toBe(3);
queueableFns[0].fn('foo');
queueableFns[1].fn('foo');
expect(leaf1.execute).toHaveBeenCalledWith('foo', false);
queueableFns[1].fn('bar');
queueableFns[2].fn('bar');
expect(leaf2.execute).toHaveBeenCalledWith('bar', false);
});
@@ -348,18 +349,19 @@ describe("TreeProcessor", function() {
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
queueableFns[0].fn(nodeDone);
expect(nodeStart).toHaveBeenCalledWith(node);
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
expect(queueableFns.length).toBe(1);
expect(queueableFns.length).toBe(2);
queueableFns[0].fn('foo');
queueableFns[0].fn('bar');
expect(nodeStart).toHaveBeenCalledWith(node, 'bar');
queueableFns[1].fn('foo');
expect(leaf1.execute).toHaveBeenCalledWith('foo', true);
node.getResult.and.returnValue({ im: 'disabled' });
queueRunner.calls.mostRecent().args[0].onComplete();
expect(nodeComplete).toHaveBeenCalledWith(node, { im: 'disabled' });
expect(nodeComplete).toHaveBeenCalledWith(node, { im: 'disabled' }, nodeDone);
});
it("runs beforeAlls for a node with children", function() {
@@ -384,7 +386,7 @@ describe("TreeProcessor", function() {
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
expect(queueableFns).toEqual(['beforeAll1', 'beforeAll2', { fn: jasmine.any(Function) }]);
expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, 'beforeAll1', 'beforeAll2', { fn: jasmine.any(Function) }]);
});
it("runs afterAlls for a node with children", function() {
@@ -409,7 +411,7 @@ describe("TreeProcessor", function() {
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, 'afterAll1', 'afterAll2']);
expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, { fn: jasmine.any(Function) }, 'afterAll1', 'afterAll2']);
});
it("does not run beforeAlls or afterAlls for a node with no children", function() {
@@ -433,7 +435,7 @@ describe("TreeProcessor", function() {
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
expect(queueableFns).toEqual([]);
expect(queueableFns).toEqual([{fn: jasmine.any(Function)}]);
});
it("does not run beforeAlls or afterAlls for a node with only pending children", function() {
@@ -460,7 +462,7 @@ describe("TreeProcessor", function() {
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }]);
expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, { fn: jasmine.any(Function) }]);
});
it("runs leaves in the order specified", function() {
@@ -529,7 +531,7 @@ describe("TreeProcessor", function() {
expect(specifiedLeaf.execute).not.toHaveBeenCalled();
var nodeQueueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
nodeQueueableFns[0].fn();
nodeQueueableFns[1].fn();
expect(childLeaf.execute).toHaveBeenCalled();
@@ -558,8 +560,8 @@ describe("TreeProcessor", function() {
expect(queueableFns.length).toBe(5);
queueableFns[0].fn();
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
expect(leaf1.execute).toHaveBeenCalled();
queueableFns[1].fn();
@@ -567,8 +569,8 @@ describe("TreeProcessor", function() {
queueableFns[2].fn();
expect(queueRunner.calls.count()).toBe(3);
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
expect(leaf2.execute).toHaveBeenCalled();
queueableFns[3].fn();
@@ -576,8 +578,8 @@ describe("TreeProcessor", function() {
queueableFns[4].fn();
expect(queueRunner.calls.count()).toBe(4);
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
expect(leaf3.execute).toHaveBeenCalled();
});
@@ -603,12 +605,12 @@ describe("TreeProcessor", function() {
queueableFns[0].fn();
expect(queueRunner.calls.count()).toBe(2);
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
expect(queueRunner.calls.count()).toBe(3);
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
expect(leaf1.execute).toHaveBeenCalled();
queueableFns[1].fn();
@@ -616,12 +618,12 @@ describe("TreeProcessor", function() {
queueableFns[2].fn();
expect(queueRunner.calls.count()).toBe(4);
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
expect(queueRunner.calls.count()).toBe(5);
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
expect(leaf2.execute).toHaveBeenCalled();
queueableFns[3].fn();
@@ -629,12 +631,12 @@ describe("TreeProcessor", function() {
queueableFns[4].fn();
expect(queueRunner.calls.count()).toBe(6);
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(1);
expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
expect(queueRunner.calls.count()).toBe(7);
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn();
queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
expect(leaf3.execute).toHaveBeenCalled();
});
@@ -661,11 +663,11 @@ describe("TreeProcessor", function() {
queueableFns[1].fn();
var childFns = queueRunner.calls.mostRecent().args[0].queueableFns;
expect(childFns.length).toBe(2);
childFns[0].fn();
expect(childFns.length).toBe(3);
childFns[1].fn();
expect(leaf2.execute).toHaveBeenCalled();
childFns[1].fn();
childFns[2].fn();
expect(leaf3.execute).toHaveBeenCalled();
});