diff --git a/src/emulator/apphosting/serve.spec.ts b/src/emulator/apphosting/serve.spec.ts index 819c080b3f1..8a94a461ebe 100644 --- a/src/emulator/apphosting/serve.spec.ts +++ b/src/emulator/apphosting/serve.spec.ts @@ -8,6 +8,8 @@ import * as utils from "./developmentServer"; import * as configsImport from "./config"; import * as projectPathImport from "../../projectPath"; import { AppHostingYamlConfig } from "../../apphosting/yaml"; +import * as emulatorRegistry from "../registry"; +import * as emulatorEnvs from "../env"; describe("serve", () => { let checkListenableStub: sinon.SinonStub; @@ -16,6 +18,8 @@ describe("serve", () => { let detectStartCommandStub: sinon.SinonStub; let configsStub: sinon.SinonStubbedInstance; let resolveProjectPathStub: sinon.SinonStub; + let listRunningWithInfoStub: sinon.SinonStub; + let setEnvVarsForEmulatorsStub: sinon.SinonStub; beforeEach(() => { checkListenableStub = sinon.stub(portUtils, "checkListenable"); @@ -25,6 +29,9 @@ describe("serve", () => { configsStub = sinon.stub(configsImport); resolveProjectPathStub = sinon.stub(projectPathImport, "resolveProjectPath"); + listRunningWithInfoStub = sinon.stub(emulatorRegistry.EmulatorRegistry, "listRunningWithInfo"); + setEnvVarsForEmulatorsStub = sinon.stub(emulatorEnvs, "setEnvVarsForEmulators"); + resolveProjectPathStub.returns(""); detectStartCommandStub.returns("npm run dev"); }); @@ -37,6 +44,10 @@ describe("serve", () => { }); describe("start", () => { + beforeEach(() => { + listRunningWithInfoStub.returns([]); + }); + it("should use user-provided port if one is defined", async () => { checkListenableStub.onFirstCall().returns(true); configsStub.getLocalAppHostingConfiguration.returns( @@ -71,4 +82,13 @@ describe("serve", () => { expect(spawnWithCommandStringStub.getCall(0).args[0]).to.eq(startCommand); }); }); + + describe("getEmulatorEnvs", () => { + it("should omit apphosting emulator", () => { + listRunningWithInfoStub.returns([{ name: "apphosting" }, { name: "functions" }]); + serve.getEmulatorEnvs(); + + expect(setEnvVarsForEmulatorsStub).to.be.calledWith({}, [{ name: "functions" }]); + }); + }); }); diff --git a/src/emulator/apphosting/serve.ts b/src/emulator/apphosting/serve.ts index 3e31a0dcdf3..cc8760a8747 100644 --- a/src/emulator/apphosting/serve.ts +++ b/src/emulator/apphosting/serve.ts @@ -85,9 +85,14 @@ function availablePort(host: string, port: number): Promise { }); } -function getEmulatorEnvs(): Record { +/** + * Exported for unit tests + */ +export function getEmulatorEnvs(): Record { const envs: Record = {}; - const emulatorInfos = EmulatorRegistry.listRunningWithInfo(); + const emulatorInfos = EmulatorRegistry.listRunningWithInfo().filter( + (emulator) => emulator.name !== Emulators.APPHOSTING, // No need to set envs for the apphosting emulator itself. + ); setEnvVarsForEmulators(envs, emulatorInfos); return envs;