-
Notifications
You must be signed in to change notification settings - Fork 971
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
134 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Enforce webframeworks enablement only on webframeworks sites (#8168) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { expect } from "chai"; | ||
import * as sinon from "sinon"; | ||
|
||
import { setEnabled } from "../../experiments"; | ||
import { FirebaseConfig } from "../../firebaseConfig"; | ||
import * as frameworks from "../../frameworks"; | ||
import * as config from "../../hosting/config"; | ||
import { HostingOptions } from "../../hosting/options"; | ||
import { Options } from "../../options"; | ||
import { prepareFrameworksIfNeeded } from "../index"; | ||
|
||
describe("hosting prepare", () => { | ||
let frameworksStub: sinon.SinonStubbedInstance<typeof frameworks>; | ||
let classicSiteConfig: config.HostingResolved; | ||
let webFrameworkSiteConfig: config.HostingResolved; | ||
let firebaseJson: FirebaseConfig; | ||
let options: HostingOptions & Options; | ||
|
||
beforeEach(() => { | ||
frameworksStub = sinon.stub(frameworks); | ||
|
||
// We're intentionally using pointer references so that editing site | ||
// edits the results of hostingConfig() and changes firebase.json | ||
classicSiteConfig = { | ||
site: "classic", | ||
target: "classic", | ||
public: ".", | ||
}; | ||
webFrameworkSiteConfig = { | ||
site: "webframework", | ||
target: "webframework", | ||
source: "src", | ||
}; | ||
firebaseJson = { | ||
hosting: [classicSiteConfig, webFrameworkSiteConfig], | ||
}; | ||
options = { | ||
cwd: ".", | ||
configPath: ".", | ||
only: "hosting", | ||
except: "", | ||
filteredTargets: ["HOSTING"], | ||
force: false, | ||
json: false, | ||
nonInteractive: false, | ||
interactive: true, | ||
debug: false, | ||
projectId: "project", | ||
config: { | ||
src: firebaseJson, | ||
get: (key: string) => { | ||
if (key === "hosting") { | ||
return firebaseJson.hosting; | ||
} | ||
return null; | ||
}, | ||
} as any, | ||
rc: null as any, | ||
|
||
// Forces caching behavior of hostingConfig call | ||
normalizedHostingConfig: [classicSiteConfig, webFrameworkSiteConfig], | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
sinon.verifyAndRestore(); | ||
}); | ||
|
||
it("deploys classic site without webframeworks disabled", async () => { | ||
setEnabled("webframeworks", false); | ||
options.only = "hosting:classic"; | ||
await expect(prepareFrameworksIfNeeded(["hosting"], options, {})).to.not.be.rejected; | ||
}); | ||
|
||
it("fails webframework deploy with webframeworks disabled", async () => { | ||
setEnabled("webframeworks", false); | ||
options.only = "hosting:webframework"; | ||
await expect(prepareFrameworksIfNeeded(["hosting"], options, {})).to.be.rejectedWith( | ||
/Cannot deploy a web framework from source because the experiment.+webframeworks.+is not enabled/, | ||
); | ||
}); | ||
|
||
it("deploys webframework site with webframeworks enabled", async () => { | ||
setEnabled("webframeworks", true); | ||
options.only = "hosting:webframework"; | ||
await expect(prepareFrameworksIfNeeded(["hosting"], options, {})).to.not.be.rejected; | ||
expect(frameworksStub.prepareFrameworks).to.have.been.calledOnceWith("deploy", ["hosting"]); | ||
}); | ||
|
||
it("deploys classic site with webframeworks enabled", async () => { | ||
setEnabled("webframeworks", true); | ||
options.only = "hosting:classic"; | ||
await expect(prepareFrameworksIfNeeded(["hosting"], options, {})).to.not.be.rejected; | ||
expect(frameworksStub.prepareFrameworks).to.not.have.been.called; | ||
}); | ||
|
||
it("fails when at least one site has webframeworks enabled and the experiment is disabled", async () => { | ||
setEnabled("webframeworks", false); | ||
options.only = "hosting"; | ||
await expect(prepareFrameworksIfNeeded(["hosting"], options, {})).to.be.rejectedWith( | ||
/Cannot deploy a web framework from source because the experiment.+webframeworks.+is not enabled/, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters