Skip to content

Commit 4d15d1d

Browse files
committed
build: run browserstack on circleci
1 parent 193eb48 commit 4d15d1d

File tree

8 files changed

+90
-36
lines changed

8 files changed

+90
-36
lines changed

.circleci/config.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,25 @@ jobs:
125125

126126
- *save_cache
127127

128+
# ----------------------------------------------------------------------------
129+
# Job that runs the unit tests on Browserstack. The browsers that will be used
130+
# to run the unit tests on Browserstack are set in: test/browser-providers.js
131+
# ----------------------------------------------------------------------------
132+
tests_browserstack:
133+
<<: *job_defaults
134+
resource_class: xlarge
135+
environment:
136+
BROWSER_STACK_USERNAME: "angularteam1"
137+
BROWSER_STACK_ACCESS_KEY: "CaXMeMHD9pr5PHg8N7Jq"
138+
steps:
139+
- *checkout_code
140+
- *restore_cache
141+
- *yarn_install
142+
143+
- run: ./scripts/circleci/run-browserstack-tests.sh
144+
145+
- *save_cache
146+
128147
# --------------------------------------
129148
# Job that builds the demo-app with AOT
130149
# --------------------------------------
@@ -189,6 +208,7 @@ workflows:
189208
unit_tests:
190209
jobs:
191210
- tests_local_browsers
211+
- tests_browserstack
192212

193213
integration_tests:
194214
jobs:

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ jobs:
2727
include:
2828
- env: "MODE=payload"
2929
- env: "MODE=saucelabs_required"
30-
- env: "MODE=browserstack_required"
3130
- env: "DEPLOY_MODE=build-artifacts"
3231
if: type = push
3332
- env: "DEPLOY_MODE=docs-content"

scripts/browserstack/start-tunnel.sh

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,46 @@
22

33
set -e -o pipefail
44

5-
# Workaround for Travis CI cookbook https://github.com/travis-ci/travis-ci/issues/4862,
6-
# where $PATH will be extended with relative paths to the NPM binaries.
7-
PATH=`echo ${PATH} | sed -e 's/:\.\/node_modules\/\.bin//'`
5+
tunnelFileName="BrowserStackLocal-linux-x64.zip"
6+
tunnelUrl="https://www.browserstack.com/browserstack-local/${tunnelFileName}"
87

9-
TUNNEL_FILE="BrowserStackLocal-linux-x64.zip"
10-
TUNNEL_URL="https://www.browserstack.com/browserstack-local/${TUNNEL_FILE}"
11-
TUNNEL_DIR="/tmp/browserstack-tunnel"
12-
TUNNEL_LOG="${LOGS_DIR}/browserstack-tunnel.log"
13-
14-
BROWSER_STACK_ACCESS_KEY=`echo ${BROWSER_STACK_ACCESS_KEY} | rev`
8+
tunnelTmpDir="/tmp/material-browserstack"
9+
tunnelLogFile="${tunnelTmpDir}/browserstack-local.log"
10+
tunnelReadyFile="${tunnelTmpDir}/readyfile"
11+
tunnelErrorFile="${tunnelTmpDir}/errorfile"
1512

1613
# Cleanup and create the folder structure for the tunnel connector.
17-
rm -rf ${TUNNEL_DIR} ${BROWSER_PROVIDER_READY_FILE}
18-
mkdir -p ${TUNNEL_DIR}
19-
touch ${TUNNEL_LOG}
14+
rm -rf ${tunnelTmpDir} ${tunnelReadyFile} ${tunnelErrorFile}
15+
mkdir -p ${tunnelTmpDir}
16+
touch ${tunnelLogFile}
2017

21-
cd ${TUNNEL_DIR}
18+
# Go into temporary tunnel directory.
19+
cd ${tunnelTmpDir}
2220

2321
# Download the browserstack local binaries.
24-
curl ${TUNNEL_URL} -o ${TUNNEL_FILE} 2> /dev/null 1> /dev/null
22+
curl ${tunnelUrl} -o ${tunnelFileName} 2> /dev/null 1> /dev/null
2523

2624
# Extract the browserstack local binaries from the tarball.
2725
mkdir -p browserstack-tunnel
28-
unzip -q ${TUNNEL_FILE} -d browserstack-tunnel
26+
unzip -q ${tunnelFileName} -d browserstack-tunnel
2927

30-
# Cleanup the download directory.
31-
rm ${TUNNEL_FILE}
28+
# Cleanup the downloaded zip archive.
29+
rm ${tunnelFileName}
3230

3331
ARGS=""
3432

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}"
33+
if [ ! -z "${CIRCLE_BUILD_NUM}" ]; then
34+
ARGS="${ARGS} --local-identifier ${CIRCLE_BUILD_NUM}"
3835
fi
3936

40-
echo "Starting Browserstack Local in the background, logging into: ${TUNNEL_LOG}"
37+
echo "Starting Browserstack Local in the background, logging into: ${tunnelLogFile}"
4138

4239
# Extension to the BrowserStackLocal binaries, because those can't create a readyfile.
4340
function create_ready_file {
4441

4542
# To be able to exit the tail properly we need to have a sub shell spawned, which is
4643
# used to track the state of tail.
47-
{ sleep 120; touch ${BROWSER_PROVIDER_ERROR_FILE}; } &
44+
{ sleep 120; touch ${tunnelErrorFile}; } &
4845

4946
TIMER_PID=${!}
5047

@@ -54,16 +51,17 @@ function create_ready_file {
5451

5552
# When the tail recognizes the `Ctrl-C` log message the BrowserStack Tunnel is up.
5653
{
57-
tail -n0 -f ${TUNNEL_LOG} --pid ${TIMER_PID} | { sed '/Ctrl/q' && kill -9 ${TIMER_PID}; };
54+
tail -n0 -f ${tunnelLogFile} --pid ${TIMER_PID} | { sed '/Ctrl/q' && kill -9 ${TIMER_PID}; };
5855
} &> /dev/null
5956

6057
echo
6158
echo "BrowserStack Tunnel ready"
6259

63-
touch ${BROWSER_PROVIDER_READY_FILE}
60+
touch ${tunnelReadyFile}
6461
}
6562

66-
browserstack-tunnel/BrowserStackLocal -k ${BROWSER_STACK_ACCESS_KEY} ${ARGS} 2>&1 >> ${TUNNEL_LOG} &
63+
browserstack-tunnel/BrowserStackLocal -k ${BROWSER_STACK_ACCESS_KEY} ${ARGS} 2>&1 >> \
64+
${tunnelLogFile} &
6765

6866
# Wait for the tunnel to be ready and create the readyfile with the Browserstack PID
6967
create_ready_file &

scripts/browserstack/stop-tunnel.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
set -e -o pipefail
44

5-
65
echo "Shutting down Browserstack tunnel"
76

87
killall BrowserStackLocal
@@ -13,4 +12,4 @@ while [[ -n `ps -ef | grep "BrowserStackLocal" | grep -v "grep"` ]]; do
1312
done
1413

1514
echo ""
16-
echo "Browserstack tunnel has been shut down"
15+
echo "Browserstack tunnel has been shut down"

scripts/browserstack/wait-tunnel.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
#!/bin/bash
22

3-
TUNNEL_LOG="$LOGS_DIR/browserstack-tunnel.log"
3+
tunnelTmpDir="/tmp/material-browserstack"
4+
tunnelLogFile="${tunnelTmpDir}/browserstack-local.log"
5+
tunnelReadyFile="${tunnelTmpDir}/readyfile"
6+
tunnelErrorFile="${tunnelTmpDir}/errorfile"
7+
48
WAIT_DELAY=30
59

610
# Method that prints the logfile output of the browserstack tunnel.
711
printLog() {
8-
echo "Logfile output of Browserstack tunnel (${TUNNEL_LOG}):"
12+
echo "Logfile output of Browserstack tunnel (${tunnelLogFile}):"
913
echo ""
10-
cat ${TUNNEL_LOG}
14+
cat ${tunnelLogFile}
1115
}
1216

1317
# Wait for Connect to be ready before exiting
1418
# Time out if we wait for more than 2 minutes, so the process won't run forever.
1519
let "counter=0"
1620

1721
# Exit the process if there are errors reported. Print the tunnel log to the console.
18-
if [ -f $BROWSER_PROVIDER_ERROR_FILE ]; then
22+
if [ -f ${tunnelErrorFile} ]; then
1923
echo
2024
echo "An error occurred while starting the tunnel. See error:"
2125
printLog
2226
exit 5
2327
fi
2428

25-
while [ ! -f $BROWSER_PROVIDER_READY_FILE ]; do
29+
while [ ! -f ${tunnelReadyFile} ]; do
2630
let "counter++"
2731

2832
# Counter needs to be multiplied by two because the while loop only sleeps a half second.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# In case any command failed, we want to immediately exit the script with the
4+
# proper exit code.
5+
set -e
6+
7+
# Go to project directory.
8+
cd $(dirname ${0})/../..
9+
10+
# Decode access token and make it accessible for child processes.
11+
export BROWSER_STACK_ACCESS_KEY=`echo ${BROWSER_STACK_ACCESS_KEY} | rev`
12+
13+
# Start tunnel and wait for it being ready.
14+
./scripts/browserstack/start-tunnel.sh
15+
./scripts/browserstack/wait-tunnel.sh
16+
17+
# Setup the test platform environment variable that will be read
18+
# by the Karma configuration script.
19+
export TEST_PLATFORM="browserstack"
20+
21+
# Run the unit tests on Browserstack with Karma.
22+
yarn gulp ci:test
23+
24+
# Kill the Browserstack tunnel. This is necessary in order to avoid rate-limit
25+
# errors that cause the unit tests to be flaky.
26+
./scripts/browserstack/stop-tunnel.sh

test/browser-providers.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ function decodeToken(token) {
7171
return (token || '').split('').reverse().join('');
7272
}
7373

74-
75-
/** Ensures that the Travis access keys work properly. */
74+
/** Ensures that the Saucelabs and Browserstack access keys work properly. */
7675
if (process.env.TRAVIS) {
7776
process.env.SAUCE_ACCESS_KEY = decodeToken(process.env.SAUCE_ACCESS_KEY);
7877
process.env.BROWSER_STACK_ACCESS_KEY = decodeToken(process.env.BROWSER_STACK_ACCESS_KEY);

test/karma.conf.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,16 @@ module.exports = (config) => {
101101
});
102102

103103
if (process.env['CIRCLECI']) {
104-
config.browsers = platformMap[process.env['TEST_PLATFORM']];
104+
const buildIdentifier = `angular-material-${process.env['CIRCLE_BUILD_NUM']}`;
105+
const testPlatform = process.env['TEST_PLATFORM'];
106+
107+
if (testPlatform === 'browserstack') {
108+
config.browserStack.build = buildIdentifier;
109+
config.browserStack.tunnelIdentifier = buildIdentifier;
110+
}
111+
112+
// Configure Karma launch the browsers that belong to the given test platform.
113+
config.browsers = platformMap[testPlatform];
105114
}
106115

107116
if (process.env['TRAVIS']) {

0 commit comments

Comments
 (0)