mirror of
https://github.com/zhigang1992/firebase-tools.git
synced 2026-01-12 17:22:36 +08:00
adding a type for the options object
This commit is contained in:
@@ -4,12 +4,16 @@ import { fetch } from "../fetchWebSetup";
|
||||
|
||||
const INIT_TEMPLATE = readFileSync(`${__dirname}/../../templates/hosting/init.js`, "utf8");
|
||||
|
||||
export interface ImplicitInitRequest {
|
||||
projectNumber: number;
|
||||
}
|
||||
|
||||
export interface ImplicitInitResponse {
|
||||
js: string;
|
||||
json: string;
|
||||
}
|
||||
|
||||
export async function init(options: any): Promise<ImplicitInitResponse> {
|
||||
export async function init(options: ImplicitInitRequest): Promise<ImplicitInitResponse> {
|
||||
const config = await fetch(options);
|
||||
const configJson = JSON.stringify(config, null, 2);
|
||||
return {
|
||||
|
||||
@@ -15,15 +15,15 @@ describe("implicitInit", () => {
|
||||
afterEach(() => sandbox.restore());
|
||||
|
||||
it("should fetch the information about the project", async () => {
|
||||
await init({});
|
||||
await init({ projectNumber: 1 });
|
||||
|
||||
sinon.assert.calledOnce(fetchWebSetup.fetch as sinon.SinonStub);
|
||||
sinon.assert.calledWithExactly(fetchWebSetup.fetch as sinon.SinonStub, {});
|
||||
sinon.assert.calledWithExactly(fetchWebSetup.fetch as sinon.SinonStub, { projectNumber: 1 });
|
||||
});
|
||||
|
||||
it("should insert the config into the js value returned", async () => {
|
||||
(fetchWebSetup.fetch as sinon.SinonStub).resolves({ foo: "bar" });
|
||||
const data = await init({});
|
||||
const data = await init({ projectNumber: 1 });
|
||||
|
||||
expect(data.js).to.contain(`"foo": "bar"`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user