add new script for testing hosting

This commit is contained in:
Bryan Kendall
2018-11-02 11:58:55 -07:00
parent 0fddfb3d02
commit 56e38f768c
6 changed files with 81 additions and 3 deletions

View File

@@ -4,8 +4,12 @@ node_js:
- '8'
- '10'
sudo: false
before_script:
- openssl aes-256-cbc -K $encrypted_830857fa25dd_key -iv $encrypted_830857fa25dd_iv -in scripts/creds-public.json.enc -out scripts/creds-public.json -d
- openssl aes-256-cbc -K $encrypted_830857fa25dd_key -iv $encrypted_830857fa25dd_iv -in scripts/creds-private.json.enc -out scripts/creds-private.json -d
after_script:
- nyc report --reporter=text-lcov | coveralls
- ./scripts/test-hosting.sh
cache:
directories:
- node_modules

Binary file not shown.

Binary file not shown.

71
scripts/test-hosting.sh Executable file
View File

@@ -0,0 +1,71 @@
#!/usr/bin/env bash
set -e
CWD="$(pwd)"
TARGET_FILE="${TRAVIS_COMMIT}-${TRAVIS_JOB_ID}"
GOOGLE_APPLICATION_CREDENTIALS="${CWD}/scripts/creds-private.json"
if [ "${TRAVIS_REPO_SLUG}" == "firebase/firebase-tools" ]; then
GOOGLE_APPLICATION_CREDENTIALS="${CWD}/scripts/creds-public.json"
fi
echo "Running in ${CWD}"
echo "Running with node: $(which node)"
echo "Running with npm: $(which npm)"
echo "Running with Application Creds: ${GOOGLE_APPLICATION_CREDENTIALS}"
false
echo "Target project: ${FBTOOLS_TARGET_PROJECT}"
echo "Initalizing some variables..."
DATE="$(date)"
echo "Variables initalized..."
echo "Creating temp directory..."
TEMP_DIR="$(mktemp -d)"
echo "Created temp directory: ${TEMP_DIR}"
echo "Building and packaging firebase-tools..."
npm pack
FBT_PACKAGE="$(pwd)/$(ls *.tgz)"
echo "Built and packaged firebase-tools: ${FBT_PACKAGE}"
echo "Installing firebase-tools..."
npm install --global "${FBT_PACKAGE}"
echo "Installed firebase-tools: $(which firebase)"
echo "Initalizing temp directory..."
cd "${TEMP_DIR}"
cat > "firebase.json" <<- EOM
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
EOM
mkdir "public"
touch "public/${TARGET_FILE}"
echo "${DATE}" > "public/${TARGET_FILE}.txt"
echo "Initalized temp directory."
echo "Testing local serve..."
PORT=8685
firebase serve --only hosting --project "${FBTOOLS_TARGET_PROJECT}" --port "${PORT}" &
PID="$!"
sleep 5
VALUE="$(curl localhost:${PORT}/${TARGET_FILE})"
test "${DATE}" = "${VALUE}" || (echo "Expected ${VALUE} to equal ${DATE}." && false)
kill "$PID"
echo "Tested local serve."
echo "Testing hosting deployment..."
firebase deploy --only hosting --project "${FBTOOLS_TARGET_PROJECT}"
sleep 5
VALUE="$(curl https://${FBTOOLS_TARGET_PROJECT}.firebaseapp.com/${TARGET_FILE})"
test "${DATE}" = "${VALUE}" || (echo "Expected ${VALUE} to equal ${DATE}." && false)
echo "Tested hosting deployment."

View File

@@ -133,6 +133,9 @@ var api = {
setAccessToken: function(token) {
accessToken = token;
},
getScopes: function() {
return commandScopes;
},
setScopes: function(s) {
commandScopes = _.uniq(
_.flatten(

View File

@@ -33,9 +33,9 @@ function _autoAuth(options, authScopes) {
});
}
module.exports = function(options, authScopes) {
module.exports = function(options) {
api.setScopes([scopes.CLOUD_PLATFORM, scopes.FIREBASE_PLATFORM]);
options.authScopes = api.commandScopes;
options.authScopes = api.getScopes();
var tokens = configstore.get("tokens");
var user = configstore.get("user");
@@ -48,7 +48,7 @@ module.exports = function(options, authScopes) {
} else if (user) {
logger.debug("> authorizing via signed-in user");
} else {
return _autoAuth(options, authScopes);
return _autoAuth(options, options.authScopes);
}
tokenOpt = tokenOpt || process.env.FIREBASE_TOKEN;