Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Refactored gulpfile to perform end-to-end tests locally, remotely and…
Browse files Browse the repository at this point in the history
… remotely from travis-ci.
  • Loading branch information
Mark Jones authored and hmdhk committed Jul 5, 2016
1 parent 31649cc commit dc33d00
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 63 deletions.
3 changes: 3 additions & 0 deletions e2e_test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
"angular-route": "^1.4.9",
"angular-ui-router": "^0.2.18",
"babel": "^6.5.1",
"error-stack-parser": "^1.3.5",
"loglevel": "^1.4.0",
"requirejs": "^2.1.22",
"stack-generator": "^1.0.7",
"stackframe": "^1.0.2",
"systemjs": "^0.19.20",
"traceur": "0.0.102",
"zone.js": "^0.5.15"
Expand Down
106 changes: 48 additions & 58 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,75 +202,60 @@ gulp.task('test', function (done) {
}, done).start()
})


// Run end-to-end tests on the local machine using webdriver configuration
gulp.task('test:e2e', function (done) {
var stream = gulp.src('wdio.conf.js').pipe(webdriver({
user: 'opbeat',
key: 'de42e589-1450-41a2-8a44-90aa00c15168',
host: 'ondemand.saucelabs.com',
port: 80,
baseUrl: 'http://localhost:8000'
}))

stream.on('error', function () {
return process.exit(1)
})
done()
gulp.src('wdio.conf.js')
.pipe(webdriver())
.on('error', function () {
return process.exit(1)
})
.on('end', function () {
return process.exit(0)
})
})

// Run end-to-end tests remotely in saucelabs using webdriver configuration
gulp.task('test:e2e:sauceconnect', function () {
return gulp.src('wdio.conf.js')
.pipe(webdriver({
user: 'opbeat',
key: 'de42e589-1450-41a2-8a44-90aa00c15168',
host: 'ondemand.saucelabs.com',
port: 80,
baseUrl: 'http://localhost:8000'
}))
.on('error', function () {
console.log('Exiting process with status 1')
process.exit(1)
})
.on('end', function () {
console.log('Tests complete')
})
})

gulp.task('test.sauce.start', function (done) {
// Launch sauce connect and connect
gulp.task('test:e2e:launchsauceconnect', function (done) {
var sauceConnectLauncher = require('sauce-connect-launcher')

sauceConnectLauncher({
username: 'opbeat',
accessKey: 'de42e589-1450-41a2-8a44-90aa00c15168'
accessKey: 'de42e589-1450-41a2-8a44-90aa00c15168',
logger: console.log
}, function (err, sauceConnectProcess) {
if (err) {
console.error(err.message)
return
return process.exit(1)
}

console.log('Sauce Connect ready')

// sauceConnectProcess.close(function () {
// console.log('Closed Sauce Connect process')
// })
done()
})
})

gulp.task('test.e2e.sauce', function (done) {
var capabilities = [
{
browserName: 'chrome'
},
{
browserName: 'internet explorer'
}
]

// if the e2e assets are available online
var extraConfig = {
user: 'opbeat',
key: 'de42e589-1450-41a2-8a44-90aa00c15168',
host: 'ondemand.saucelabs.com',
port: 80,
baseUrl: 'http://10.0.1.152:8000',
}

var sauceConnectConfig = {
host: '127.0.0.1',
port: 4445,
user: 'opbeat',
key: 'de42e589-1450-41a2-8a44-90aa00c15168',
capabilities: capabilities
}
var stream = gulp.src('wdio.conf.js').pipe(webdriver(sauceConnectConfig))

stream.on('error', function () { })
done()
})

gulp.task('e2e-serve', function (done) {
connect.server({
// Serve test application
gulp.task('test:e2e:serve', function () {
return connect.server({
root: ['e2e_test', 'src', './'],
port: 8000,
livereload: false,
Expand All @@ -281,20 +266,25 @@ gulp.task('e2e-serve', function (done) {
return middlewares
}
})
done()
})

gulp.task('selenium-start', function (done) {
// Install and start selenium
gulp.task('test:e2e:selenium', function (done) {
selenium.install({ logger: console.log }, function () {
selenium.start(function () {
done()
})
})
})

gulp.task('e2e-start', ['e2e-serve', 'selenium-start'])
gulp.task('e2e-sauce-start', ['e2e-serve', 'test.sauce.start'])
gulp.task('e2e-travis', ['build', 'e2e-serve', 'test:e2e'])
// Run all required tasks to perform remote end-to-end testing
gulp.task('test:e2e:start', function (done) {
runSequence('build', 'test:e2e:serve', 'test:e2e:launchsauceconnect', 'test:e2e:sauceconnect', function () {
console.log('All tasks completed.')
done()
process.exit(0)
});
})

gulp.task('watch:e2e', ['e2e-serve', 'selenium-start'], function (done) {
gulp.watch(['e2e_test/**'], function () {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "src/opbeat.js",
"scripts": {
"build": "gulp build:release",
"test": "node node_modules/standard/bin/cmd.js src/**/* && gulp test && gulp e2e-travis",
"test": "node node_modules/standard/bin/cmd.js src/**/* && gulp test && gulp test:e2e:start",
"prepublish": "npm run build"
},
"files": [
Expand All @@ -26,6 +26,7 @@
"es6-promise": "^3.0.2",
"event-stream": "^3.3.1",
"loglevel": "^1.4.0",
"sauce-connect-launcher": "^0.14.0",
"simple-lru-cache": "0.0.2",
"stack-generator": "^1.0.7",
"zone.js": "^0.5.15"
Expand Down Expand Up @@ -82,4 +83,4 @@
"xdescribe"
]
}
}
}
9 changes: 6 additions & 3 deletions wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ exports.config = {
{
maxInstances: 1,
browserName: 'chrome',
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
before: function () {
browser.timeoutsAsyncScript(30000)
}
}
// {
// maxInstances: 1,
Expand Down Expand Up @@ -154,8 +157,8 @@ exports.config = {
// Gets executed before test execution begins. At this point you will have access to all global
// variables like `browser`. It is the perfect place to define custom commands.
before: function () {
browser.timeoutsAsyncScript(15000)
// do something
// do something
browser.timeoutsAsyncScript(30000)
},
//
// Gets executed after all tests are done. You still have access to all global variables from
Expand Down

0 comments on commit dc33d00

Please sign in to comment.