Skip to content

Commit 3c68d91

Browse files
committed
build: run chrome headless in travis
* No longer runs Chrome inside of Saucelabs or Browserstack. * Chrome will now run directly in Travis in headless mode.
1 parent d3d6d26 commit 3c68d91

File tree

6 files changed

+71
-54
lines changed

6 files changed

+71
-54
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
sudo: false
3+
dist: trusty
34

45
node_js:
56
- '--lts'
@@ -9,6 +10,7 @@ addons:
910
# SAUCE_ACCESS_KEY<=secret for FIREBASE_ACCESS_TOKEN to work around travis-ci/travis-ci#7223, unencrypted value in valentine as FIREBASE_ACCESS_TOKEN>
1011
# we alias FIREBASE_ACCESS_TOKEN to $SAUCE_ACCESS_KEY in env.sh and set the SAUCE_ACCESS_KEY there
1112
- secure: "PKts/IbxuJRWWOEeiGbl8Z9zds0M+hIdCH/g/E4WbQ9yzSvSbdwzfmRfFccQFjxjsrY7+SJMVjsURZy+xUyBpzqgWYHUItnSVqjZb8DlyAU2IXyg8TM9BVLkGGe6k5k4PIFVmfMMMzQwWMM0X0W9w3oYmfHL5egxwSHvf9HIqLolLNXg8sqamIdS5d5KoCXf1c+oRjN/IMBktzNBR6N4OFOZQXVoepXNiIvTWAcTtOPBvFWdKP2n7RVioHKdm4a85aCUpDJp+LYGaLqiQZoRzmzfVTnAhTAPdd4ao5w/+jojrfZIHV55bqYF9rLnQMTneKsiyVNVYJzOLuxmARa/EEKfZld+J3rX4/o4cogrU38YSZF+T7J9g/7CTsnIZ3F6W6m+8iJbIBh55nGOQi5PVe458Q/nGb3fgQd2Z4+6lK9k479H4Ssh/Y7hbVQbepqEVIXzZKqWX6/ZE4iWoR/Q2dm0hySFmmB/R2etixX5JxhnHvgobTYIQ+1liJVp/3YFW1ru64Yg6yz/V291Bhh9g31znmTROCJ/usAmZZaLUqW1TDKnLIMP+M74MF9XERqcWKywXRFwxP4E5uDnx/vAyN49gL+SDfrBUxUtXrTkKZAlglwo9SgA7cOYEPWrionvKcGm87gCBYHFUmXZNQVzh212fpuJYXb/vy0sPDj8La4="
13+
chrome: stable
1214

1315
branches:
1416
only:
@@ -17,13 +19,14 @@ branches:
1719
jobs:
1820
include:
1921
- env: "MODE=lint"
20-
- env: "MODE=e2e"
2122
- env: "MODE=aot"
2223
- env: "MODE=payload"
2324
- env: "MODE=prerender"
2425
- env: "MODE=closure-compiler"
26+
- env: "MODE=e2e"
2527
- env: "MODE=saucelabs_required"
2628
- env: "MODE=browserstack_required"
29+
- env: "MODE=travis_required"
2730
- stage: Deploy
2831
script: ./scripts/ci/publish-artifacts.sh
2932
env: "MODE=release"

scripts/ci/env.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

3+
if [[ -z "${TRAVIS}" ]]; then
4+
echo "This script can only setup the environment inside of Travis builds"
5+
exit 0
6+
fi
37

4-
if [[ ${TRAVIS:-} ]]; then
5-
# If FIREBASE_ACCESS_TOKEN not set yet, export the FIREBASE_ACCESS_TOKEN using the JWT token that Travis generated and exported for SAUCE_ACCESS_KEY.
6-
# This is a workaround for travis-ci/travis-ci#7223
7-
# WARNING: FIREBASE_ACCESS_TOKEN should NOT be printed
8-
export FIREBASE_ACCESS_TOKEN=${FIREBASE_ACCESS_TOKEN:-$SAUCE_ACCESS_KEY}
8+
# If FIREBASE_ACCESS_TOKEN not set yet, export the FIREBASE_ACCESS_TOKEN using the JWT token that Travis generated and exported for SAUCE_ACCESS_KEY.
9+
# This is a workaround for travis-ci/travis-ci#7223
10+
# WARNING: FIREBASE_ACCESS_TOKEN should NOT be printed
11+
export FIREBASE_ACCESS_TOKEN=${FIREBASE_ACCESS_TOKEN:-$SAUCE_ACCESS_KEY}
912

10-
# - we overwrite the value set by Travis JWT addon here to work around travis-ci/travis-ci#7223 for FIREBASE_ACCESS_TOKEN
11-
export SAUCE_ACCESS_KEY=9b988f434ff8-fbca-8aa4-4ae3-35442987
12-
fi
13+
# - we overwrite the value set by Travis JWT addon here to work around travis-ci/travis-ci#7223 for FIREBASE_ACCESS_TOKEN
14+
export SAUCE_ACCESS_KEY=9b988f434ff8-fbca-8aa4-4ae3-35442987

scripts/ci/sources/mode.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
source ./scripts/ci/sources/tunnel.sh
33

44
is_e2e() {
5-
[[ "$MODE" = e2e ]]
5+
[[ "${MODE}" = e2e ]]
66
}
77

88
is_lint() {
9-
[[ "$MODE" = lint ]]
9+
[[ "${MODE}" = lint ]]
1010
}
1111

1212
is_aot() {
13-
[[ "$MODE" = aot ]]
13+
[[ "${MODE}" = aot ]]
1414
}
1515

1616
is_closure_compiler() {
17-
[[ "$MODE" = closure-compiler ]]
17+
[[ "${MODE}" = closure-compiler ]]
1818
}
1919

2020
is_payload() {
21-
[[ "$MODE" = payload ]]
21+
[[ "${MODE}" = payload ]]
2222
}
2323

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

2828
is_prerender() {

test/browser-providers.js

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22

33
/*
44
* Browser Configuration for the different jobs in the CI.
5-
* Target can be either: BS (Browserstack) | SL (Saucelabs) | null (To not run at all)
5+
* Target can be either: BS (Browserstack) | SL (Saucelabs) | TC (Travis CI) | null (To not run)
66
*/
77
const browserConfig = {
8-
'Chrome': { unitTest: {target: 'BS', required: true }},
9-
'Firefox': { unitTest: {target: 'BS', 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: 'BS', required: true }},
30-
'WindowsPhone': { unitTest: {target: null, required: false }}
8+
'ChromeHeadless_CI': { unitTest: {target: 'TC', required: true }},
9+
'Firefox': { unitTest: {target: 'BS', 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: 'BS', required: true }},
30+
'WindowsPhone': { unitTest: {target: null, required: false }}
3131
};
3232

3333
/** Exports all available remote browsers. */
@@ -43,14 +43,26 @@ exports.platformMap = {
4343
required: buildConfiguration('unitTest', 'BS', true),
4444
optional: buildConfiguration('unitTest', 'BS', false)
4545
},
46+
'travis': {
47+
required: buildConfiguration('unitTest', 'TC', true),
48+
optional: buildConfiguration('unitTest', 'TC', false)
49+
}
4650
};
4751

4852
/** Build a list of configuration (custom launcher names). */
4953
function buildConfiguration(type, target, required) {
50-
return Object.keys(browserConfig)
51-
.map(item => [item, browserConfig[item][type]])
52-
.filter(([, conf]) => conf.required === required && conf.target === target)
53-
.map(([item]) => `${target}_${item.toUpperCase()}`);
54+
const targetBrowsers = Object.keys(browserConfig)
55+
.map(browserName => [browserName, browserConfig[browserName][type]])
56+
.filter(([, config]) => config.required === required && config.target === target)
57+
.map(([browserName]) => browserName);
58+
59+
// For browsers that run on Travis CI the browser name shouldn't be prefixed with the shortcut
60+
// of Travis. The different Karma launchers only work with the plain browser name (e.g Firefox)
61+
if (target === 'TC') {
62+
return targetBrowsers;
63+
}
64+
65+
return targetBrowsers.map(browserName => `${target}_${browserName.toUpperCase()}`);
5466
}
5567

5668
/** Decode the token for Travis to use. */

test/karma.conf.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = (config) => {
9292
});
9393

9494
if (process.env['TRAVIS']) {
95-
let buildId = `TRAVIS #${process.env.TRAVIS_BUILD_NUMBER} (${process.env.TRAVIS_BUILD_ID})`;
95+
const buildId = `TRAVIS #${process.env.TRAVIS_BUILD_NUMBER} (${process.env.TRAVIS_BUILD_ID})`;
9696

9797
if (process.env['TRAVIS_PULL_REQUEST'] === 'false' &&
9898
process.env['MODE'] === "browserstack_required") {
@@ -102,21 +102,21 @@ module.exports = (config) => {
102102
}
103103

104104
// The MODE variable is the indicator of what row in the test matrix we're running.
105-
// It will look like <platform>_<alias>, where platform is one of 'saucelabs' or 'browserstack',
106-
// and alias is one of the keys in the CI configuration variable declared in
107-
// browser-providers.ts.
108-
let [platform, alias] = process.env.MODE.split('_');
105+
// It will look like <platform>_<target>, where platform is one of 'saucelabs', 'browserstack'
106+
// or 'travis'. The target is a reference to different collections of browsers that can run
107+
// in the previously specified platform.
108+
const [platform, target] = process.env.MODE.split('_');
109109

110110
if (platform === 'saucelabs') {
111111
config.sauceLabs.build = buildId;
112112
config.sauceLabs.tunnelIdentifier = process.env.TRAVIS_JOB_ID;
113113
} else if (platform === 'browserstack') {
114114
config.browserStack.build = buildId;
115115
config.browserStack.tunnelIdentifier = process.env.TRAVIS_JOB_ID;
116-
} else {
116+
} else if (platform !== 'travis') {
117117
throw new Error(`Platform "${platform}" unknown, but Travis specified. Exiting.`);
118118
}
119119

120-
config.browsers = platformMap[platform][alias.toLowerCase()];
120+
config.browsers = platformMap[platform][target.toLowerCase()];
121121
}
122122
};

test/remote_browsers.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"ChromeNoSandbox": {
3-
"base": "Chrome",
2+
"ChromeHeadless_CI": {
3+
"base": "ChromeHeadless",
44
"flags": [
5-
"--no-sandbox"
5+
"--window-size=1024,768"
66
]
77
},
88
"Chrome_1024x768": {

0 commit comments

Comments
 (0)