Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var Mocha = require('mocha'),
fs = require('fs'),
path = require('path'),
exit = require('exit'),
glob = require('glob'),
ui = require('./mocha-fiberized-ui');
var mochaOptions = {
ui: 'fiberized-bdd-ui',
timeout: process.env['chimp.mochaTimeout'],
slow: process.env['chimp.mochaSlow'],
reporter: process.env['chimp.mochaReporter']
};
if ((0, _environmentVariableParsers.parseBoolean)(process.env['chimp.watch'])) {
mochaOptions.grep = new RegExp((0, _environmentVariableParsers.parseString)(process.env['chimp.watchTags']).split(',').map(_escapeRegExp2.default).join('|'));
} else {
mochaOptions.grep = new RegExp((0, _environmentVariableParsers.parseString)(process.env['chimp.mochaTags']).split(',').map(_escapeRegExp2.default).join('|'));
}
var mocha = new Mocha(mochaOptions);
mocha.addFile(path.join(path.resolve(__dirname, path.join('mocha-helper.js'))));
if (process.argv.length > 3) {
process.argv.splice(3).forEach(function (spec) {
mocha.addFile(spec);
});
} else {
// Add each .js file to the mocha instance
var testDir = process.env['chimp.path'];
process.chdir(testsDir);
const Jasmine = require('jasmine');
const jasmine = new Jasmine();
// Capability to add multiple spec filters
const specFilters = [];
jasmine.env.specFilter = function shouldRunSpec(spec) {
return _.every(specFilters, specFilter => specFilter(spec));
};
jasmine.jasmine.addSpecFilter = function addSpecFilter(filterFn) {
specFilters.push(filterFn);
};
if (parseBoolean(process.env['chimp.watch'])) {
// Only run specs with a watch tag in watch mode
const watchedSpecRegExp = new RegExp(
parseString(process.env['chimp.watchTags']).split(',').map(escapeRegExp).join('|')
);
jasmine.jasmine.addSpecFilter((spec) => watchedSpecRegExp.test(spec.getFullName()));
}
// Capability to capture screenshots
jasmine.jasmine.getEnv().addReporter({
specDone: function(result) {
if (screenshotHelper.shouldTakeScreenshot(result.status)) {
if (booleanHelper.isTruthy(process.env['chimp.saveScreenshotsToDisk'])) {
const affix = result.status !== 'passed' ? ' (failed)' : '';
const fileName = result.fullName + affix;
screenshotHelper.saveScreenshotsToDisk(fileName, projectDir);
}
loadAssertionLibrary: function loadAssertionLibrary() {
if (booleanHelper.isTruthy(process.env['chimp.chai'])) {
log.debug('[chimp][helper] Using the chai-expect assertion library');
chai.use(chaiAsPromised);
chai.should();
// give users access to the chai instance
global.chai = chai;
global.expect = chai.expect;
global.assert = chai.assert;
} else {
log.debug('[chimp][helper] Using the jasmine-expect assertion library');
global.expect = require('xolvio-jasmine-expect').expect;
}
},
loadAssertionLibrary: function () {
if (booleanHelper.isTruthy(process.env['chimp.chai'])) {
log.debug('[chimp][helper] Using the chai-expect assertion library');
chai.use(chaiAsPromised);
chai.should();
// give users access to the chai instance
global.chai = chai;
global.expect = chai.expect;
global.assert = chai.assert;
} else {
log.debug('[chimp][helper] Using the jasmine-expect assertion library');
global.expect = require('xolvio-jasmine-expect').expect;
}
},
mochaOptions.grep = new RegExp(
parseString(process.env['chimp.mochaTags']).split(',').map(escapeRegExp).join('|')
);
}
var mocha = new Mocha(mochaOptions);
mocha.addFile(path.join(path.resolve(__dirname, path.join('mocha-helper.js'))));
if (process.argv.length > 3) {
process.argv.splice(3).forEach(function (spec) {
mocha.addFile(spec);
});
} else {
// Add each .js file to the mocha instance
var testDir = process.env['chimp.path'];
glob.sync(path.join(testDir, '**')).filter(function (file) {
// Only keep the .js files
return file.substr(-3) === '.js';
}).forEach(function (file) {
mocha.addFile(file);
});
}
try {
// Run the tests.
mocha.run(function (failures) {
exit(failures);
});
} catch (e) {
throw (e);
}
mochaOptions.grep = new RegExp((0, _environmentVariableParsers.parseString)(process.env['chimp.watchTags']).split(',').map(_escapeRegExp2.default).join('|'));
} else {
mochaOptions.grep = new RegExp((0, _environmentVariableParsers.parseString)(process.env['chimp.mochaTags']).split(',').map(_escapeRegExp2.default).join('|'));
}
var mocha = new Mocha(mochaOptions);
mocha.addFile(path.join(path.resolve(__dirname, path.join('mocha-helper.js'))));
if (process.argv.length > 3) {
process.argv.splice(3).forEach(function (spec) {
mocha.addFile(spec);
});
} else {
// Add each .js file to the mocha instance
var testDir = process.env['chimp.path'];
glob.sync(path.join(testDir, '**')).filter(function (file) {
// Only keep the .js files
return file.substr(-3) === '.js';
}).forEach(function (file) {
mocha.addFile(file);
});
}
try {
// Run the tests.
mocha.run(function (failures) {
exit(failures);
});
} catch (e) {
throw e;
}
(function () {
// Only run specs with a watch tag in watch mode
var watchedSpecRegExp = new RegExp((0, _environmentVariableParsers.parseString)(process.env['chimp.watchTags']).split(',').map(_escapeRegExp2.default).join('|'));
jasmine.jasmine.addSpecFilter(function (spec) {
return watchedSpecRegExp.test(spec.getFullName());
});
})();
}
var Mocha = require('mocha'),
fs = require('fs'),
path = require('path'),
exit = require('exit'),
glob = require('glob'),
ui = require('./mocha-fiberized-ui');
var mochaOptions = {
ui: 'fiberized-bdd-ui',
timeout: process.env['chimp.mochaTimeout'],
slow: process.env['chimp.mochaSlow'],
reporter: process.env['chimp.mochaReporter']
};
if ((0, _environmentVariableParsers.parseBoolean)(process.env['chimp.watch'])) {
mochaOptions.grep = new RegExp((0, _environmentVariableParsers.parseString)(process.env['chimp.watchTags']).split(',').map(_escapeRegExp2.default).join('|'));
} else {
mochaOptions.grep = new RegExp((0, _environmentVariableParsers.parseString)(process.env['chimp.mochaTags']).split(',').map(_escapeRegExp2.default).join('|'));
}
var mocha = new Mocha(mochaOptions);
mocha.addFile(path.join(path.resolve(__dirname, path.join('mocha-helper.js'))));
if (process.argv.length > 3) {
process.argv.splice(3).forEach(function (spec) {
mocha.addFile(spec);
});
} else {
// Add each .js file to the mocha instance
var testDir = process.env['chimp.path'];
glob.sync(path.join(testDir, '**')).filter(function (file) {
const jasmine = new Jasmine();
// Capability to add multiple spec filters
const specFilters = [];
jasmine.env.specFilter = function shouldRunSpec(spec) {
return _.every(specFilters, specFilter => specFilter(spec));
};
jasmine.jasmine.addSpecFilter = function addSpecFilter(filterFn) {
specFilters.push(filterFn);
};
if (parseBoolean(process.env['chimp.watch'])) {
// Only run specs with a watch tag in watch mode
const watchedSpecRegExp = new RegExp(
parseString(process.env['chimp.watchTags']).split(',').map(escapeRegExp).join('|')
);
jasmine.jasmine.addSpecFilter((spec) => watchedSpecRegExp.test(spec.getFullName()));
}
// Capability to capture screenshots
jasmine.jasmine.getEnv().addReporter({
specDone: function(result) {
if (screenshotHelper.shouldTakeScreenshot(result.status)) {
if (booleanHelper.isTruthy(process.env['chimp.saveScreenshotsToDisk'])) {
const affix = result.status !== 'passed' ? ' (failed)' : '';
const fileName = result.fullName + affix;
screenshotHelper.saveScreenshotsToDisk(fileName, projectDir);
}
}
}
});
if (!this.options.domainOnly) {
if (this.options.browser === 'phantomjs') {
process.env['chimp.host'] = this.options.host = 'localhost';
var phantom = new exports.Phantom(this.options);
processes.push(phantom);
}
else if (userHasProvidedBrowser() && userHasNotProvidedSeleniumHost()) {
process.env['chimp.host'] = this.options.host = 'localhost';
var selenium = new exports.Selenium(this.options);
processes.push(selenium);
}
else if (userHasNotProvidedSeleniumHost()) {
// rewrite the browser to be chrome since "chromedriver" is not a valid browser
process.env['chimp.browser'] = this.options.browser = 'chrome';
process.env['chimp.host'] = this.options.host = 'localhost';
var chromedriver = new exports.Chromedriver(this.options);
processes.push(chromedriver);
}
}
if (booleanHelper.isTruthy(this.options.mocha)) {
var mocha = new exports.Mocha(this.options);
processes.push(mocha);
} else if (booleanHelper.isTruthy(this.options.jasmine)) {
const jasmine = new exports.Jasmine(this.options);
processes.push(jasmine);
} else {
if (booleanHelper.isTruthy(this.options.e2eSteps) || booleanHelper.isTruthy(this.options.domainSteps)) {
// domain scenarios
if (booleanHelper.isTruthy(this.options.domainSteps)) {