Skip to content

Commit 7128628

Browse files
aslushnikovJoelEinbinder
authored andcommitted
feat(testrunner): ability to repeat test suites (#681)
Now you can `fdescribe.repeat(10)` to repeat test suites.
1 parent 541fa95 commit 7128628

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

utils/testrunner/TestRunner.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,20 +322,30 @@ class TestRunner extends EventEmitter {
322322
}
323323
}
324324

325+
const duplicateTest = (amount, mode, timeout) => {
326+
return (name, callback) => {
327+
for (let i = 0; i < amount; ++i)
328+
this._addTest(name, callback, mode, timeout);
329+
}
330+
}
331+
332+
const duplicateSuite = (amount, mode) => {
333+
return (name, callback, ...args) => {
334+
for (let i = 0; i < amount; ++i)
335+
this._addSuite(mode, name, callback, ...args);
336+
}
337+
}
338+
325339
// bind methods so that they can be used as a DSL.
326340
this.describe = this._addSuite.bind(this, TestMode.Run);
327341
this.describe.skip = condition => condition ? this.xdescribe : this.describe;
342+
this.describe.repeat = number => duplicateSuite(number, TestMode.Run);
328343
this.fdescribe = this._addSuite.bind(this, TestMode.Focus);
329344
this.fdescribe.skip = () => this.fdescribe; // no-op
345+
this.fdescribe.repeat = number => duplicateSuite(number, TestMode.Focus);
330346
this.xdescribe = this._addSuite.bind(this, TestMode.Skip);
331347
this.xdescribe.skip = () => this.xdescribe; // no-op
332-
333-
const duplicateTest = (amount, mode, timeout) => {
334-
return (name, callback) => {
335-
for (let i = 0; i < amount; ++i)
336-
this._addTest(name, callback, mode, timeout);
337-
}
338-
}
348+
this.xdescribe.repeat = number => duplicateSuite(number, TestMode.Skip);
339349

340350
this.it = (name, callback) => void this._addTest(name, callback, TestMode.Run, this._timeout);
341351
this.it.skip = condition => condition ? this.xit : this.it;

0 commit comments

Comments
 (0)