Skip to content

Commit 59ae96e

Browse files
committed
build: run all unit tests on browserstack
* No longer runs tests on Saucelabs, because those jobs mostly time out, or are just flaky.
1 parent 73bc948 commit 59ae96e

File tree

9 files changed

+86
-285
lines changed

9 files changed

+86
-285
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ jobs:
2727
- env: "MODE=payload"
2828
- env: "MODE=prerender"
2929
- env: "MODE=e2e"
30-
- env: "MODE=saucelabs_required"
31-
- env: "MODE=browserstack_required"
32-
- env: "MODE=travis_required"
30+
- env: "MODE=test-browserstack-1"
31+
- env: "MODE=test-browserstack-2"
32+
- env: "MODE=test-travis-1"
3333
- env: "DEPLOY_MODE=build-artifacts"
3434
if: type = push
3535
- env: "DEPLOY_MODE=docs-content"
@@ -45,8 +45,8 @@ env:
4545
global:
4646
- LOGS_DIR=/tmp/angular-material2-build/logs
4747
- SAUCE_USERNAME=angular-ci
48-
- BROWSER_STACK_USERNAME=angularteam1
49-
- BROWSER_STACK_ACCESS_KEY=BWCd4SynLzdDcv8xtzsB
48+
- BROWSER_STACK_USERNAME=paulgschwendtner2
49+
- BROWSER_STACK_ACCESS_KEY=hsz2pirQRsDASY1aZKaz
5050
- BROWSER_PROVIDER_READY_FILE=/tmp/angular-material2-build/readyfile
5151
- BROWSER_PROVIDER_ERROR_FILE=/tmp/angular-material2-build/errorfile
5252

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
"karma-coverage": "^1.1.1",
101101
"karma-firefox-launcher": "^1.0.1",
102102
"karma-jasmine": "^1.1.0",
103-
"karma-sauce-launcher": "^1.2.0",
104103
"karma-sourcemap-loader": "^0.3.7",
105104
"madge": "^2.2.0",
106105
"magic-string": "^0.22.4",

scripts/browserstack/start-tunnel.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ unzip -q ${TUNNEL_FILE} -d browserstack-tunnel
3030
# Cleanup the download directory.
3131
rm ${TUNNEL_FILE}
3232

33-
ARGS=""
33+
if [ -z "${TRAVIS_JOB_ID}" ]; then
34+
echo "Error: Cannot set up a BrowserStack tunnel if there is no '\$TRAVIS_JOB_ID' set."
35+
exit 1
36+
fi;
3437

35-
# Set tunnel-id only on Travis, to make local testing easier.
36-
if [ ! -z "${TRAVIS_JOB_ID}" ]; then
37-
ARGS="${ARGS} --local-identifier ${TRAVIS_JOB_ID}"
38-
fi
38+
ARGS="--local-identifier ${TRAVIS_JOB_ID}"
3939

40-
echo "Starting Browserstack Local in the background, logging into: ${TUNNEL_LOG}"
40+
echo "Starting Browserstack Local in the background, logging into: ${TUNNEL_LOG}." \
41+
"Using the following tunnel identifier: ${TRAVIS_JOB_ID}"
4142

4243
# Extension to the BrowserStackLocal binaries, because those can't create a readyfile.
4344
function create_ready_file {

scripts/ci/sources/mode.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ is_payload() {
2222
}
2323

2424
is_unit() {
25-
[[ "${MODE}" =~ ^.*_(optional|required)$ ]]
25+
[[ "${MODE}" =~ ^test-.* ]]
2626
}
2727

2828
is_prerender() {

scripts/ci/sources/tunnel.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,38 @@ source ./scripts/retry-call.sh
66
# Variable the specifies how often the wait script should be invoked if it fails.
77
WAIT_RETRIES=2
88

9-
start_tunnel() {
9+
start_tunnel_if_necessary() {
1010
case "$MODE" in
11-
e2e*|saucelabs*)
11+
e2e*)
1212
./scripts/saucelabs/start-tunnel.sh
1313
;;
14-
browserstack*)
14+
test-browserstack-*)
1515
./scripts/browserstack/start-tunnel.sh
1616
;;
1717
*)
1818
;;
1919
esac
2020
}
2121

22-
wait_for_tunnel() {
22+
wait_for_tunnel_if_present() {
2323
case "$MODE" in
24-
e2e*|saucelabs*)
24+
e2e*)
2525
retryCall ${WAIT_RETRIES} ./scripts/saucelabs/wait-tunnel.sh
2626
;;
27-
browserstack*)
27+
test-browserstack-*)
2828
retryCall ${WAIT_RETRIES} ./scripts/browserstack/wait-tunnel.sh
2929
;;
3030
*)
3131
;;
3232
esac
3333
}
3434

35-
teardown_tunnel() {
35+
teardown_tunnel_if_present() {
3636
case "$MODE" in
37-
e2e*|saucelabs*)
37+
e2e*)
3838
./scripts/saucelabs/stop-tunnel.sh
3939
;;
40-
browserstack*)
40+
test-browserstack-*)
4141
./scripts/browserstack/stop-tunnel.sh
4242
;;
4343
*)

scripts/ci/travis-testing.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ if [ "$TRAVIS_PULL_REQUEST" = "true" ]; then
2828
fi
2929
fi
3030

31-
start_tunnel
32-
wait_for_tunnel
31+
start_tunnel_if_necessary
32+
wait_for_tunnel_if_present
3333

3434
if is_lint; then
3535
$(npm bin)/gulp ci:lint
@@ -52,4 +52,4 @@ if [ -f dist/coverage/coverage-summary.json ]; then
5252
$(npm bin)/gulp ci:coverage
5353
fi
5454

55-
teardown_tunnel
55+
teardown_tunnel_if_present

test/browser-providers.js

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,75 +5,61 @@
55
* Target can be either: BS (Browserstack) | SL (Saucelabs) | TC (Travis CI) | null (To not run)
66
*/
77
const browserConfig = {
8-
'ChromeHeadlessCI': { unitTest: {target: 'TC', required: true }},
9-
'FirefoxHeadless': { unitTest: {target: 'TC', required: true }},
10-
'ChromeBeta': { unitTest: {target: null, required: false }},
11-
'FirefoxBeta': { unitTest: {target: null, required: false }},
12-
'ChromeDev': { unitTest: {target: null, required: true }},
13-
'FirefoxDev': { unitTest: {target: null, required: true }},
14-
'IE9': { unitTest: {target: null, required: false }},
15-
'IE10': { unitTest: {target: null, required: true }},
16-
'IE11': { unitTest: {target: 'SL', required: true }},
17-
'Edge': { unitTest: {target: 'SL', required: true }},
18-
'Android4.1': { unitTest: {target: null, required: false }},
19-
'Android4.2': { unitTest: {target: null, required: false }},
20-
'Android4.3': { unitTest: {target: null, required: false }},
21-
'Android4.4': { unitTest: {target: null, required: false }},
22-
'Android5': { unitTest: {target: null, required: false }},
23-
'Safari7': { unitTest: {target: null, required: false }},
24-
'Safari8': { unitTest: {target: null, required: false }},
25-
'Safari9': { unitTest: {target: 'SL', required: true }},
26-
'Safari10': { unitTest: {target: 'BS', required: true }},
27-
'iOS7': { unitTest: {target: null, required: false }},
28-
'iOS8': { unitTest: {target: null, required: false }},
29-
'iOS9': { unitTest: {target: null, required: false }},
30-
'iOS10': { unitTest: {target: 'BS', required: true }},
31-
'WindowsPhone': { unitTest: {target: null, required: false }}
8+
'ChromeHeadlessCI': { target: 'TC', poolId: 1 },
9+
'FirefoxHeadless': { target: 'TC', poolId: 1 },
10+
'IE11': { target: null },
11+
'Edge': { target: 'BS', poolId: 1 },
12+
'Android4.4': { target: null },
13+
'Android5': { target: null },
14+
'Safari10': { target: 'BS', poolId: 1 },
15+
'Safari11': { target: 'BS', poolId: 2 },
16+
'iOS10': { target: null },
17+
'iOS11': { target: 'BS', poolId: 2 },
18+
'WindowsPhone': { target: null }
3219
};
3320

3421
/** Exports all available remote browsers. */
3522
exports.customLaunchers = require('./remote_browsers.json');
3623

3724
/** Exports a map of configured browsers, which should run on the CI. */
3825
exports.platformMap = {
39-
'saucelabs': {
40-
required: buildConfiguration('unitTest', 'SL', true),
41-
optional: buildConfiguration('unitTest', 'SL', false)
42-
},
43-
'browserstack': {
44-
required: buildConfiguration('unitTest', 'BS', true),
45-
optional: buildConfiguration('unitTest', 'BS', false)
46-
},
47-
'travis': {
48-
required: buildConfiguration('unitTest', 'TC', true),
49-
optional: buildConfiguration('unitTest', 'TC', false)
50-
}
26+
'browserstack': buildConfiguration('BS'),
27+
'travis': buildConfiguration('TC'),
5128
};
5229

53-
/** Build a list of configuration (custom launcher names). */
54-
function buildConfiguration(type, target, required) {
55-
const targetBrowsers = Object.keys(browserConfig)
56-
.map(browserName => [browserName, browserConfig[browserName][type]])
57-
.filter(([, config]) => config.required === required && config.target === target)
58-
.map(([browserName]) => browserName);
30+
/** Build a list of configuration for the specified platform. */
31+
function buildConfiguration(platform) {
32+
const platformConfig = {};
5933

60-
// For browsers that run on Travis CI the browser name shouldn't be prefixed with the shortcut
61-
// of Travis. The different Karma launchers only work with the plain browser name (e.g Firefox)
62-
if (target === 'TC') {
63-
return targetBrowsers;
64-
}
34+
Object.keys(browserConfig).forEach(browserName => {
35+
const config = browserConfig[browserName];
6536

66-
return targetBrowsers.map(browserName => `${target}_${browserName.toUpperCase()}`);
37+
if (config.target !== platform || !config.poolId) {
38+
return;
39+
}
40+
41+
if (!platformConfig[config.poolId]) {
42+
platformConfig[config.poolId] = [];
43+
}
44+
45+
// For browsers that run on Travis CI the browser name shouldn't be prefixed with the shortcut
46+
// of Travis. The different Karma launchers only work with the plain browser name (e.g Firefox)
47+
if (platform !== 'TC') {
48+
browserName = `${platform}_${browserName.toUpperCase()}`;
49+
}
50+
51+
platformConfig[config.poolId].push(browserName);
52+
});
53+
54+
return platformConfig;
6755
}
6856

6957
/** Decode the token for Travis to use. */
7058
function decodeToken(token) {
7159
return (token || '').split('').reverse().join('');
7260
}
7361

74-
7562
/** Ensures that the Travis access keys work properly. */
7663
if (process.env.TRAVIS) {
77-
process.env.SAUCE_ACCESS_KEY = decodeToken(process.env.SAUCE_ACCESS_KEY);
7864
process.env.BROWSER_STACK_ACCESS_KEY = decodeToken(process.env.BROWSER_STACK_ACCESS_KEY);
7965
}

test/karma.conf.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module.exports = (config) => {
99
plugins: [
1010
require('karma-jasmine'),
1111
require('karma-browserstack-launcher'),
12-
require('karma-sauce-launcher'),
1312
require('karma-chrome-launcher'),
1413
require('karma-firefox-launcher'),
1514
require('karma-sourcemap-loader'),
@@ -79,9 +78,10 @@ module.exports = (config) => {
7978

8079
browserDisconnectTimeout: 20000,
8180
browserNoActivityTimeout: 240000,
81+
browserDisconnectTolerance: 1,
8282
captureTimeout: 120000,
83-
browsers: ['ChromeHeadlessLocal'],
8483

84+
browsers: ['ChromeHeadlessLocal'],
8585
singleRun: false,
8686

8787
browserConsoleLogOptions: {
@@ -98,31 +98,30 @@ module.exports = (config) => {
9898
});
9999

100100
if (process.env['TRAVIS']) {
101-
const buildId = `TRAVIS #${process.env.TRAVIS_BUILD_NUMBER} (${process.env.TRAVIS_BUILD_ID})`;
101+
const buildId = `TravisCI ${process.env.TRAVIS_BUILD_ID}`;
102+
const tunnelIdentifier = process.env.TRAVIS_JOB_ID;
102103

103-
if (process.env['TRAVIS_PULL_REQUEST'] === 'false' &&
104-
process.env['MODE'] === "travis_required") {
104+
if (process.env['TRAVIS_PULL_REQUEST'] === 'false'
105+
&& process.env['MODE'] === "test-travis-1") {
105106

106107
config.preprocessors['dist/packages/**/!(*+(.|-)spec).js'] = ['coverage'];
107108
config.reporters.push('coverage');
108109
}
109110

110111
// The MODE variable is the indicator of what row in the test matrix we're running.
111-
// It will look like <platform>_<target>, where platform is one of 'saucelabs', 'browserstack'
112-
// or 'travis'. The target is a reference to different collections of browsers that can run
113-
// in the previously specified platform.
114-
const [platform, target] = process.env.MODE.split('_');
115-
116-
if (platform === 'saucelabs') {
117-
config.sauceLabs.build = buildId;
118-
config.sauceLabs.tunnelIdentifier = process.env.TRAVIS_JOB_ID;
119-
} else if (platform === 'browserstack') {
112+
// It will look like "test-<platform>[-poolId], where platform is one of 'browserstack' or
113+
// 'travis'. Pool ids allow running different browsers on the same
114+
// platform, but in different CI jobs.
115+
const [, platform, poolId] = process.env.MODE.split('-');
116+
117+
if (platform === 'browserstack') {
120118
config.browserStack.build = buildId;
121-
config.browserStack.tunnelIdentifier = process.env.TRAVIS_JOB_ID;
119+
config.browserStack.tunnelIdentifier = tunnelIdentifier;
120+
console.log(`Setting up Browserstack launcher. Connecting to tunnel: "${tunnelIdentifier}"`);
122121
} else if (platform !== 'travis') {
123-
throw new Error(`Platform "${platform}" unknown, but Travis specified. Exiting.`);
122+
throw new Error(`Platform "${platform}" is unknown. Exiting..`);
124123
}
125124

126-
config.browsers = platformMap[platform][target.toLowerCase()];
125+
config.browsers = platformMap[platform][parseInt(poolId)];
127126
}
128127
};

0 commit comments

Comments
 (0)