Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (dependencies.getDependency('babel-core')) {
mochaConfig.compilers = {
js: require('babel-core/register')
};
}
//
// Mocha spec loading can fail during mocha initialization. If path.resolve
// fails for some reason, you get a stack trace, but it's totally useless
// because it doesn't tell you which spec file was the source of the resolve
// error. The following code patches that.
//
var MochaConstructor = require('mocha');
if (MochaConstructor.prototype.loadFiles && !MochaConstructor.__jenkinsLoadfilesWrapped) {
var path = require('path');
MochaConstructor.prototype.loadFiles = function(fn) {
var self = this;
var suite = this.suite;
this.files.forEach(function(file) {
try {
file = path.resolve(file);
suite.emit('pre-require', global, file, self);
suite.emit('require', require(file), file, self);
suite.emit('post-require', global, file, self);
} catch(e) {
logger.logError('*****************************************************************');
logger.logError('Mocha test initialization failure. Failed to load spec file "' + file + '". Tests will not run. See stack trace below.');
logger.logError('*****************************************************************');
throw e;
}
});
fn && fn();
return amountParse.call(this, j);
}
var accountParse = ripplelib.UInt160.prototype.parse_json;
ripplelib.UInt160.prototype.parse_json = function(j) {
if (config.accounts[j]) {
j = config.accounts[j].account;
}
return accountParse.call(this, j);
}
var oldLoader = mocha.prototype.loadFiles
if (!oldLoader.monkeyPatched) {
// Gee thanks Mocha ...
mocha.prototype.loadFiles = function() {
try {
oldLoader.apply(this, arguments);
} catch (e) {
// Normally mocha just silently bails
console.error(e.stack);
// We throw, so mocha doesn't continue trying to run the test suite
throw e;
}
}
mocha.prototype.loadFiles.monkeyPatched = true;
};
var oldLoader = mocha.prototype.loadFiles
if (!oldLoader.monkeyPatched) {
// Gee thanks Mocha ...
mocha.prototype.loadFiles = function() {
try {
oldLoader.apply(this, arguments);
} catch (e) {
// Normally mocha just silently bails
console.error(e.stack);
// We throw, so mocha doesn't continue trying to run the test suite
throw e;
}
}
mocha.prototype.loadFiles.monkeyPatched = true;
};
var mochaConfig = {};
if (dependencies.getDependency('babel-core')) {
mochaConfig.compilers = {
js: require('babel-core/register')
};
}
//
// Mocha spec loading can fail during mocha initialization. If path.resolve
// fails for some reason, you get a stack trace, but it's totally useless
// because it doesn't tell you which spec file was the source of the resolve
// error. The following code patches that.
//
var MochaConstructor = require('mocha');
if (MochaConstructor.prototype.loadFiles && !MochaConstructor.__jenkinsLoadfilesWrapped) {
var path = require('path');
MochaConstructor.prototype.loadFiles = function(fn) {
var self = this;
var suite = this.suite;
this.files.forEach(function(file) {
try {
file = path.resolve(file);
suite.emit('pre-require', global, file, self);
suite.emit('require', require(file), file, self);
suite.emit('post-require', global, file, self);
} catch(e) {
logger.logError('*****************************************************************');
logger.logError('Mocha test initialization failure. Failed to load spec file "' + file + '". Tests will not run. See stack trace below.');
logger.logError('*****************************************************************');
throw e;
}
j = String(Math.floor(parseFloat(j, 10) * 1e6));
}
}
return amountParse.call(this, j);
}
var accountParse = ripplelib.UInt160.prototype.parse_json;
ripplelib.UInt160.prototype.parse_json = function(j) {
if (config.accounts[j]) {
j = config.accounts[j].account;
}
return accountParse.call(this, j);
}
var oldLoader = mocha.prototype.loadFiles
if (!oldLoader.monkeyPatched) {
// Gee thanks Mocha ...
mocha.prototype.loadFiles = function() {
try {
oldLoader.apply(this, arguments);
} catch (e) {
// Normally mocha just silently bails
console.error(e.stack);
// We throw, so mocha doesn't continue trying to run the test suite
throw e;
}
}
mocha.prototype.loadFiles.monkeyPatched = true;
};
runTests({
options: Object.assign({}, {
reporterName: this._reporterName,
reporterOptions: this._reporterOptions,
reporter: Reporter,
testsLength: this._filesTotal
}),
throttledCalls: this._throttledCalls
});
return this._customRunner;
}
}
Object.keys(Mocha.prototype).forEach(key => {
if (typeof Mocha.prototype[key] !== 'function') {
return;
}
// we have our own implementations of these methods
// other methods should be saved and re-applied during runTests()
if (key === 'run' || key === 'addFile' || key === 'reporter') {
return;
}
MochaParallelTests.prototype[key] = function (...args) {
// mocha calls some of its methods inside constructor
// so MochaParallelTests own constructor function can still be in progress here
this._throttledCalls = this._throttledCalls || [];
this._throttledCalls.push({
function prepare(onPrepare, onUnprepare) {
// Monkey-patch run method
var Mocha = require('mocha');
var run = Mocha.prototype.run;
Mocha.prototype.run = function (done) {
var self = this;
// Call onPrepare() before the actual run().
onPrepare(function (err) {
if (err) {
if (err instanceof Error) {
console.error(err.stack);
}
process.exit(1);
done(); // unreachable. test purpose only.
} else {
// Call the actual run().
run.call(self, function () {
// All test complete with a result code.
// Pass forward the arugments for possible spec change
// in the future.
var thisArg = this;
function prepare(onPrepare, onUnprepare) {
// Monkey-patch run method
var Mocha = require('mocha');
var run = Mocha.prototype.run;
Mocha.prototype.run = function (done) {
var self = this;
// Call onPrepare() before the actual run().
onPrepare(function (err) {
if (err) {
if (err instanceof Error) {
console.error(err.stack);
}
process.exit(1);
done(); // unreachable. test purpose only.
} else {
// Call the actual run().
run.call(self, function () {
// All test complete with a result code.
// Pass forward the arugments for possible spec change
global.should = chai.should();
chai.use(sinonChai);
chai.use(require('chai-properties'));
var sinon = require('sinon');
sinon.config = {
injectIntoThis: true,
injectInto: null,
properties: ['spy', 'stub', 'mock', 'clock', 'sandbox', 'server', 'requests', 'on'],
useFakeTimers: [10],
useFakeServer: true
};
var loadFiles = Mocha.prototype.loadFiles;
Mocha.prototype.loadFiles = function() {
this.suite.beforeEach(function() {
var config = sinon.getConfig(sinon.config);
config.injectInto = this;
this.sandbox = sinon.sandbox.create(config);
});
this.suite.afterEach(function() {
this.clock.tick(1000);
this.sandbox.verifyAndRestore();
});
return loadFiles.apply(this);
};
global.should = chai.should();
chai.use(sinonChai);
chai.use(require('chai-properties'));
var sinon = require('sinon');
sinon.config = {
injectIntoThis: true,
injectInto: null,
properties: ['spy', 'stub', 'mock', 'clock', 'sandbox', 'server', 'requests', 'on'],
useFakeTimers: [10],
useFakeServer: true
};
var loadFiles = Mocha.prototype.loadFiles;
Mocha.prototype.loadFiles = function() {
this.suite.beforeEach(function() {
var config = sinon.getConfig(sinon.config);
config.injectInto = this;
this.sandbox = sinon.sandbox.create(config);
});
this.suite.afterEach(function() {
this.clock.tick(1000);
this.sandbox.verifyAndRestore();
});
return loadFiles.apply(this);
};