-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Removing webframeworks questions from init hosting #9843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joehan
wants to merge
1
commit into
main
Choose a base branch
from
jh-remove-wf
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+248
−138
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,210 @@ | ||
| import { expect } from "chai"; | ||
| import * as sinon from "sinon"; | ||
| import * as prompt from "../../../prompt"; | ||
| import * as config from "../../../config"; | ||
| import * as getDefaultHostingSiteMod from "../../../getDefaultHostingSite"; | ||
| import * as hostingInteractive from "../../../hosting/interactive"; | ||
| import * as hostingApi from "../../../hosting/api"; | ||
| import { Client } from "../../../apiv2"; | ||
| import { askQuestions, actuate } from "./index"; | ||
| import { Setup } from "../.."; | ||
| import * as github from "./github"; | ||
|
|
||
| describe("hosting feature init", () => { | ||
| let sandbox: sinon.SinonSandbox; | ||
|
|
||
| beforeEach(() => { | ||
| sandbox = sinon.createSandbox(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sandbox.restore(); | ||
| }); | ||
|
|
||
| describe("askQuestions", () => { | ||
| it("should prompt for public directory and spa", async () => { | ||
| const setup: Setup = { | ||
| config: {}, | ||
| rcfile: { projects: {}, targets: {}, etags: {} }, | ||
| projectId: "test-project", | ||
| instructions: [], | ||
| }; | ||
| const cfg = new config.Config({}, { projectDir: "/", cwd: "/" }); | ||
|
|
||
| // Mock existing site check | ||
| sandbox.stub(getDefaultHostingSiteMod, "getDefaultHostingSite").resolves("test-site"); | ||
|
|
||
| const inputStub = sandbox.stub(prompt, "input").resolves("public"); | ||
| const confirmStub = sandbox.stub(prompt, "confirm").resolves(false); | ||
| sandbox.stub(github, "initGitHub").resolves(); | ||
|
|
||
| await askQuestions(setup, cfg, { | ||
| cwd: "/", | ||
| configPath: "", | ||
| only: "", | ||
| except: "", | ||
| nonInteractive: false, | ||
| } as any); | ||
|
|
||
| expect( | ||
| inputStub.calledWith( | ||
| sinon.match({ message: "What do you want to use as your public directory?" }), | ||
| ), | ||
| ).to.be.true; | ||
| expect( | ||
| confirmStub.calledWith( | ||
| sinon.match("Configure as a single-page app (rewrite all urls to /index.html)?"), | ||
| ), | ||
| ).to.be.true; | ||
|
|
||
| expect(setup.featureInfo?.hosting).to.deep.include({ | ||
| public: "public", | ||
| spa: false, | ||
| }); | ||
| }); | ||
|
|
||
| it("should prompt to create a site if none exists", async () => { | ||
| const setup: Setup = { | ||
| config: {}, | ||
| rcfile: { projects: {}, targets: {}, etags: {} }, | ||
| projectId: "test-project", | ||
| instructions: [], | ||
| }; | ||
| const cfg = new config.Config({}, { projectDir: "/", cwd: "/" }); | ||
|
|
||
| sandbox | ||
| .stub(getDefaultHostingSiteMod, "getDefaultHostingSite") | ||
| .rejects(getDefaultHostingSiteMod.errNoDefaultSite); | ||
| sandbox.stub(prompt, "confirm").resolves(true); | ||
| const pickSiteStub = sandbox | ||
| .stub(hostingInteractive, "pickHostingSiteName") | ||
| .resolves("new-site-id"); | ||
| sandbox.stub(prompt, "input").resolves("public"); | ||
| sandbox.stub(github, "initGitHub").resolves(); | ||
|
|
||
| await askQuestions(setup, cfg, { | ||
| cwd: "/", | ||
| configPath: "", | ||
| only: "", | ||
| except: "", | ||
| nonInteractive: false, | ||
| } as any); | ||
|
|
||
| expect(pickSiteStub.called).to.be.true; | ||
| expect(setup.featureInfo?.hosting?.newSiteId).to.equal("new-site-id"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("actuate", () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| it("should write 404.html and index.html for non-SPA", async () => { | ||
| const setup: Setup = { | ||
| config: {}, | ||
| rcfile: { projects: {}, targets: {}, etags: {} }, | ||
| projectId: "test-project", | ||
| featureInfo: { | ||
| hosting: { | ||
| public: "public", | ||
| spa: false, | ||
| }, | ||
| }, | ||
| instructions: [], | ||
| }; | ||
| const cfg = new config.Config({}, { projectDir: "/", cwd: "/" }); | ||
| const askWriteStub = sandbox.stub(cfg, "askWriteProjectFile").resolves(); | ||
|
|
||
| const clientStub = sandbox.stub(Client.prototype, "get").resolves({ | ||
| body: { current: { version: "1.2.3" } }, | ||
| status: 200, | ||
| response: {} as any, | ||
| }); | ||
|
|
||
| await actuate(setup, cfg, { | ||
| cwd: "/", | ||
| configPath: "", | ||
| only: "", | ||
| except: "", | ||
| nonInteractive: false, | ||
| } as any); | ||
|
|
||
| expect(askWriteStub.calledTwice).to.be.true; | ||
| expect(askWriteStub.firstCall.args[0]).to.equal("public/404.html"); | ||
| expect(askWriteStub.secondCall.args[0]).to.equal("public/index.html"); | ||
| expect(clientStub.calledWith("/firebasejs/releases.json")).to.be.true; | ||
| }); | ||
|
|
||
| it("should configure rewrites for SPA", async () => { | ||
| const setup: Setup = { | ||
| config: {}, | ||
| rcfile: { projects: {}, targets: {}, etags: {} }, | ||
| projectId: "test-project", | ||
| featureInfo: { | ||
| hosting: { | ||
| public: "public", | ||
| spa: true, | ||
| }, | ||
| }, | ||
| instructions: [], | ||
| }; | ||
| const cfg = new config.Config({}, { projectDir: "/", cwd: "/" }); | ||
| const askWriteStub = sandbox.stub(cfg, "askWriteProjectFile").resolves(); | ||
| sandbox.stub(Client.prototype, "get").resolves({ | ||
| body: { current: { version: "1.2.3" } }, | ||
| status: 200, | ||
| response: {} as any, | ||
| }); | ||
|
|
||
| await actuate(setup, cfg, { | ||
| cwd: "/", | ||
| configPath: "", | ||
| only: "", | ||
| except: "", | ||
| nonInteractive: false, | ||
| } as any); | ||
|
|
||
| expect(setup.config.hosting).to.deep.include({ | ||
| rewrites: [{ source: "**", destination: "/index.html" }], | ||
| }); | ||
| expect(askWriteStub.calledOnce).to.be.true; // Only index.html | ||
| }); | ||
|
|
||
| it("should create site if newSiteId is present", async () => { | ||
| const setup: Setup = { | ||
| config: {}, | ||
| rcfile: { projects: {}, targets: {}, etags: {} }, | ||
| projectId: "test-project", | ||
| featureInfo: { | ||
| hosting: { | ||
| public: "public", | ||
| spa: false, | ||
| newSiteId: "new-site", | ||
| }, | ||
| }, | ||
| instructions: [], | ||
| }; | ||
| const cfg = new config.Config({}, { projectDir: "/", cwd: "/" }); | ||
| sandbox.stub(cfg, "askWriteProjectFile").resolves(); | ||
| sandbox.stub(Client.prototype, "get").resolves({ | ||
| body: { current: { version: "1.2.3" } }, | ||
| status: 200, | ||
| response: {} as any, | ||
| }); | ||
| const createSiteStub = sandbox.stub(hostingApi, "createSite").resolves({ | ||
| name: "new-site", | ||
| defaultUrl: "https://new-site.web.app", | ||
| type: hostingApi.SiteType.DEFAULT_SITE, | ||
| appId: "app-id", | ||
| labels: {}, | ||
| }); | ||
|
|
||
| await actuate(setup, cfg, { | ||
| cwd: "/", | ||
| configPath: "", | ||
| only: "", | ||
| except: "", | ||
| nonInteractive: false, | ||
| } as any); | ||
|
|
||
| expect(createSiteStub.calledWith("test-project", "new-site")).to.be.true; | ||
| }); | ||
| }); | ||
| }).timeout(5000); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock
optionsobject is created inline withas anyin multiple tests. To improve readability, reduce repetition, and make it easier to manage, consider defining a constant for these mock options at the top of thedescribeblock and reusing it in your tests.