Skip everything except afterAll fns when a beforeAll fn errors
* Fixes #1533
This commit is contained in:
+79
-25
@@ -83,6 +83,9 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
|
|||||||
j$.SetContaining = jRequire.SetContaining(j$);
|
j$.SetContaining = jRequire.SetContaining(j$);
|
||||||
j$.QueueRunner = jRequire.QueueRunner(j$);
|
j$.QueueRunner = jRequire.QueueRunner(j$);
|
||||||
j$.NeverSkipPolicy = jRequire.NeverSkipPolicy(j$);
|
j$.NeverSkipPolicy = jRequire.NeverSkipPolicy(j$);
|
||||||
|
j$.SkipAfterBeforeAllErrorPolicy = jRequire.SkipAfterBeforeAllErrorPolicy(
|
||||||
|
j$
|
||||||
|
);
|
||||||
j$.CompleteOnFirstErrorSkipPolicy = jRequire.CompleteOnFirstErrorSkipPolicy(
|
j$.CompleteOnFirstErrorSkipPolicy = jRequire.CompleteOnFirstErrorSkipPolicy(
|
||||||
j$
|
j$
|
||||||
);
|
);
|
||||||
@@ -1612,15 +1615,19 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var queueRunnerFactory = function(options, args) {
|
var queueRunnerFactory = function(options, args) {
|
||||||
if (
|
if (options.isLeaf) {
|
||||||
// A spec
|
// A spec
|
||||||
options.isLeaf ||
|
|
||||||
// A suite, and config.stopOnSpecFailure is set
|
|
||||||
(!options.isLeaf && !options.isReporter && config.stopOnSpecFailure)
|
|
||||||
) {
|
|
||||||
options.SkipPolicy = j$.CompleteOnFirstErrorSkipPolicy;
|
options.SkipPolicy = j$.CompleteOnFirstErrorSkipPolicy;
|
||||||
} else {
|
} else if (options.isReporter) {
|
||||||
|
// A reporter queue
|
||||||
options.SkipPolicy = j$.NeverSkipPolicy;
|
options.SkipPolicy = j$.NeverSkipPolicy;
|
||||||
|
} else {
|
||||||
|
// A suite
|
||||||
|
if (config.stopOnSpecFailure) {
|
||||||
|
options.SkipPolicy = j$.CompleteOnFirstErrorSkipPolicy;
|
||||||
|
} else {
|
||||||
|
options.SkipPolicy = j$.SkipAfterBeforeAllErrorPolicy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
options.clearStack = options.clearStack || clearStack;
|
options.clearStack = options.clearStack || clearStack;
|
||||||
@@ -3390,21 +3397,22 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
|
|
||||||
getJasmineRequireObj().CompleteOnFirstErrorSkipPolicy = function(j$) {
|
getJasmineRequireObj().CompleteOnFirstErrorSkipPolicy = function(j$) {
|
||||||
function CompleteOnFirstErrorSkipPolicy(queueableFns, firstCleanupIx) {
|
function CompleteOnFirstErrorSkipPolicy(queueableFns, firstCleanupIx) {
|
||||||
this.queueableFns_ = queueableFns;
|
|
||||||
this.firstCleanupIx_ = firstCleanupIx;
|
this.firstCleanupIx_ = firstCleanupIx;
|
||||||
|
this.skipping_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompleteOnFirstErrorSkipPolicy.prototype.skipTo = function(
|
CompleteOnFirstErrorSkipPolicy.prototype.skipTo = function(lastRanFnIx) {
|
||||||
lastRanFnIx,
|
if (this.skipping_ && lastRanFnIx < this.firstCleanupIx_) {
|
||||||
errored
|
|
||||||
) {
|
|
||||||
if (errored && lastRanFnIx < this.firstCleanupIx_) {
|
|
||||||
return this.firstCleanupIx_;
|
return this.firstCleanupIx_;
|
||||||
} else {
|
} else {
|
||||||
return lastRanFnIx + 1;
|
return lastRanFnIx + 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CompleteOnFirstErrorSkipPolicy.prototype.fnErrored = function(fnIx) {
|
||||||
|
this.skipping_ = true;
|
||||||
|
};
|
||||||
|
|
||||||
return CompleteOnFirstErrorSkipPolicy;
|
return CompleteOnFirstErrorSkipPolicy;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -7288,10 +7296,12 @@ getJasmineRequireObj().MockDate = function(j$) {
|
|||||||
getJasmineRequireObj().NeverSkipPolicy = function(j$) {
|
getJasmineRequireObj().NeverSkipPolicy = function(j$) {
|
||||||
function NeverSkipPolicy(queueableFns, firstCleanupIx) {}
|
function NeverSkipPolicy(queueableFns, firstCleanupIx) {}
|
||||||
|
|
||||||
NeverSkipPolicy.prototype.skipTo = function(lastRanFnIx, errored) {
|
NeverSkipPolicy.prototype.skipTo = function(lastRanFnIx) {
|
||||||
return lastRanFnIx + 1;
|
return lastRanFnIx + 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NeverSkipPolicy.prototype.fnErrored = function(fnIx) {};
|
||||||
|
|
||||||
return NeverSkipPolicy;
|
return NeverSkipPolicy;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -7762,7 +7772,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
|
|
||||||
const SkipPolicy = attrs.SkipPolicy || j$.NeverSkipPolicy;
|
const SkipPolicy = attrs.SkipPolicy || j$.NeverSkipPolicy;
|
||||||
this.skipPolicy_ = new SkipPolicy(this.queueableFns, this.firstCleanupIx);
|
this.skipPolicy_ = new SkipPolicy(this.queueableFns, this.firstCleanupIx);
|
||||||
this.errored = false;
|
this.errored_ = false;
|
||||||
|
|
||||||
if (typeof this.onComplete !== 'function') {
|
if (typeof this.onComplete !== 'function') {
|
||||||
throw new Error('invalid onComplete ' + JSON.stringify(this.onComplete));
|
throw new Error('invalid onComplete ' + JSON.stringify(this.onComplete));
|
||||||
@@ -7818,7 +7828,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
|
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
|
||||||
self.fail(err);
|
self.fail(err);
|
||||||
}
|
}
|
||||||
self.errored = errored = true;
|
self.recordError_(iterativeIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
function runNext() {
|
function runNext() {
|
||||||
@@ -7844,7 +7854,6 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
errored = false,
|
|
||||||
timedOut = false,
|
timedOut = false,
|
||||||
queueableFn = self.queueableFns[iterativeIndex],
|
queueableFn = self.queueableFns[iterativeIndex],
|
||||||
timeoutId,
|
timeoutId,
|
||||||
@@ -7852,7 +7861,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
|
|
||||||
next.fail = function nextFail() {
|
next.fail = function nextFail() {
|
||||||
self.fail.apply(null, arguments);
|
self.fail.apply(null, arguments);
|
||||||
self.errored = errored = true;
|
self.recordError_(iterativeIndex);
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -7895,15 +7904,15 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
onException(e);
|
onException(e);
|
||||||
self.errored = errored = true;
|
self.recordError_(iterativeIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
return { completedSynchronously: true, errored: errored };
|
return { completedSynchronously: true };
|
||||||
|
|
||||||
function onException(e) {
|
function onException(e) {
|
||||||
self.onException(e);
|
self.onException(e);
|
||||||
self.errored = errored = true;
|
self.recordError_(iterativeIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPromiseRejection(e) {
|
function onPromiseRejection(e) {
|
||||||
@@ -7927,14 +7936,12 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
if (!result.completedSynchronously) {
|
if (!result.completedSynchronously) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.errored = self.errored || result.errored;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clearStack(function() {
|
this.clearStack(function() {
|
||||||
self.globalErrors.popListener(self.handleFinalError);
|
self.globalErrors.popListener(self.handleFinalError);
|
||||||
|
|
||||||
if (self.errored) {
|
if (self.errored_) {
|
||||||
self.onComplete(new StopExecutionError());
|
self.onComplete(new StopExecutionError());
|
||||||
} else {
|
} else {
|
||||||
self.onComplete();
|
self.onComplete();
|
||||||
@@ -7943,7 +7950,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
QueueRunner.prototype.nextFnIx_ = function(currentFnIx) {
|
QueueRunner.prototype.nextFnIx_ = function(currentFnIx) {
|
||||||
const result = this.skipPolicy_.skipTo(currentFnIx, this.errored);
|
const result = this.skipPolicy_.skipTo(currentFnIx);
|
||||||
|
|
||||||
if (result === currentFnIx) {
|
if (result === currentFnIx) {
|
||||||
throw new Error("Can't skip to the same queueable fn that just finished");
|
throw new Error("Can't skip to the same queueable fn that just finished");
|
||||||
@@ -7952,6 +7959,11 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QueueRunner.prototype.recordError_ = function(currentFnIx) {
|
||||||
|
this.errored_ = true;
|
||||||
|
this.skipPolicy_.fnErrored(currentFnIx);
|
||||||
|
};
|
||||||
|
|
||||||
QueueRunner.prototype.diagnoseConflictingAsync_ = function(fn, retval) {
|
QueueRunner.prototype.diagnoseConflictingAsync_ = function(fn, retval) {
|
||||||
var msg;
|
var msg;
|
||||||
|
|
||||||
@@ -8496,6 +8508,39 @@ getJasmineRequireObj().interface = function(jasmine, env) {
|
|||||||
return jasmineInterface;
|
return jasmineInterface;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getJasmineRequireObj().SkipAfterBeforeAllErrorPolicy = function(j$) {
|
||||||
|
function SkipAfterBeforeAllErrorPolicy(queueableFns, firstCleanupIx) {
|
||||||
|
this.queueableFns_ = queueableFns;
|
||||||
|
this.skipping_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SkipAfterBeforeAllErrorPolicy.prototype.skipTo = function(lastRanFnIx) {
|
||||||
|
if (this.skipping_) {
|
||||||
|
return this.nextAfterAllAfter_(lastRanFnIx);
|
||||||
|
} else {
|
||||||
|
return lastRanFnIx + 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SkipAfterBeforeAllErrorPolicy.prototype.nextAfterAllAfter_ = function(i) {
|
||||||
|
for (
|
||||||
|
i++;
|
||||||
|
i < this.queueableFns_.length &&
|
||||||
|
this.queueableFns_[i].type !== 'afterAll';
|
||||||
|
i++
|
||||||
|
) {}
|
||||||
|
return i;
|
||||||
|
};
|
||||||
|
|
||||||
|
SkipAfterBeforeAllErrorPolicy.prototype.fnErrored = function(fnIx) {
|
||||||
|
if (this.queueableFns_[fnIx].type === 'beforeAll') {
|
||||||
|
this.skipping_ = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return SkipAfterBeforeAllErrorPolicy;
|
||||||
|
};
|
||||||
|
|
||||||
getJasmineRequireObj().Spy = function(j$) {
|
getJasmineRequireObj().Spy = function(j$) {
|
||||||
var nextOrder = (function() {
|
var nextOrder = (function() {
|
||||||
var order = 0;
|
var order = 0;
|
||||||
@@ -9942,7 +9987,16 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return node.beforeAllFns.concat(result).concat(node.afterAllFns);
|
return node.beforeAllFns
|
||||||
|
.map(function(fn) {
|
||||||
|
return { type: 'beforeAll', ...fn };
|
||||||
|
})
|
||||||
|
.concat(result)
|
||||||
|
.concat(
|
||||||
|
node.afterAllFns.map(function(fn) {
|
||||||
|
return { type: 'afterAll', ...fn };
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,9 @@
|
|||||||
"node": true,
|
"node": true,
|
||||||
"es2017": true
|
"es2017": true
|
||||||
},
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2018
|
||||||
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"quotes": [
|
"quotes": [
|
||||||
"error",
|
"error",
|
||||||
|
|||||||
@@ -1,24 +1,25 @@
|
|||||||
describe('CompleteOnFirstErrorSkipPolicy', function() {
|
describe('CompleteOnFirstErrorSkipPolicy', function() {
|
||||||
describe('#skipTo', function() {
|
describe('#skipTo', function() {
|
||||||
describe('When errored is false', function() {
|
describe('Before anything has errored', function() {
|
||||||
it('returns the next index', function() {
|
it('returns the next index', function() {
|
||||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||||
arrayOfArbitraryFns(4),
|
arrayOfArbitraryFns(4),
|
||||||
4
|
4
|
||||||
);
|
);
|
||||||
expect(policy.skipTo(1, false)).toEqual(2);
|
expect(policy.skipTo(1)).toEqual(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When errored is true', function() {
|
describe('After something has errored', function() {
|
||||||
it('returns the first cleanup fn when called with a non cleanup fn', function() {
|
it('returns the first cleanup fn when called with a non cleanup fn', function() {
|
||||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||||
arrayOfArbitraryFns(4),
|
arrayOfArbitraryFns(4),
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(policy.skipTo(0, true)).toEqual(2);
|
policy.fnErrored(0);
|
||||||
expect(policy.skipTo(1, true)).toEqual(2);
|
expect(policy.skipTo(0)).toEqual(2);
|
||||||
|
expect(policy.skipTo(1)).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the next index when called with a cleanup fn', function() {
|
it('returns the next index when called with a cleanup fn', function() {
|
||||||
@@ -27,8 +28,9 @@ describe('CompleteOnFirstErrorSkipPolicy', function() {
|
|||||||
1
|
1
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(policy.skipTo(1, true)).toEqual(2);
|
policy.fnErrored(0);
|
||||||
expect(policy.skipTo(2, true)).toEqual(3);
|
expect(policy.skipTo(1)).toEqual(2);
|
||||||
|
expect(policy.skipTo(2)).toEqual(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -674,7 +674,10 @@ describe('QueueRunner', function() {
|
|||||||
{ fn: jasmine.createSpy('fn2').and.throwError(new Error('nope')) },
|
{ fn: jasmine.createSpy('fn2').and.throwError(new Error('nope')) },
|
||||||
{ fn: jasmine.createSpy('fn3') }
|
{ fn: jasmine.createSpy('fn3') }
|
||||||
];
|
];
|
||||||
const skipPolicy = jasmine.createSpyObj('skipPolicy', ['skipTo']);
|
const skipPolicy = jasmine.createSpyObj('skipPolicy', [
|
||||||
|
'skipTo',
|
||||||
|
'fnErrored'
|
||||||
|
]);
|
||||||
skipPolicy.skipTo.and.callFake(function(lastRanIx) {
|
skipPolicy.skipTo.and.callFake(function(lastRanIx) {
|
||||||
return lastRanIx === 0 ? 2 : lastRanIx + 1;
|
return lastRanIx === 0 ? 2 : lastRanIx + 1;
|
||||||
});
|
});
|
||||||
@@ -687,8 +690,9 @@ describe('QueueRunner', function() {
|
|||||||
|
|
||||||
queueRunner.execute();
|
queueRunner.execute();
|
||||||
|
|
||||||
expect(skipPolicy.skipTo).toHaveBeenCalledWith(0, false);
|
expect(skipPolicy.skipTo).toHaveBeenCalledWith(0);
|
||||||
expect(skipPolicy.skipTo).toHaveBeenCalledWith(2, true);
|
expect(skipPolicy.skipTo).toHaveBeenCalledWith(2);
|
||||||
|
expect(skipPolicy.fnErrored).toHaveBeenCalledWith(2);
|
||||||
expect(queueableFns[0].fn).toHaveBeenCalled();
|
expect(queueableFns[0].fn).toHaveBeenCalled();
|
||||||
expect(queueableFns[1].fn).not.toHaveBeenCalled();
|
expect(queueableFns[1].fn).not.toHaveBeenCalled();
|
||||||
expect(queueableFns[2].fn).toHaveBeenCalled();
|
expect(queueableFns[2].fn).toHaveBeenCalled();
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
describe('SkipAfterBeforeAllErrorPolicy', function() {
|
||||||
|
describe('#skipTo', function() {
|
||||||
|
describe('When nothing has errored', function() {
|
||||||
|
it('does not skip anything', function() {
|
||||||
|
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
|
||||||
|
arrayOfArbitraryFns(4),
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(policy.skipTo(0)).toEqual(1);
|
||||||
|
expect(policy.skipTo(1)).toEqual(2);
|
||||||
|
expect(policy.skipTo(2)).toEqual(3);
|
||||||
|
expect(policy.skipTo(3)).toEqual(4);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When anything but a beforeAll has errored', function() {
|
||||||
|
it('does not skip anything', function() {
|
||||||
|
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
|
||||||
|
arrayOfArbitraryFns(4),
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
policy.fnErrored(0);
|
||||||
|
expect(policy.skipTo(0)).toEqual(1);
|
||||||
|
policy.fnErrored(1);
|
||||||
|
expect(policy.skipTo(1)).toEqual(2);
|
||||||
|
policy.fnErrored(2);
|
||||||
|
expect(policy.skipTo(2)).toEqual(3);
|
||||||
|
policy.fnErrored(3);
|
||||||
|
expect(policy.skipTo(3)).toEqual(4);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('When a beforeAll has errored', function() {
|
||||||
|
it('skips subsequent functions other than afterAll', function() {
|
||||||
|
const fns = [
|
||||||
|
{ type: 'beforeAll', fn: () => {} },
|
||||||
|
{ fn: () => {} },
|
||||||
|
{ fn: () => {} },
|
||||||
|
{ type: 'afterAll', fn: () => {} },
|
||||||
|
{ type: 'afterAll', fn: () => {} }
|
||||||
|
];
|
||||||
|
const policy = new jasmineUnderTest.SkipAfterBeforeAllErrorPolicy(
|
||||||
|
fns,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
policy.fnErrored(0);
|
||||||
|
expect(policy.skipTo(0)).toEqual(3);
|
||||||
|
expect(policy.skipTo(3)).toEqual(4);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function arrayOfArbitraryFns(n) {
|
||||||
|
const result = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
result.push({ fn: () => {} });
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -482,7 +482,10 @@ describe('TreeProcessor', function() {
|
|||||||
var leaf = new Leaf(),
|
var leaf = new Leaf(),
|
||||||
node = new Node({
|
node = new Node({
|
||||||
children: [leaf],
|
children: [leaf],
|
||||||
beforeAllFns: ['beforeAll1', 'beforeAll2']
|
beforeAllFns: [
|
||||||
|
{ fn: 'beforeAll1', timeout: 1 },
|
||||||
|
{ fn: 'beforeAll2', timeout: 2 }
|
||||||
|
]
|
||||||
}),
|
}),
|
||||||
root = new Node({ children: [node] }),
|
root = new Node({ children: [node] }),
|
||||||
queueRunner = jasmine.createSpy('queueRunner'),
|
queueRunner = jasmine.createSpy('queueRunner'),
|
||||||
@@ -502,8 +505,8 @@ describe('TreeProcessor', function() {
|
|||||||
|
|
||||||
expect(queueableFns).toEqual([
|
expect(queueableFns).toEqual([
|
||||||
{ fn: jasmine.any(Function) },
|
{ fn: jasmine.any(Function) },
|
||||||
'beforeAll1',
|
{ type: 'beforeAll', fn: 'beforeAll1', timeout: 1 },
|
||||||
'beforeAll2',
|
{ type: 'beforeAll', fn: 'beforeAll2', timeout: 2 },
|
||||||
{ fn: jasmine.any(Function) }
|
{ fn: jasmine.any(Function) }
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
@@ -512,7 +515,7 @@ describe('TreeProcessor', function() {
|
|||||||
var leaf = new Leaf(),
|
var leaf = new Leaf(),
|
||||||
node = new Node({
|
node = new Node({
|
||||||
children: [leaf],
|
children: [leaf],
|
||||||
afterAllFns: ['afterAll1', 'afterAll2']
|
afterAllFns: [{ fn: 'afterAll1' }, { fn: 'afterAll2' }]
|
||||||
}),
|
}),
|
||||||
root = new Node({ children: [node] }),
|
root = new Node({ children: [node] }),
|
||||||
queueRunner = jasmine.createSpy('queueRunner'),
|
queueRunner = jasmine.createSpy('queueRunner'),
|
||||||
@@ -533,15 +536,15 @@ describe('TreeProcessor', function() {
|
|||||||
expect(queueableFns).toEqual([
|
expect(queueableFns).toEqual([
|
||||||
{ fn: jasmine.any(Function) },
|
{ fn: jasmine.any(Function) },
|
||||||
{ fn: jasmine.any(Function) },
|
{ fn: jasmine.any(Function) },
|
||||||
'afterAll1',
|
{ type: 'afterAll', fn: 'afterAll1' },
|
||||||
'afterAll2'
|
{ type: 'afterAll', fn: 'afterAll2' }
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not run beforeAlls or afterAlls for a node with no children', function() {
|
it('does not run beforeAlls or afterAlls for a node with no children', function() {
|
||||||
var node = new Node({
|
var node = new Node({
|
||||||
beforeAllFns: ['before'],
|
beforeAllFns: [{ fn: 'before' }],
|
||||||
afterAllFns: ['after']
|
afterAllFns: [{ fn: 'after' }]
|
||||||
}),
|
}),
|
||||||
root = new Node({ children: [node] }),
|
root = new Node({ children: [node] }),
|
||||||
queueRunner = jasmine.createSpy('queueRunner'),
|
queueRunner = jasmine.createSpy('queueRunner'),
|
||||||
@@ -566,8 +569,8 @@ describe('TreeProcessor', function() {
|
|||||||
var leaf = new Leaf({ markedPending: true }),
|
var leaf = new Leaf({ markedPending: true }),
|
||||||
node = new Node({
|
node = new Node({
|
||||||
children: [leaf],
|
children: [leaf],
|
||||||
beforeAllFns: ['before'],
|
beforeAllFns: [{ fn: 'before' }],
|
||||||
afterAllFns: ['after'],
|
afterAllFns: [{ fn: 'after' }],
|
||||||
markedPending: false
|
markedPending: false
|
||||||
}),
|
}),
|
||||||
root = new Node({ children: [node] }),
|
root = new Node({ children: [node] }),
|
||||||
|
|||||||
@@ -1158,6 +1158,68 @@ describe('spec running', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('When a beforeAll function fails', function() {
|
||||||
|
it('skips contained specs and suites', async function() {
|
||||||
|
const outerBeforeEach = jasmine.createSpy('outerBeforeEach');
|
||||||
|
const nestedBeforeEach = jasmine.createSpy('nestedBeforeEach');
|
||||||
|
const outerAfterEach = jasmine.createSpy('outerAfterEach');
|
||||||
|
const nestedAfterEach = jasmine.createSpy('nestedAfterEach');
|
||||||
|
const outerIt = jasmine.createSpy('outerIt');
|
||||||
|
const nestedIt = jasmine.createSpy('nestedIt');
|
||||||
|
const nestedBeforeAll = jasmine.createSpy('nestedBeforeAll');
|
||||||
|
|
||||||
|
env.beforeAll(function() {
|
||||||
|
throw new Error('nope');
|
||||||
|
});
|
||||||
|
|
||||||
|
env.beforeEach(outerBeforeEach);
|
||||||
|
env.it('a spec', outerIt);
|
||||||
|
env.describe('a nested suite', function() {
|
||||||
|
env.beforeAll(nestedBeforeAll);
|
||||||
|
env.beforeEach(nestedBeforeEach);
|
||||||
|
env.it('a nested spec', nestedIt);
|
||||||
|
env.afterEach(nestedAfterEach);
|
||||||
|
});
|
||||||
|
env.afterEach(outerAfterEach);
|
||||||
|
|
||||||
|
await env.execute();
|
||||||
|
|
||||||
|
expect(outerBeforeEach).not.toHaveBeenCalled();
|
||||||
|
expect(outerIt).not.toHaveBeenCalled();
|
||||||
|
expect(nestedBeforeAll).not.toHaveBeenCalled();
|
||||||
|
expect(nestedBeforeEach).not.toHaveBeenCalled();
|
||||||
|
expect(nestedIt).not.toHaveBeenCalled();
|
||||||
|
expect(nestedAfterEach).not.toHaveBeenCalled();
|
||||||
|
expect(outerAfterEach).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('runs afterAll functions in the current suite and outer scopes', async function() {
|
||||||
|
const outerAfterAll = jasmine.createSpy('outerAfterAll');
|
||||||
|
const nestedAfterAll = jasmine.createSpy('nestedAfterAll');
|
||||||
|
const secondNestedAfterAll = jasmine.createSpy('secondNestedAfterAll');
|
||||||
|
|
||||||
|
env.describe('a nested suite', function() {
|
||||||
|
env.beforeAll(function() {
|
||||||
|
throw new Error('nope');
|
||||||
|
});
|
||||||
|
|
||||||
|
env.describe('more nesting', function() {
|
||||||
|
env.it('a nested spec', function() {});
|
||||||
|
env.afterAll(secondNestedAfterAll);
|
||||||
|
});
|
||||||
|
|
||||||
|
env.afterAll(nestedAfterAll);
|
||||||
|
});
|
||||||
|
env.afterAll(outerAfterAll);
|
||||||
|
|
||||||
|
await env.execute();
|
||||||
|
|
||||||
|
expect(secondNestedAfterAll).not.toHaveBeenCalled();
|
||||||
|
expect(nestedAfterAll).toHaveBeenCalled();
|
||||||
|
expect(outerAfterAll).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when stopOnSpecFailure is on', function() {
|
describe('when stopOnSpecFailure is on', function() {
|
||||||
it('does not run further specs when one fails', function(done) {
|
it('does not run further specs when one fails', function(done) {
|
||||||
var actions = [],
|
var actions = [],
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
getJasmineRequireObj().CompleteOnFirstErrorSkipPolicy = function(j$) {
|
getJasmineRequireObj().CompleteOnFirstErrorSkipPolicy = function(j$) {
|
||||||
function CompleteOnFirstErrorSkipPolicy(queueableFns, firstCleanupIx) {
|
function CompleteOnFirstErrorSkipPolicy(queueableFns, firstCleanupIx) {
|
||||||
this.queueableFns_ = queueableFns;
|
|
||||||
this.firstCleanupIx_ = firstCleanupIx;
|
this.firstCleanupIx_ = firstCleanupIx;
|
||||||
|
this.skipping_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompleteOnFirstErrorSkipPolicy.prototype.skipTo = function(
|
CompleteOnFirstErrorSkipPolicy.prototype.skipTo = function(lastRanFnIx) {
|
||||||
lastRanFnIx,
|
if (this.skipping_ && lastRanFnIx < this.firstCleanupIx_) {
|
||||||
errored
|
|
||||||
) {
|
|
||||||
if (errored && lastRanFnIx < this.firstCleanupIx_) {
|
|
||||||
return this.firstCleanupIx_;
|
return this.firstCleanupIx_;
|
||||||
} else {
|
} else {
|
||||||
return lastRanFnIx + 1;
|
return lastRanFnIx + 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CompleteOnFirstErrorSkipPolicy.prototype.fnErrored = function(fnIx) {
|
||||||
|
this.skipping_ = true;
|
||||||
|
};
|
||||||
|
|
||||||
return CompleteOnFirstErrorSkipPolicy;
|
return CompleteOnFirstErrorSkipPolicy;
|
||||||
};
|
};
|
||||||
|
|||||||
+10
-6
@@ -502,15 +502,19 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var queueRunnerFactory = function(options, args) {
|
var queueRunnerFactory = function(options, args) {
|
||||||
if (
|
if (options.isLeaf) {
|
||||||
// A spec
|
// A spec
|
||||||
options.isLeaf ||
|
|
||||||
// A suite, and config.stopOnSpecFailure is set
|
|
||||||
(!options.isLeaf && !options.isReporter && config.stopOnSpecFailure)
|
|
||||||
) {
|
|
||||||
options.SkipPolicy = j$.CompleteOnFirstErrorSkipPolicy;
|
options.SkipPolicy = j$.CompleteOnFirstErrorSkipPolicy;
|
||||||
} else {
|
} else if (options.isReporter) {
|
||||||
|
// A reporter queue
|
||||||
options.SkipPolicy = j$.NeverSkipPolicy;
|
options.SkipPolicy = j$.NeverSkipPolicy;
|
||||||
|
} else {
|
||||||
|
// A suite
|
||||||
|
if (config.stopOnSpecFailure) {
|
||||||
|
options.SkipPolicy = j$.CompleteOnFirstErrorSkipPolicy;
|
||||||
|
} else {
|
||||||
|
options.SkipPolicy = j$.SkipAfterBeforeAllErrorPolicy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
options.clearStack = options.clearStack || clearStack;
|
options.clearStack = options.clearStack || clearStack;
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
getJasmineRequireObj().NeverSkipPolicy = function(j$) {
|
getJasmineRequireObj().NeverSkipPolicy = function(j$) {
|
||||||
function NeverSkipPolicy(queueableFns, firstCleanupIx) {}
|
function NeverSkipPolicy(queueableFns, firstCleanupIx) {}
|
||||||
|
|
||||||
NeverSkipPolicy.prototype.skipTo = function(lastRanFnIx, errored) {
|
NeverSkipPolicy.prototype.skipTo = function(lastRanFnIx) {
|
||||||
return lastRanFnIx + 1;
|
return lastRanFnIx + 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NeverSkipPolicy.prototype.fnErrored = function(fnIx) {};
|
||||||
|
|
||||||
return NeverSkipPolicy;
|
return NeverSkipPolicy;
|
||||||
};
|
};
|
||||||
|
|||||||
+13
-11
@@ -59,7 +59,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
|
|
||||||
const SkipPolicy = attrs.SkipPolicy || j$.NeverSkipPolicy;
|
const SkipPolicy = attrs.SkipPolicy || j$.NeverSkipPolicy;
|
||||||
this.skipPolicy_ = new SkipPolicy(this.queueableFns, this.firstCleanupIx);
|
this.skipPolicy_ = new SkipPolicy(this.queueableFns, this.firstCleanupIx);
|
||||||
this.errored = false;
|
this.errored_ = false;
|
||||||
|
|
||||||
if (typeof this.onComplete !== 'function') {
|
if (typeof this.onComplete !== 'function') {
|
||||||
throw new Error('invalid onComplete ' + JSON.stringify(this.onComplete));
|
throw new Error('invalid onComplete ' + JSON.stringify(this.onComplete));
|
||||||
@@ -115,7 +115,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
|
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
|
||||||
self.fail(err);
|
self.fail(err);
|
||||||
}
|
}
|
||||||
self.errored = errored = true;
|
self.recordError_(iterativeIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
function runNext() {
|
function runNext() {
|
||||||
@@ -141,7 +141,6 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
errored = false,
|
|
||||||
timedOut = false,
|
timedOut = false,
|
||||||
queueableFn = self.queueableFns[iterativeIndex],
|
queueableFn = self.queueableFns[iterativeIndex],
|
||||||
timeoutId,
|
timeoutId,
|
||||||
@@ -149,7 +148,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
|
|
||||||
next.fail = function nextFail() {
|
next.fail = function nextFail() {
|
||||||
self.fail.apply(null, arguments);
|
self.fail.apply(null, arguments);
|
||||||
self.errored = errored = true;
|
self.recordError_(iterativeIndex);
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -192,15 +191,15 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
onException(e);
|
onException(e);
|
||||||
self.errored = errored = true;
|
self.recordError_(iterativeIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
return { completedSynchronously: true, errored: errored };
|
return { completedSynchronously: true };
|
||||||
|
|
||||||
function onException(e) {
|
function onException(e) {
|
||||||
self.onException(e);
|
self.onException(e);
|
||||||
self.errored = errored = true;
|
self.recordError_(iterativeIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPromiseRejection(e) {
|
function onPromiseRejection(e) {
|
||||||
@@ -224,14 +223,12 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
if (!result.completedSynchronously) {
|
if (!result.completedSynchronously) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.errored = self.errored || result.errored;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clearStack(function() {
|
this.clearStack(function() {
|
||||||
self.globalErrors.popListener(self.handleFinalError);
|
self.globalErrors.popListener(self.handleFinalError);
|
||||||
|
|
||||||
if (self.errored) {
|
if (self.errored_) {
|
||||||
self.onComplete(new StopExecutionError());
|
self.onComplete(new StopExecutionError());
|
||||||
} else {
|
} else {
|
||||||
self.onComplete();
|
self.onComplete();
|
||||||
@@ -240,7 +237,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
QueueRunner.prototype.nextFnIx_ = function(currentFnIx) {
|
QueueRunner.prototype.nextFnIx_ = function(currentFnIx) {
|
||||||
const result = this.skipPolicy_.skipTo(currentFnIx, this.errored);
|
const result = this.skipPolicy_.skipTo(currentFnIx);
|
||||||
|
|
||||||
if (result === currentFnIx) {
|
if (result === currentFnIx) {
|
||||||
throw new Error("Can't skip to the same queueable fn that just finished");
|
throw new Error("Can't skip to the same queueable fn that just finished");
|
||||||
@@ -249,6 +246,11 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QueueRunner.prototype.recordError_ = function(currentFnIx) {
|
||||||
|
this.errored_ = true;
|
||||||
|
this.skipPolicy_.fnErrored(currentFnIx);
|
||||||
|
};
|
||||||
|
|
||||||
QueueRunner.prototype.diagnoseConflictingAsync_ = function(fn, retval) {
|
QueueRunner.prototype.diagnoseConflictingAsync_ = function(fn, retval) {
|
||||||
var msg;
|
var msg;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
getJasmineRequireObj().SkipAfterBeforeAllErrorPolicy = function(j$) {
|
||||||
|
function SkipAfterBeforeAllErrorPolicy(queueableFns, firstCleanupIx) {
|
||||||
|
this.queueableFns_ = queueableFns;
|
||||||
|
this.skipping_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SkipAfterBeforeAllErrorPolicy.prototype.skipTo = function(lastRanFnIx) {
|
||||||
|
if (this.skipping_) {
|
||||||
|
return this.nextAfterAllAfter_(lastRanFnIx);
|
||||||
|
} else {
|
||||||
|
return lastRanFnIx + 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SkipAfterBeforeAllErrorPolicy.prototype.nextAfterAllAfter_ = function(i) {
|
||||||
|
for (
|
||||||
|
i++;
|
||||||
|
i < this.queueableFns_.length &&
|
||||||
|
this.queueableFns_[i].type !== 'afterAll';
|
||||||
|
i++
|
||||||
|
) {}
|
||||||
|
return i;
|
||||||
|
};
|
||||||
|
|
||||||
|
SkipAfterBeforeAllErrorPolicy.prototype.fnErrored = function(fnIx) {
|
||||||
|
if (this.queueableFns_[fnIx].type === 'beforeAll') {
|
||||||
|
this.skipping_ = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return SkipAfterBeforeAllErrorPolicy;
|
||||||
|
};
|
||||||
@@ -253,7 +253,16 @@ getJasmineRequireObj().TreeProcessor = function() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return node.beforeAllFns.concat(result).concat(node.afterAllFns);
|
return node.beforeAllFns
|
||||||
|
.map(function(fn) {
|
||||||
|
return { type: 'beforeAll', ...fn };
|
||||||
|
})
|
||||||
|
.concat(result)
|
||||||
|
.concat(
|
||||||
|
node.afterAllFns.map(function(fn) {
|
||||||
|
return { type: 'afterAll', ...fn };
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ var getJasmineRequireObj = (function(jasmineGlobal) {
|
|||||||
j$.SetContaining = jRequire.SetContaining(j$);
|
j$.SetContaining = jRequire.SetContaining(j$);
|
||||||
j$.QueueRunner = jRequire.QueueRunner(j$);
|
j$.QueueRunner = jRequire.QueueRunner(j$);
|
||||||
j$.NeverSkipPolicy = jRequire.NeverSkipPolicy(j$);
|
j$.NeverSkipPolicy = jRequire.NeverSkipPolicy(j$);
|
||||||
|
j$.SkipAfterBeforeAllErrorPolicy = jRequire.SkipAfterBeforeAllErrorPolicy(
|
||||||
|
j$
|
||||||
|
);
|
||||||
j$.CompleteOnFirstErrorSkipPolicy = jRequire.CompleteOnFirstErrorSkipPolicy(
|
j$.CompleteOnFirstErrorSkipPolicy = jRequire.CompleteOnFirstErrorSkipPolicy(
|
||||||
j$
|
j$
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user