Skip to content

Commit

Permalink
integrate travis with saucelabs
Browse files Browse the repository at this point in the history
  • Loading branch information
qiu8310 committed Jun 22, 2015
1 parent 3b88614 commit 7400c19
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ coverage/
npm-debug.log
.DS_Store
.idea
sauce-connect.log
46 changes: 46 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
language: node_js
env:
matrix:
- CI=true TRAVIS=true

# global:
# - secure: RN0H1IlQVGU7GSdYVmpUJZdWQFyyDGZdZhfoLtjZOQLbGwPkw2ZNanij1DfXuSHPX/T+8/tURYiP3PgbyLif7Uiktyp/XecqYGaUCYpr491ovwV37DapzwAJeyKR9FTDgdRN0DT2x8BijLz8iIj+D+CcwnOs1udiqAuQ9FY8gyGefV/ubRt3hRS4vJyfaL/+yApKoFCxU8O9ktlR1Y29gsd8Y0zpateFPDXmIN6sHdDqiFrefqso2nUQL6R7Ow1cV++M+cNN4InDZfNte9qaZfEyJ0b/Fp3aHq/oKA2HdFdy6zNzjZBJ2kKp0VWXzILbtC/B1WU93QfGcEaQjY9KNwzcij/8nPZ0+h0xC6c146lnID5Wu7HFuZdds8cBThb/10FEBEMuK5uL7yJltHLFvyseB0PE2H139BS4ek4RtzP81P/CCVRQtzFlSz2U7YecRCyorLJ4UwX3pdbhEw0cTuppQ4KT8JL/kQ+IZiVZpHJ9TiMwe5lhxDsEU6WPT0WP/nLR0nin3P0GD9a4RCJb6ZLezHbHUZIOor+JkiV/xFfIOkOi46xJ3jowNk6F3GDc2NOkI0dopdGetr7gfwv0RebC2BI6Kna70FQzRQmGACo8Ritehk/E5DYQZsq26LGvPq7Mjbg0g6T6ln6uVmF5FlTu5wwzmtL2eCGNlLBawAs=
# - secure: IAN10TRpFdb8WrYz6jHmBO/UZmjREK5Wrx1bDV8JwV4vonJWNtu6GqtPtCx+4iQV8zkjpNk8RHu7+KpBV54o+1AoWGG16Tvk1nZ9E07iH3p+Cnd/RHM2Y0jKTggOJCEnoQwMDEuBZByVlMgjvOzwzLYi5l1eY1Blusa2Sw6TeGxct6QaelFFppk+6CYhHt7GE5urUrbfcsdJryc2PczeoPDOPVkZYaiLuYkvmS2XgHV2cbVfJ3sVrodbBW5WyHyO/yy2Bvf5gLlXORHkjlhCesOm3krc0nmmFqfYwqjQ/w3CIAihk+Kup6OU/EYUzY1sIVqcoVGWk1lXlblglBxE5PmVv3E9qx/IYXeorcqpx//w7WyPHl968BnFS1oLxGBj+0RG2avFJAjSdqlhix6fz/wOt0NzJjRgRfCHlSc7WLkxBbYUs7BqiNYqjfpWsq33qP+aW3avYP3qwYYY6Zy5aVtEPaqRKbJy4Xx7T0hHcSHRAGen73Ec5wHmN5gPfW5geoQOB5uYbSPO8ye663/Vb8XAZRxHBzxoW2TY+38HM/ICL60p3GaVBvUvp6lEwFUE7i0iMvE8cwih+0THofKSkGgVSRGz/uF0fdBDY7mxjGF8tN5CxFxLZxSQMA0PR1xkV6HRs7o6fdWWWBa9CpXuil51Y+Ah5CMvUrVEd9JxaNs=

sudo: false


## blacklist
#branches:
# except:
# - legacy
# - experimental
#
## whitelist
#branches:
# only:
# - master
# - stable

node_js:
- "iojs"
# - "iojs-v1.0"
# - "0.10"

script:
- npm run test

after_script:
- npm run coveralls

addons:
sauce_connect: true


notifications:
email:
recipients:
- qiuzhongleiabc@126.com
on_success: never
on_failure: always

50 changes: 47 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# demo-web-babel

[![Build Status][travis-image]][travis-url]
[![Coverage Status][coveralls-image]][coveralls-url]

[![Sauce Test Status](https://saucelabs.com/browser-matrix/qiu8310.svg)](https://saucelabs.com/u/qiu8310)


[travis-url]: https://travis-ci.org/qiu8310/demo-web-babel
[travis-image]: https://travis-ci.org/qiu8310/demo-web-babel.svg?branch=master
[coveralls-url]: https://coveralls.io/r/qiu8310/demo-web-babel
[coveralls-image]: https://coveralls.io/repos/qiu8310/demo-web-babel/badge.png

## Stacks

* karma & mocha
Expand All @@ -11,12 +22,45 @@
## Test

* `npm test` - local test
* `npm run test-remote` - test on saucelabs
* `npm run test-sl` - test on saucelabs

## Todo

* Auto enable saucelabs test when push to github
## SauceLabs

1. Add environment variables

```bash
export SAUCE_USERNAME="your sauce labs user name"
export SAUCE_ACCESS_KEY="yous sauce labs access key"
```

2. Run Sauce Labs test on local

```bash
npm run test-sl
```

3. Run Sauce Labs test on TravisCI

1. [Enable TravisCI](https://travis-ci.org/qiu8310/profile)
2. [Adding Sauce Labs credentials for a public github repo](https://docs.saucelabs.com/ci-integrations/travis-ci/#adding-credentials-for-a-public-github-repo) or [you can add environment variables in travis](https://travis-ci.org/qiu8310/demo-web-babel/settings/env_vars)
3. Add a addons to .travis.yml

```
addons:
sauce_connect: true
```
4. [Sauce Labs badge](https://docs.saucelabs.com/reference/status-images/) __Note: if your have multiple projects that need sauce labs status badge, you have to [create sub-account](https://saucelabs.com/sub-accounts).__


_[Reference](https://docs.saucelabs.com/ci-integrations/travis-ci/)_


## Todo

[ ] Auto enable saucelabs test when push to github
[ ] Can't stop saucelabs test on travis, example [build #67801561](https://travis-ci.org/qiu8310/demo-web-babel/builds/67801561)
[ ] Make a yeoman generator

## Reference

Expand Down
8 changes: 7 additions & 1 deletion karma.local.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module.exports = function(config) {
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',

port: 9876,

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: [
Expand All @@ -34,6 +36,10 @@ module.exports = function(config) {
},

coverageReporter: {
reporters: [
{ type: 'html' },
{ type: 'lcovonly' }
],
instrumenters: { isparta : require('isparta') },
instrumenter: {
'**/*.js': 'isparta'
Expand All @@ -55,7 +61,7 @@ module.exports = function(config) {
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [
'PhantomJS'
'PhantomJS'//, 'Firefox'
]

});
Expand Down
77 changes: 62 additions & 15 deletions karma.saucelabs.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.');
process.exit(1);
}

// https://saucelabs.com/platforms/
var browsers = {
sl_chrome: {
Expand All @@ -7,17 +12,17 @@ var browsers = {
platform: 'Windows 7',
version: '35'
},
sl_firefox: {
base: 'SauceLabs',
browserName: 'firefox',
version: '30'
},
sl_ios_safari: {
base: 'SauceLabs',
browserName: 'iphone',
platform: 'OS X 10.9',
version: '7.1'
},
//sl_firefox: {
// base: 'SauceLabs',
// browserName: 'firefox',
// version: '30'
//},
//sl_ios_safari: {
// base: 'SauceLabs',
// browserName: 'iphone',
// platform: 'OS X 10.9',
// version: '7.1'
//},
sl_ie_11: {
base: 'SauceLabs',
browserName: 'internet explorer',
Expand All @@ -26,13 +31,55 @@ var browsers = {
}
};

module.exports = function(config) {
config.set({
var key,
defCfg = {},
cfg = {
// all other options that are defined in
// local.karma.conf.js were elided for the
// purpose of this blog post.
reporters: ['saucelabs', 'spec'],
browsers: Object.keys(browsers),
customLaunchers: browsers
});
customLaunchers: browsers,
//logLevel: 'LOG_INFO',
captureTimeout: 120000,
browserNoActivityTimeout: 60000,

// https://docs.saucelabs.com/reference/test-configuration
sauceLabs: {
testName: 'demo-web-babel',
build: 'local ' + Date.now(),
recordLogs: true,
recordVideo: false,
startConnect: true,
recordScreenshots: true,
captureHtml: true,
passed: true,
public: 'public',
connectOptions: {
port: 5757,
logfile: 'sauce-connect.log'
}
},
singleRun: true,
autoWatch : false
};


if (process.env.TRAVIS) {

cfg.logLevel = 'LOG_DEBUG';
//cfg.transports = [ 'websocket' ];

cfg.sauceLabs.build = 'TRAVIS #' + process.env.TRAVIS_BUILD_NUMBER + ' (' + process.env.TRAVIS_BUILD_ID + ')';
cfg.sauceLabs.startConnect = false;
cfg.sauceLabs.recordScreenshots = true;
cfg.sauceLabs.tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER;
}


require('./karma.local.conf.js')({set: function(obj) { defCfg = obj; }});
for (key in defCfg) if (!(key in cfg) && defCfg.hasOwnProperty(key)) cfg[key] = defCfg[key];

module.exports = function(config) {
config.set(cfg);
};
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
"karma",
"web"
],
"dependencies": {},
"dependencies": {
"coveralls": "^2.11.2"
},
"devDependencies": {
"babel-plugin-espower": "^1.0.0",
"babelify": "^6.1.2",
"isparta": "^3.0.3",
"istanbul": "^0.3.15",
"karma": "^0.12.36",
"karma-bro": "^0.11.1",
"karma-browserify": "^4.0.0",
"karma-coverage": "douglasduteil/karma-coverage#next",
"karma-firefox-launcher": "^0.1.6",
"karma-mocha": "^0.1.10",
"karma-phantomjs-launcher": "^0.2.0",
"karma-sauce-launcher": "^0.2.11",
Expand All @@ -41,7 +44,9 @@
},
"scripts": {
"babel": "babel src/ --out-dir build --watch",
"test": "karma start karma.local.conf.js",
"test-sl": "karma start karma.saucelabs.conf.js"
"test": "rm -rf coverage && karma start karma.local.conf.js",
"test-sl": "karma start karma.saucelabs.conf.js",
"ci": "npm run test && npm run test-sl",
"coveralls": "cat coverage/Phantom*/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
}
}

0 comments on commit 7400c19

Please sign in to comment.