feat(testrunner): ability to repeat test suites (#681)

Now you can `fdescribe.repeat(10)` to repeat test suites.
This commit is contained in:
Andrey Lushnikov 2020-01-27 12:48:11 -08:00 committed by Joel Einbinder
parent 541fa95ce4
commit 7128628d70

View file

@ -322,14 +322,6 @@ class TestRunner extends EventEmitter {
}
}
// bind methods so that they can be used as a DSL.
this.describe = this._addSuite.bind(this, TestMode.Run);
this.describe.skip = condition => condition ? this.xdescribe : this.describe;
this.fdescribe = this._addSuite.bind(this, TestMode.Focus);
this.fdescribe.skip = () => this.fdescribe; // no-op
this.xdescribe = this._addSuite.bind(this, TestMode.Skip);
this.xdescribe.skip = () => this.xdescribe; // no-op
const duplicateTest = (amount, mode, timeout) => {
return (name, callback) => {
for (let i = 0; i < amount; ++i)
@ -337,6 +329,24 @@ class TestRunner extends EventEmitter {
}
}
const duplicateSuite = (amount, mode) => {
return (name, callback, ...args) => {
for (let i = 0; i < amount; ++i)
this._addSuite(mode, name, callback, ...args);
}
}
// bind methods so that they can be used as a DSL.
this.describe = this._addSuite.bind(this, TestMode.Run);
this.describe.skip = condition => condition ? this.xdescribe : this.describe;
this.describe.repeat = number => duplicateSuite(number, TestMode.Run);
this.fdescribe = this._addSuite.bind(this, TestMode.Focus);
this.fdescribe.skip = () => this.fdescribe; // no-op
this.fdescribe.repeat = number => duplicateSuite(number, TestMode.Focus);
this.xdescribe = this._addSuite.bind(this, TestMode.Skip);
this.xdescribe.skip = () => this.xdescribe; // no-op
this.xdescribe.repeat = number => duplicateSuite(number, TestMode.Skip);
this.it = (name, callback) => void this._addTest(name, callback, TestMode.Run, this._timeout);
this.it.skip = condition => condition ? this.xit : this.it;
this.it.repeat = number => duplicateTest(number, TestMode.Run, this._timeout);