[go: nahoru, domu]

Skip to content

Commit

Permalink
fix use of normalizedHostingConfigs when it is called repeatedly (fir…
Browse files Browse the repository at this point in the history
…ebase#2748)

* fix normalizedHostingConfig across multiple calls

* add tests for deploying to a hosting target and deploying a hosting channel to a target
  • Loading branch information
bkendall committed Oct 27, 2020
1 parent cfb5e21 commit 4fe7bcd
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixes issue in `hosting:channel` commands where a Firebase Hosting target may cause configuration parsing issues (#2746).
56 changes: 53 additions & 3 deletions scripts/hosting-tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo "Running with Application Creds: ${GOOGLE_APPLICATION_CREDENTIALS}"

echo "Target project: ${FBTOOLS_TARGET_PROJECT}"

echo "Initalizing some variables..."
echo "Initializing some variables..."
DATE="$(date)"
echo "Variables initalized..."

Expand All @@ -25,7 +25,7 @@ echo "Installing firebase-tools..."
npm link
echo "Installed firebase-tools: $(which firebase)"

echo "Initalizing temp directory..."
echo "Initializing temp directory..."
cd "${TEMP_DIR}"
cat > "firebase.json" <<- EOM
{
Expand All @@ -42,7 +42,7 @@ EOM
mkdir "public"
touch "public/${TARGET_FILE}"
echo "${DATE}" > "public/${TARGET_FILE}"
echo "Initalized temp directory."
echo "Initialized temp directory."

echo "Testing local serve..."
PORT=8685
Expand Down Expand Up @@ -72,3 +72,53 @@ sleep 5
VALUE="$(curl https://${FBTOOLS_TARGET_PROJECT}.web.app/${TARGET_FILE})"
test "${DATE}" = "${VALUE}" || (echo "Expected ${VALUE} to equal ${DATE}." && false)
echo "Tested hosting deployment."

# Test more complex scenarios:
echo "Creating second temp directory..."
TEMP_DIR="$(mktemp -d)"
echo "Created second temp directory: ${TEMP_DIR}"

echo "Initializing a new date..."
DATE="$(date)"
echo "Initialized a new date."

echo "Initializing second temp directory..."
cd "${TEMP_DIR}"
cat > "firebase.json" <<- EOM
{
"hosting": [
{
"target": "customtarget",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
]
}
EOM
mkdir "public"
touch "public/${TARGET_FILE}"
echo "${DATE}" > "public/${TARGET_FILE}"
echo "Setting targets..."
firebase use --add "${FBTOOLS_TARGET_PROJECT}"
firebase target:apply hosting customtarget "${FBTOOLS_TARGET_PROJECT}"
echo "Set targets."
echo "Initialized second temp directory."

echo "Testing hosting deployment by target..."
firebase deploy --only hosting:customtarget --project "${FBTOOLS_TARGET_PROJECT}"
sleep 5
VALUE="$(curl https://${FBTOOLS_TARGET_PROJECT}.web.app/${TARGET_FILE})"
test "${DATE}" = "${VALUE}" || (echo "Expected ${VALUE} to equal ${DATE}." && false)
echo "Tested hosting deployment by target."

echo "Testing hosting channel deployment by target..."
firebase hosting:channel:deploy mychannel --only customtarget --project "${FBTOOLS_TARGET_PROJECT}" --json | tee output.json
sleep 5
CHANNEL_URL=$(cat output.json | jq -r ".result.customtarget.url")
VALUE="$(curl ${CHANNEL_URL}/${TARGET_FILE})"
test "${DATE}" = "${VALUE}" || (echo "Expected ${VALUE} to equal ${DATE}." && false)
echo "Tested hosting channel deployment by target."
3 changes: 2 additions & 1 deletion src/hosting/normalizedHostingConfigs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { bold } from "cli-color";
import { cloneDeep } from "lodash";

import { FirebaseError } from "../error";

Expand Down Expand Up @@ -65,7 +66,7 @@ export function normalizedHostingConfigs(
cmdOptions: any, // eslint-disable-line @typescript-eslint/no-explicit-any
options: { resolveTargets?: boolean } = {}
): HostingConfig[] {
let configs = cmdOptions.config.get("hosting");
let configs = cloneDeep(cmdOptions.config.get("hosting"));
if (!configs) {
return [];
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/hosting/normalizedHostingConfigs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ describe("normalizedHostingConfigs", () => {
);
});

it("should not modify the config when resolving targets", () => {
const singleHostingConfig = { target: "target" };
const cmdConfig = {
site: "default-site",
config: { get: () => singleHostingConfig },
rc: { requireTarget: () => ["default-site"] },
};
normalizedHostingConfigs(cmdConfig, { resolveTargets: true });
expect(singleHostingConfig).to.deep.equal({ target: "target" });
});

describe("without an only parameter", () => {
const DEFAULT_SITE = "default-hosting-site";
const baseConfig = { public: "public", ignore: ["firebase.json"] };
Expand Down

0 comments on commit 4fe7bcd

Please sign in to comment.