Skip to content

Commit

Permalink
Update deps and work on tests (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
imurchie authored Apr 23, 2019
1 parent 9e06faf commit b77a002
Show file tree
Hide file tree
Showing 16 changed files with 1,190 additions and 778 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ env:
# - CONFIG=ipad
# - CONFIG=android_phone
script:
- "npx gulp travis --config $CONFIG --sauce"
- npx gulp travis --config $CONFIG --sauce
86 changes: 53 additions & 33 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ var gulp = require('gulp'),
mochaStream = require('spawn-mocha-parallel').mochaStream,
httpProxy = require('http-proxy'),
sauceConnectLauncher = require('sauce-connect-launcher'),
async = require('async');
async = require('async'),
log = require('fancy-log')
gulpIf = require('gulp-if')
debug = require('gulp-debug');

require('./test/helpers/env');


const VERBOSE = !!process.env.VERBOSE;

args.browsers = (args.browser || 'chrome').split(',');
args.sauce = args.sauce ? true : false;

Expand All @@ -26,14 +32,18 @@ process.env.SAUCE_CONNECT_VERBOSE = false;
var PROXY_PORT = 5050;
var expressPort = 3000; // incremented after each test to avoid colision

function buildMochaOpts(opts) {
var debugLog = log.bind(log);
var warnLog = log.warn.bind(log);
var errorLog = log.error.bind(log);

function buildMochaOpts(opts) {
var mochaOpts = {
flags: {
u: 'bdd-with-opts',
R: 'spec',
c: true
c: true,
},
exit: true,
bin: path.join(__dirname, 'node_modules/.bin/' + ((process.platform !== "win32") ? 'mocha' : 'mocha.cmd')),
concurrency: args.concurrency | process.env.CONCURRENCY || 3
};
Expand Down Expand Up @@ -81,36 +91,40 @@ gulp.task('test-unit', function () {
var opts = buildMochaOpts({ unit: true });
var mocha = mochaStream(opts);
return gulp.src('test/specs/**/*-specs.js', {read: false})
.pipe(gulpIf(VERBOSE, debug()))
.pipe(mocha)
.on('error', console.warn.bind(console));
.on('error', warnLog);
});

gulp.task('test-midway-multi', function () {
var opts = buildMochaOpts({ midway: true, browser: 'multi' });
var mocha = mochaStream(opts);
return gulp.src('test/midway/multi/**/*-specs.js', {
read: false})
.pipe(gulpIf(VERBOSE, debug()))
.pipe(mocha)
.on('error', console.warn.bind(console));
.on('error', warnLog);
});

_(BROWSERS).each(function(browser) {
gulp.task('test-midway-' + browser, function () {
var opts = buildMochaOpts({ midway: true, browser: browser });
var mocha = mochaStream(opts);
return gulp.src([
'test/midway/**/*-specs.js',
'!test/midway/multi/**'
], {read: false})
'test/midway/**/*-specs.js',
'!test/midway/multi/**'
], {read: false})
.pipe(gulpIf(VERBOSE, debug()))
.pipe(mocha)
.on('error', console.warn.bind(console));
.on('error', errorLog);
});
gulp.task('test-e2e-' + browser, function () {
var opts = buildMochaOpts({ browser: browser });
var mocha = mochaStream(opts);
return gulp.src('test/e2e/**/*-specs.js', {read: false})
.pipe(gulpIf(VERBOSE, debug()))
.pipe(mocha)
.on('error', console.warn.bind(console));
.on('error', errorLog);
});
});

Expand All @@ -123,8 +137,9 @@ _(MOBILE_BROWSERS).each(function (browser) {
'test/midway/api-exec-specs.js',
'test/midway/mobile-specs.js',
], {read: false})
.pipe(gulpIf(VERBOSE, debug()))
.pipe(mochaStream(opts))
.on('error', console.warn.bind(console));
.on('error', errorLog);
});
});

Expand Down Expand Up @@ -190,7 +205,7 @@ gulp.task('start-proxy', function(done) {
}
} catch (err) {
try{
console.error('Proxy error for: ', req.url + ':' , err);
log.error('Proxy error for: ', req.url + ':' , err);
res.writeHead(500, {
'Content-Type': 'text/plain'
});
Expand All @@ -200,26 +215,28 @@ gulp.task('start-proxy', function(done) {
});

server.on('error', function(err) {
console.error('Proxy error: ', err);
log.error('Proxy error: ', err);
});

console.log("listening on port", PROXY_PORT);
log("Listening on port", PROXY_PORT);
server.listen(PROXY_PORT, done);
});

gulp.task('stop-proxy', function(done) {
// stop proxy, exit after 5 ec if hanging
// stop proxy, exit after 5 sec if hanging
done = _.once(done);
var t = setTimeout(function() {
var timeout = setTimeout(function () {
done();
}, 5000);
if(server) {
server.close(function() {
clearTimeout(t);
if (server) {
server.close(function () {
clearTimeout(timeout);
done();
});
}
else { done(); }
else {
done();
}
});

var sauceConnectProcess = null;
Expand All @@ -230,27 +247,27 @@ gulp.task('start-sc', function (done) {
accessKey: process.env.SAUCE_ACCESS_KEY,
verbose: process.env.SAUCE_CONNECT_VERBOSE,
directDomains: 'cdnjs.cloudflare.com,html5shiv.googlecode.com',
logger: function(mess) {console.log(mess);}
logger: debugLog,
};
if(process.env.TRAVIS_JOB_NUMBER) {
if (process.env.TRAVIS_JOB_NUMBER) {
opts.tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER;
}
var startTunnel = function (done, n) {
sauceConnectLauncher(opts, function (err, _sauceConnectProcess) {
if (err) {
if(n > 0) {
console.log('retrying sauce connect in 20 secs.');
setTimeout(function() {
startTunnel(done, n-1);
if (n > 0) {
log('retrying sauce connect in 20 secs.');
setTimeout(function () {
startTunnel(done, n - 1);
}, 20000);
} else {
console.error(err.message);
log.error(err.message);
done(err);
}
return;
}
sauceConnectProcess = _sauceConnectProcess;
console.log("Sauce Connect ready");
log("Sauce Connect ready");
done();
});
};
Expand All @@ -259,21 +276,24 @@ gulp.task('start-sc', function (done) {
});

gulp.task('stop-sc', function (done) {
if(sauceConnectProcess) { sauceConnectProcess.close(done); }
else { done(); }
if(sauceConnectProcess) {
sauceConnectProcess.close(done);
} else {
done();
}
});

gulp.task('pre-midway', function() {
var seq = ['start-proxy'];
if(args.sauce && !args['nosc']) {
if (args.sauce && !args['nosc']) {
seq.unshift('start-sc');
}
return runSequence(seq);
});

gulp.task('post-midway', function() {
gulp.task('post-midway', function () {
var seq = ['stop-proxy'];
if(args.sauce && !args['nosc']) {
if (args.sauce && !args['nosc']) {
seq.unshift('stop-sc');
}
return runSequence(seq);
Expand Down
32 changes: 17 additions & 15 deletions lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,18 +993,17 @@ commands.waitForElement = function(){
* opts with the following fields: timeout, pollFreq, asserter.
* asserter like: function(element , cb) -> cb(err, satisfied, el)
*/
commands.waitForElements = function(){

commands.waitForElements = function (){
var cb = findCallback(arguments);
var fargs = utils.varargs(arguments);
var using = fargs.all[0],
value = fargs.all[1];
var opts;

// retrieving options
if(typeof fargs.all[2] === 'object' && !(fargs.all[2] instanceof Asserter)){
if (typeof fargs.all[2] === 'object' && !(fargs.all[2] instanceof Asserter)){
opts = fargs.all[2];
} else if(fargs.all[2] instanceof Asserter) {
} else if (fargs.all[2] instanceof Asserter) {
opts = {
asserter: fargs.all[2],
timeout: fargs.all[3],
Expand All @@ -1021,38 +1020,41 @@ commands.waitForElements = function(){
opts.asserter = opts.asserter || new Asserter(function(el, cb) { cb(null, true); });

var unpromisedAsserter = new Asserter(
function(el, cb) {
function (el, cb) {
var promise = opts.asserter.assert(el, cb);
if(promise && promise.then && typeof promise.then === 'function'){
if (promise && promise.then && typeof promise.then === 'function') {
promise.then(
function() { cb(null, true); },
function(err) {
if(err.retriable) { cb(null, false); }
else { throw err; }
if (err.retriable) {
cb(null, false);
} else {
cb(err);
}
}
);
}
}
);

var wrappedAsserter = new Asserter(
function(browser, cb){
function(browser, cb) {
browser.elements(using, value, function(err, els){
if(err) { return cb(err); }
if (err) { return cb(err); }
var seq = [];
var satisfiedEls = [];
_(els).each(function(el) {
seq.push(function(cb) {
_(els).each(function (el) {
seq.push(function (cb) {
unpromisedAsserter.assert(el, function(err, satisfied) {
if(err) { return cb(err); }
if(satisfied) { satisfiedEls.push(el); }
cb(err);
cb();
});
});
});
async.series(seq, function(err) {
if(err) { return cb(err); }
cb(err, satisfiedEls.length > 0 , satisfiedEls);
if(err) { return cb(err); }
cb(null, satisfiedEls.length > 0 , satisfiedEls);
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/promise-webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module.exports = function(WebDriver, Element, chainable) {
var _this = this;
// There are cases were enrich may be called on non-promise objects.
// It is easier and safer to check within the method.
if(utils.isPromise(obj) && !obj.__wd_promise_enriched) {
if (utils.isPromise(obj) && !obj.__wd_promise_enriched) {

var promise = obj;

Expand Down
Loading

0 comments on commit b77a002

Please sign in to comment.