Skip to content

Commit 0949f6e

Browse files
committed
Merge pull request #353 from bryk/sauce
Run tests that require a browser on saucelabs (FF/Chrome/IE)
2 parents 8af7465 + c31b4fd commit 0949f6e

File tree

7 files changed

+98
-35
lines changed

7 files changed

+98
-35
lines changed

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ language: node_js
3030
node_js:
3131
- 4.2.2
3232

33+
addons:
34+
# Run tests that require a browser on SauceLabs CI provider. Learn more at: https://saucelabs.com
35+
sauce_connect:
36+
username: k8s-dashboard-ci
37+
access_key: "18b7e71b-60e9-4177-9a7f-e769977dbb39"
38+
3339
# Docker is required to set up a simple, single node Kubernetes cluster.
3440
# Local Docker-based cluster is the simplest way to create kubernetes on the host machine.
3541
services:
3642
- docker
3743

38-
before_script:
39-
# Prepare environment for the Chrome browser.
40-
- export CHROME_BIN=chromium-browser
41-
- export DISPLAY=:99.0
42-
- sh -e /etc/init.d/xvfb start
43-
4444
script: ./node_modules/.bin/gulp check:local-cluster
4545
after_script: ./node_modules/.bin/gulp coverage-codecov-upload

build/cluster.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ gulp.task('wait-for-cluster', function(doneFn) {
149149

150150
// constantly query the cluster until it is properly running
151151
clusterHealthCheck(function(result) {
152-
if (result === 'ok') {
152+
if (result === 'ok' && isRunningSetIntervalHandler !== null) {
153153
gulpUtil.log(gulpUtil.colors.magenta('Kubernetes cluster is up and running.'));
154154
clearTimeout(isRunningSetIntervalHandler);
155155
isRunningSetIntervalHandler = null;

build/conf.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ export default {
8585
rootModuleName: 'kubernetesDashboard',
8686
},
8787

88+
/**
89+
* Configuration for tests.
90+
*/
91+
test: {
92+
/**
93+
* Whether to use sauce labs for running tests that require a browser.
94+
*/
95+
useSauceLabs:
96+
!!process.env.SAUCE_USERNAME && !!process.env.SAUCE_ACCESS_KEY && !!process.env.TRAVIS,
97+
},
98+
8899
/**
89100
* Absolute paths to known directories, e.g., to source directory.
90101
*/

build/karma.conf.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,9 @@ module.exports = function(config) {
5757

5858
frameworks: ['jasmine', 'browserify'],
5959

60-
browsers: ['Chrome'],
61-
6260
browserNoActivityTimeout: 60 * 1000, // 60 seconds.
6361

64-
customLaunchers: {
65-
// Custom launcher for Travis CI. It is required because Travis environment cannot use
66-
// sandbox.
67-
chromeTravis: {
68-
base: 'Chrome',
69-
flags: ['--no-sandbox'],
70-
},
71-
},
72-
73-
reporters: ['progress', 'coverage'],
62+
reporters: ['dots', 'coverage'],
7463

7564
coverageReporter: {
7665
dir: conf.paths.coverage,
@@ -89,6 +78,7 @@ module.exports = function(config) {
8978
'karma-ng-html2js-preprocessor',
9079
'karma-sourcemap-loader',
9180
'karma-browserify',
81+
'karma-sauce-launcher',
9282
],
9383

9484
// karma-browserify plugin config.
@@ -115,8 +105,34 @@ module.exports = function(config) {
115105
};
116106

117107
// Use custom browser configuration when running on Travis CI.
118-
if (process.env.TRAVIS) {
119-
configuration.browsers = ['chromeTravis'];
108+
if (conf.test.useSauceLabs) {
109+
configuration.reporters.push('saucelabs');
110+
111+
let testName;
112+
if (process.env.TRAVIS) {
113+
testName = `Karma tests ${process.env.TRAVIS_REPO_SLUG}, build ` +
114+
`${process.env.TRAVIS_BUILD_NUMBER}`;
115+
if (process.env.TRAVIS_PULL_REQUEST !== 'false') {
116+
testName += `, PR: https://github.com/${process.env.TRAVIS_REPO_SLUG}/pull/` +
117+
`${process.env.TRAVIS_PULL_REQUEST}`;
118+
}
119+
} else {
120+
testName = 'Local karma tests';
121+
}
122+
123+
configuration.sauceLabs = {
124+
testName: testName,
125+
connectOptions: {port: 5757, logfile: 'sauce_connect.log'},
126+
public: 'public',
127+
},
128+
configuration.customLaunchers = {
129+
sl_chrome: {base: 'SauceLabs', browserName: 'chrome'},
130+
sl_firefox: {base: 'SauceLabs', browserName: 'firefox'},
131+
sl_ie: {base: 'SauceLabs', browserName: 'internet explorer'},
132+
};
133+
configuration.browsers = Object.keys(configuration.customLaunchers);
134+
} else {
135+
configuration.browsers = ['Chrome'];
120136
}
121137

122138
// Convert all JS code written ES6 with modules to ES5 bundles that browsers can digest.

build/protractor.conf.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,61 @@
1717
*
1818
* TODO(bryk): Start using ES6 modules in this file when supported.
1919
*/
20+
/* eslint strict: [0] */
21+
'use strict';
2022
require('babel-core/register');
2123
const conf = require('./conf').default;
2224
const path = require('path');
2325

2426
/**
25-
* Exported protractor config required by the framework.
26-
*
2727
* Schema can be found here: https://github.com/angular/protractor/blob/master/docs/referenceConf.js
28+
* @return {!Object}
2829
*/
29-
exports.config = {
30-
baseUrl: `http://localhost:${conf.frontend.serverPort}`,
30+
function createConfig() {
31+
const config = {
32+
baseUrl: `http://localhost:${conf.frontend.serverPort}`,
33+
34+
framework: 'jasmine',
35+
36+
specs: [path.join(conf.paths.integrationTest, '**/*.js')],
37+
};
38+
39+
if (conf.test.useSauceLabs) {
40+
let name = `Integration tests ${process.env.TRAVIS_REPO_SLUG}, build ` +
41+
`${process.env.TRAVIS_BUILD_NUMBER}`;
42+
if (process.env.TRAVIS_PULL_REQUEST !== 'false') {
43+
name += `, PR: https://github.com/${process.env.TRAVIS_REPO_SLUG}/pull/` +
44+
`${process.env.TRAVIS_PULL_REQUEST}`;
45+
}
3146

32-
capabilities: {
33-
// Firefox is used instead of Chrome, because that's what Travis supports best.
34-
// The browser that is used in the integration tests should not affect the results, anyway.
35-
'browserName': 'firefox',
36-
},
47+
config.sauceUser = process.env.SAUCE_USERNAME;
48+
config.sauceKey = process.env.SAUCE_ACCESS_KEY;
49+
config.multiCapabilities = [
50+
{
51+
'browserName': 'chrome',
52+
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
53+
'name': name,
54+
},
55+
{
56+
'browserName': 'firefox',
57+
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
58+
'name': name,
59+
},
60+
{
61+
'browserName': 'internet explorer',
62+
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
63+
'name': name,
64+
},
65+
];
3766

38-
framework: 'jasmine',
67+
} else {
68+
config.capabilities = {'browserName': 'chrome'};
69+
}
3970

40-
specs: [path.join(conf.paths.integrationTest, '**/*.js')],
41-
};
71+
return config;
72+
}
73+
74+
/**
75+
* Exported protractor config required by the framework.
76+
*/
77+
exports.config = createConfig();

build/test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ gulp.task('integration-test:prod', ['serve:prod', 'webdriver-update'], runProtra
138138
* Runs application integration tests. Uses production version of the application.
139139
*/
140140
gulp.task(
141-
'local-cluster-integration-test:prod', ['serve:prod', 'webdriver-update', 'local-up-cluster'],
142-
runProtractorTests);
141+
'local-cluster-integration-test:prod', ['serve:prod', 'local-up-cluster'], runProtractorTests);
143142

144143
/**
145144
* Downloads and updates webdriver. Required to keep it up to date.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"karma-coverage": "~0.5.3",
5656
"karma-jasmine": "~0.3.6",
5757
"karma-ng-html2js-preprocessor": "~0.2.0",
58+
"karma-sauce-launcher": "^0.3.0",
5859
"karma-sourcemap-loader": "~0.3.6",
5960
"lodash": "~4.1.0",
6061
"proxy-middleware": "~0.15.0",

0 commit comments

Comments
 (0)