|
| 1 | +import { expect } from "chai"; |
| 2 | +import * as sinon from "sinon"; |
| 3 | +import { Delegate } from "./index"; |
| 4 | +import * as discovery from "../discovery"; |
| 5 | +import * as build from "../../build"; |
| 6 | +import * as supported from "../supported"; |
| 7 | + |
| 8 | +describe("Dart Runtime Delegate", () => { |
| 9 | + describe("discoverBuild", () => { |
| 10 | + let detectFromYamlStub: sinon.SinonStub; |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + detectFromYamlStub = sinon.stub(discovery, "detectFromYaml"); |
| 14 | + }); |
| 15 | + |
| 16 | + afterEach(() => { |
| 17 | + sinon.restore(); |
| 18 | + }); |
| 19 | + |
| 20 | + it("should not set default timeout", async () => { |
| 21 | + const delegate = new Delegate("project", "sourceDir", supported.latest("dart")); |
| 22 | + |
| 23 | + const mockBuild: build.Build = { |
| 24 | + endpoints: { |
| 25 | + func1: { |
| 26 | + platform: "gcfv2", |
| 27 | + entryPoint: "func1", |
| 28 | + project: "project", |
| 29 | + runtime: supported.latest("dart"), |
| 30 | + httpsTrigger: {}, |
| 31 | + }, |
| 32 | + }, |
| 33 | + params: [], |
| 34 | + requiredAPIs: [], |
| 35 | + }; |
| 36 | + |
| 37 | + detectFromYamlStub.resolves(mockBuild); |
| 38 | + |
| 39 | + const result = await delegate.discoverBuild({}, {}); |
| 40 | + |
| 41 | + expect(result.endpoints.func1.timeoutSeconds).to.be.undefined; |
| 42 | + expect(result.endpoints.func1.platform).to.equal("run"); |
| 43 | + }); |
| 44 | + |
| 45 | + it("should preserve user-defined timeout", async () => { |
| 46 | + const delegate = new Delegate("project", "sourceDir", supported.latest("dart")); |
| 47 | + |
| 48 | + const mockBuild: build.Build = { |
| 49 | + endpoints: { |
| 50 | + func1: { |
| 51 | + platform: "gcfv2", |
| 52 | + entryPoint: "func1", |
| 53 | + project: "project", |
| 54 | + runtime: supported.latest("dart"), |
| 55 | + httpsTrigger: {}, |
| 56 | + timeoutSeconds: 120, |
| 57 | + }, |
| 58 | + }, |
| 59 | + params: [], |
| 60 | + requiredAPIs: [], |
| 61 | + }; |
| 62 | + |
| 63 | + detectFromYamlStub.resolves(mockBuild); |
| 64 | + |
| 65 | + const result = await delegate.discoverBuild({}, {}); |
| 66 | + |
| 67 | + expect(result.endpoints.func1.timeoutSeconds).to.equal(120); |
| 68 | + expect(result.endpoints.func1.platform).to.equal("run"); |
| 69 | + }); |
| 70 | + |
| 71 | + it("should not apply default timeout in emulator mode", async () => { |
| 72 | + const delegate = new Delegate("project", "sourceDir", supported.latest("dart")); |
| 73 | + |
| 74 | + const mockBuild: build.Build = { |
| 75 | + endpoints: { |
| 76 | + func1: { |
| 77 | + platform: "gcfv2", |
| 78 | + entryPoint: "func1", |
| 79 | + project: "project", |
| 80 | + runtime: supported.latest("dart"), |
| 81 | + httpsTrigger: {}, |
| 82 | + }, |
| 83 | + }, |
| 84 | + params: [], |
| 85 | + requiredAPIs: [], |
| 86 | + }; |
| 87 | + |
| 88 | + detectFromYamlStub.resolves(mockBuild); |
| 89 | + |
| 90 | + const result = await delegate.discoverBuild({}, { FUNCTIONS_EMULATOR: "true" }); |
| 91 | + |
| 92 | + expect(result.endpoints.func1.timeoutSeconds).to.be.undefined; |
| 93 | + // Platform should not be converted to "run" in emulator mode either |
| 94 | + expect(result.endpoints.func1.platform).to.equal("gcfv2"); |
| 95 | + }); |
| 96 | + }); |
| 97 | +}); |
0 commit comments