Skip to content

Commit d793043

Browse files
GooglerThomas Césaré-herriau
authored andcommitted
1. NPM Module and Bower component support.
Updated package.json and gulpfile to allow publishing a NPM module. Added a bower.json file to publish a Bower component. Creating a NPM module basically consisted of adding some information in the package.json (`main` - main JS file of the module - and `style` - main stylesheet - properties) and precompiling everything into the dist/ folder. This way developers will have access to the compiled code when installing the module in their project (`npm install firebaseui`). The default gulp command will automatically generate the NPM module. Bower packaging consists of creating the bower.json file. It contains metadata on the component. Developers can then run `bower install firebaseui` and fetch the JS and CSS files in their app by using paths to the dist folder of the bower components (e.g. src="bower_components/dist/firebase-ui-auth.js") Bower file specs: https://github.com/bower/spec/blob/master/json.md 2. Travis and SauceLabs support. Configured Travis to run tests on SauceLabs. I've added a new command: npm test that alias npm run test. It is also the usual default command to run tests in a NPM project. See the sauce_browsers.json file for the list of browsers covered. It sill supports running phantomJS by default, so developers can use it in their local env. How it works: SauceConnect creates a tunnel to remote instances of SauceLabs browsers, which exposes the localhost to the remote instance. This tunnel gets attributed an ID. Protractor then uses this ID to connect to the distant browser and run tests. The HTTP server that serves test files is run locally, and the tunnel is meant for the remote instances to access it. When using Travis, SauceConnect will be automatically started by the process (it's an addon directly offered by Travis). The tunnel ID will be exposed as the TRAVIS_JOB_NUMBER. Travis configuration: https://docs.travis-ci.com/user/languages/javascript-with-nodejs/ Notice I'm using the secure way of storing the access key, so it can safely be pushed to the public GitHub repo. SauceLabs configuration for Travis: https://docs.travis-ci.com/user/sauce-connect/ Using protractor with SauceLabs: https://support.saucelabs.com/customer/portal/articles/2029412-running-protractor-tests-on-sauce-labs A lot of things happen under the hood here, like connecting to the remote browser Webdriver instance through the tunnel. PiperOrigin-RevId: 139406176 Change-Id: Ie5ca57218b3df5ccaee3fc187b8ac20ac31618fd
1 parent 5ed86b5 commit d793043

12 files changed

+802
-28
lines changed

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: node_js
2+
node_js:
3+
- '6'
4+
- '6.0'
5+
- '6.1'
6+
install: npm install
7+
script: npm test -- --saucelabs
8+
addons:
9+
sauce_connect:
10+
username: firebaseui
11+
jwt:
12+
secure: N2XxNudp1yIYrXZ1LIQVnVWW4L5doPIws6a10SHzxttigRXNDK2gQycVTN1MVwyVElVjPyyrLdsB9eRp0fSa0O6/MLc6tlbmt4cOT/zIi96ii3G6L5no9Yod8W5LAr4l2paB9apInghC2zetPGxCS4sW9vKEsIwzTIZZTBnq9AVfU0kpScgnD8/etiYljVTzXp36B65a2T9rXPXnhXKwYyX+TBRULJWhmHoM3FJwUxhMoa41XxxD1+0Zhd+lvBLzPjkRoUUJLR+JFpBDvjhtRkARPiAG+3r07ycrYZAMB87ZypBJOJBrUYA4KlxotPZc7jYEeAmiWJxDoZwwJQeyoI9J42fMEcdqzn7a6bm59jpKHXRwPNed2EY19BtBpXcYMjJRxLFSgWbrKw/hcqi9waaFBO/SXaCtUGPamxYSBHUaS1ljAR7omDkq2aeQAV2E4lgD9od3sgXGqCWzdl33erm4cWgjaNGVQlpNzBdG8zm3C870+x5+pvlsM2/lPCA0RIkIcA5uPmBmQlB8cgzfBCh0x5r6C9wl3TWGW9LaJAB9WZpgkmGk92A1sCnVRufaNYNJm8CwTxM2IK/3xWRc0bEdXpY3I4vA0uMelitWDI9wBIT+HN9TWPQUHzStjlP8PwBAZxf4ab2bB+GLEa5yUyiERK3iyHmX8gvFo14fPEw=

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ how to configure the app to be deployed on a Firebase Hosting instance.
447447
All unit tests can be run on the command line (via PhantomJS) with:
448448

449449
```bash
450-
npm run test
450+
npm test
451451
```
452452

453453
Alternatively, the unit tests can be run manually by running

bower.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "firebaseui-web",
3+
"version": "1.0.0",
4+
"description": "Javascript library for customizable UI on top of Firebase SDK",
5+
"main": [
6+
"./dist/firebase-ui-auth.js",
7+
"./dist/firebase-ui-auth.css"
8+
],
9+
"authors": [
10+
"Google"
11+
],
12+
"license": "Apache-2.0",
13+
"keywords": [
14+
"Firebase",
15+
"authentication"
16+
],
17+
"homepage": "https://github.com/firebase/firebaseui-web",
18+
"ignore": [
19+
"**/.*",
20+
"node_modules",
21+
"generated",
22+
"out"
23+
],
24+
"dependencies": {
25+
"firebase": "^3.3.0"
26+
}
27+
}

buildtools/run_tests.sh

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,72 @@
1717
# creates a local webserver to serve test files, and run protractor.
1818
#
1919
# Usage:
20-
# $ buildtools/run_protractor.sh
20+
#
21+
# ./buildtools/run_tests.sh [--saucelabs [--tunnelIdentifier=<tunnelId>]]
22+
#
23+
# Can take up to two arguments:
24+
# --saucelabs: Use SauceLabs instead of phantomJS.
25+
# --tunnelIdentifier=<tunnelId>: when using SauceLabs, specify the tunnel
26+
# identifier. Otherwise, uses the environment variable TRAVIS_JOB_NUMBER.
27+
#
28+
# Prefer to use the `npm test` command as explained below.
29+
#
30+
# Run locally with PhantomJS:
31+
# $ npm test
32+
# It will start a local Selenium Webdriver server as well as the HTTP server
33+
# that serves test files.
34+
#
35+
# Run locally using SauceLabs:
36+
# Go to your SauceLab account, under "My Account", and copy paste the
37+
# access key. Now export the following variables:
38+
# $ export SAUCE_USERNAME=<your username>
39+
# $ export SAUCE_ACCESS_KEY=<the copy pasted access key>
40+
# Then, start SauceConnect:
41+
# $ ./buildtools/sauce_connect.sh
42+
# Take note of the "Tunnel Identifier" value logged in the terminal.
43+
# Run the tests:
44+
# $ npm run -- --saucelabs --tunnelIdentifier=<the tunnel identifier>
45+
# This will start the HTTP Server locally, and connect through SauceConnect
46+
# to SauceLabs remote browsers instances.
47+
#
48+
# Travis will run `npm test -- --saucelabs`.
2149

2250
cd "$(dirname $(dirname "$0"))"
2351

24-
./node_modules/.bin/webdriver-manager update
25-
2652
function killServer () {
27-
# Selenium Webdriver starts one child process from this one.
28-
# This command kills them all.
29-
kill -- -$seleniumPid
53+
if [ "$seleniumStarted" = true ]; then
54+
echo "Stopping Selenium..."
55+
./node_modules/.bin/webdriver-manager shutdown
56+
./node_modules/.bin/webdriver-manager clean
57+
fi
58+
echo "Killing HTTP Server..."
3059
kill $serverPid
3160
}
3261

33-
# Start Selenium Webdriver.
34-
./node_modules/.bin/webdriver-manager start &>/dev/null &
35-
seleniumPid=$!
36-
3762
# Start the local webserver.
3863
./node_modules/.bin/gulp serve &
3964
serverPid=$!
65+
echo "Local HTTP Server started with PID $serverPid."
4066

4167
trap killServer EXIT
4268

43-
# Wait for servers to come up.
44-
sleep 10
45-
46-
./node_modules/.bin/protractor protractor.conf.js
69+
# If --saucelabs option is passed, forward it to the protractor command adding
70+
# the second argument that is required for local SauceLabs test run.
71+
if [[ $1 = "--saucelabs" ]]; then
72+
seleniumStarted=false
73+
sleep 2
74+
echo "Using SauceLabs."
75+
# $2 contains the tunnelIdentifier argument if specified, otherwise is empty.
76+
./node_modules/.bin/protractor protractor.conf.js --saucelabs $2
77+
else
78+
echo "Using PhantomJS."
79+
# Updates Selenium Webdriver.
80+
./node_modules/.bin/webdriver-manager update
81+
# Start Selenium Webdriver.
82+
./node_modules/.bin/webdriver-manager start &>/dev/null &
83+
seleniumStarted=true
84+
echo "Selenium Server started."
85+
# Wait for servers to come up.
86+
sleep 10
87+
./node_modules/.bin/protractor protractor.conf.js
88+
fi

buildtools/sauce_connect.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# Copyright 2016 Google Inc. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS-IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
#
17+
# Download and install SauceConnect under Linux 64-bit. To be used when testing
18+
# with SauceLabs locally. See the instructions in protractor.conf.js file.
19+
#
20+
# It should not be used on Travis. Travis already handles SauceConnect.
21+
#
22+
# Script copied from the Closure Library repository:
23+
# https://github.com/google/closure-library/blob/master/scripts/ci/sauce_connect.sh
24+
#
25+
26+
# Setup and start Sauce Connect locally.
27+
CONNECT_URL="https://saucelabs.com/downloads/sc-4.4.1-linux.tar.gz"
28+
CONNECT_DIR="/tmp/sauce-connect-$RANDOM"
29+
CONNECT_DOWNLOAD="sc-latest-linux.tar.gz"
30+
31+
BROWSER_PROVIDER_READY_FILE="/tmp/sauce-connect-ready"
32+
33+
# Get Connect and start it.
34+
mkdir -p $CONNECT_DIR
35+
cd $CONNECT_DIR
36+
curl $CONNECT_URL -o $CONNECT_DOWNLOAD 2> /dev/null 1> /dev/null
37+
mkdir sauce-connect
38+
tar --extract --file=$CONNECT_DOWNLOAD --strip-components=1 \
39+
--directory=sauce-connect > /dev/null
40+
rm $CONNECT_DOWNLOAD
41+
42+
function removeFiles() {
43+
echo "Removing SauceConnect files..."
44+
rm -rf $CONNECT_DIR
45+
}
46+
47+
trap removeFiles EXIT
48+
49+
# This will be used by Protractor to connect to SauceConnect.
50+
TUNNEL_IDENTIFIER="tunnelId-$RANDOM"
51+
echo "Tunnel Identifier: $TUNNEL_IDENTIFIER"
52+
53+
echo "Starting Sauce Connect..."
54+
55+
# Start SauceConnect.
56+
sauce-connect/bin/sc -u $SAUCE_USERNAME -k $SAUCE_ACCESS_KEY \
57+
-i $TUNNEL_IDENTIFIER

dist/firebase-ui-auth.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)