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);
}
it('respects noSessionReuse in watch mode', function () {
var wd = require('xolvio-sync-webdriverio');
var SessionManager = require('../lib/session-manager');
wd.remote = jest.genMockFn().
mockReturnValueOnce('return from remote1').
mockReturnValueOnce('return from remote2');
var sessionManager = new SessionManager({port: 1234, browser: 'something'});
sessionManager._waitForConnection = jest.genMockFn().mockImpl(function (browser, callback) {
callback();
});
var options = {some: 'options'};
process.env['chimp.watch'] = true;
process.env['chimp.noSessionReuse'] = true;
var callback = jest.genMockFn();
sessionManager.remote(options, callback);
sessionManager.remote(options, callback);
expect(callback.mock.calls[0][1]).toBe('return from remote1');
expect(callback.mock.calls[1][1]).toBe('return from remote2');
expect(callback.mock.calls[0][1].requestHandler).toBeFalsy();
expect(callback.mock.calls[1][1].requestHandler).toBeFalsy();
expect(wd.remote.mock.calls.length).toBe(2);
expect(wd.remote.mock.calls[0][0]).toBe(options);
expect(wd.remote.mock.calls[1][0]).toBe(options);
});
beforeEach(function () {
delete process.env['chimp.noSessionReuse'];
delete process.env['chimp.watch'];
});
glob = require('glob'),
ui = require('./mocha-fiberized-ui');
import {parseBoolean, parseNullableString, parseString} from '../environment-variable-parsers';
import escapeRegExp from '../utils/escape-reg-exp';
var mochaOptions = {
ui: 'fiberized-bdd-ui',
timeout: process.env['chimp.mochaTimeout'],
slow: process.env['chimp.mochaSlow'],
reporter: process.env['chimp.mochaReporter']
};
var mochaGrep = parseNullableString(process.env['chimp.mochaGrep']);
if (parseBoolean(process.env['chimp.watch'])) {
mochaOptions.grep = new RegExp(parseString(process.env['chimp.watchTags']).split(',').map(escapeRegExp).join('|'));
} else if (mochaGrep) {
mochaOptions.grep = mochaGrep;
} else {
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);
deviceName: (0, _environmentVariableParsers.parseNullableString)(process.env['chimp.deviceName'])
},
user: (0, _environmentVariableParsers.parseNullableString)(process.env['chimp.user'] || process.env.SAUCE_USERNAME),
key: (0, _environmentVariableParsers.parseNullableString)(process.env['chimp.key'] || process.env.SAUCE_ACCESS_KEY),
host: (0, _environmentVariableParsers.parseNullableString)(process.env['chimp.host']),
port: (0, _environmentVariableParsers.parseNullableInteger)(process.env['chimp.port']),
logLevel: booleanHelper.isTruthy(process.env['chimp.debug']) ? 'verbose' : webdriverioConfigOptions.logLevel,
sync: (0, _environmentVariableParsers.parseBoolean)(process.env['chimp.sync'])
});
global.sessionManager = new SessionFactory((0, _assign2.default)(_.pick(webdriverioOptions, 'host', 'port', 'user', 'key'), {
browser: webdriverioOptions.desiredCapabilities.browserName,
deviceName: webdriverioOptions.desiredCapabilities.deviceName
}));
if (booleanHelper.isTruthy(process.env['chimp.watch'])) {
webdriverioOptions.desiredCapabilities.applicationCacheEnabled = false;
}
log.debug('[chimp][helper] webdriverioOptions are ', (0, _stringify2.default)(webdriverioOptions));
var remoteSession = void 0;
if ((0, _environmentVariableParsers.parseNullableInteger)(process.env['CUCUMBER_BROWSERS'])) {
var options = _.clone(webdriverioOptions);
options.multiBrowser = true;
var multiremoteWebdriverIoOptions = {};
var _browsersTotal = (0, _environmentVariableParsers.parseNullableInteger)(process.env['CUCUMBER_BROWSERS']);
for (var _browserIndex = 0; _browserIndex < _browsersTotal; _browserIndex++) {
multiremoteWebdriverIoOptions['browser' + _browserIndex] = _.clone(options);
}
remoteSession = wrapAsync(global.sessionManager.multiremote, global.sessionManager);
global.browser = remoteSession(multiremoteWebdriverIoOptions);
} else {
port: parseNullableInteger(process.env['chimp.port']),
logLevel: booleanHelper.isTruthy(process.env['chimp.debug']) ?
'verbose' : webdriverioConfigOptions.logLevel,
sync: parseBoolean(process.env['chimp.sync']),
}
);
global.sessionManager = new SessionFactory(Object.assign(
_.pick(webdriverioOptions, 'host', 'port', 'user', 'key'),
{
browser: webdriverioOptions.desiredCapabilities.browserName,
deviceName: webdriverioOptions.desiredCapabilities.deviceName,
}
));
if (booleanHelper.isTruthy(process.env['chimp.watch'])) {
webdriverioOptions.desiredCapabilities.applicationCacheEnabled = false;
}
log.debug('[chimp][helper] webdriverioOptions are ', JSON.stringify(webdriverioOptions));
let remoteSession;
if (parseNullableInteger(process.env['CUCUMBER_BROWSERS'])) {
var options = _.clone(webdriverioOptions);
options.multiBrowser = true;
const multiremoteWebdriverIoOptions = {};
var _browsersTotal = parseNullableInteger(process.env['CUCUMBER_BROWSERS']);
for (var _browserIndex = 0; _browserIndex < _browsersTotal; _browserIndex++) {
multiremoteWebdriverIoOptions['browser' + _browserIndex] = _.clone(options);
}
remoteSession = wrapAsync(global.sessionManager.multiremote, global.sessionManager);
global.browser = remoteSession(multiremoteWebdriverIoOptions);