
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
mocha-repeat
Advanced tools
Loop tests through diferrent variations of data in mocha.js. Perfect for testing against multiple versions of 3rd-party libraries.
var mdescribe = require('mocha-repeat');
var libs = {
'jquery-1.9': require('../vendor/jquery-1.9.js'),
'jquery-2.0': require('../vendor/jquery-2.0.js'),
'jquery-2.1': require('../vendor/jquery-2.1.js'),
};
mdescribe("Tests", libs, function (jQuery) {
/* ..tests.. */
});
This will be expanded to:
describe("Tests (jquery-1.9)", function () {
var jQuery = require('../vendor/jquery-1.9.js');
/* ..tests.. */
});
describe("Tests (jquery-2.0)", function () {
var jQuery = require('../vendor/jquery-2.0.js');
/* ..tests.. */
});
describe("Tests (jquery-2.1)", function () {
var jQuery = require('../vendor/jquery-2.0.js');
/* ..tests.. */
});
$ npm i --save-dev mocha-repeat
This effect is easily achievable in plain JavaScript, though the resulting code will be more verbose.
libs = { ... };
for (var version in libs) {
if (libs.hasOwnProperty(version)) {
var jQuery = libs[version];
(function (jQuery, version) {
describe("Test (" + version + ")", function () {
/* ..tests.. */
});
})(jQuery, version);
}
}
It's easier to write it this way:
libs = { ... };
mdescribe("Test", libs, function (jQuery, version) {
/* ..tests.. */
});
If the values are arrays, they will be spread across the function's arguments.
In this example, the function's 2 arguments (jQuery, options) will be
populated by the array items.
var libs = {
'jquery-1.9': [ require('../vendor/jquery-1.9.js'), { legacy: true } ],
'jquery-2.0': [ require('../vendor/jquery-2.0.js'), { } ],
'jquery-2.1': [ require('../vendor/jquery-2.1.js'), { future: true } ],
};
mdescribe("Tests", stubs, function (jQuery, options) {
if (options.legacy) {
}
});
You can nest calls to mocha-repeat. This is great for testing combinations of multiple library versions. In this example, it tests against every possble combination of underscore [1.0..1.2] with backbone [1.0..1.2].
var libs = {
underscore: {
'1.0': '../vendor/underscore/1.0.0.js',
'1.1': '../vendor/underscore/1.1.0.js',
'1.2': '../vendor/underscore/1.2.0.js',
},
backbone: {
'1.0': '../vendor/backbone/1.0.0.js',
'1.1': '../vendor/backbone/1.1.0.js',
'1.2': '../vendor/backbone/1.2.0.js',
},
};
var _, Backbone;
mdescribe("Underscore", libs.underscore, function (upath) {
mdescribe("Backbone", libs.backbone, function (bpath) {
// load the libraries
// ...tip: https://www.npmjs.org/package/proxyquire
before(function () {
_ = require(upath);
Backbone = proxyquire(bpath, { underscore: _ });
});
it ('loads without errors', function () {
expect(_).is.a('function');
expect(Backbone).is.a('object');
});
});
})
Output:
$ mocha -R list
. Underscore (1.0) Backbone (1.0) loads without errors
. Underscore (1.0) Backbone (1.1) loads without errors
. Underscore (1.0) Backbone (1.2) loads without errors
. Underscore (1.1) Backbone (1.0) loads without errors
. Underscore (1.1) Backbone (1.1) loads without errors
. Underscore (1.1) Backbone (1.2) loads without errors
. Underscore (1.2) Backbone (1.0) loads without errors
. Underscore (1.2) Backbone (1.1) loads without errors
. Underscore (1.2) Backbone (1.2) loads without errors
9 passing (120ms)
mocha-repeat © 2014+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).
ricostacruz.com · GitHub @rstacruz · Twitter @rstacruz
FAQs
Loop tests through diferrent variations of data.
We found that mocha-repeat demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.