|
| 1 | +import { EmulatorFlagsManager } from "./emulator-flags-manager"; |
| 2 | + |
| 3 | +describe("EmulatorFlagsManager", () => { |
| 4 | + it("should add flag without --", async () => { |
| 5 | + const flagsManager = new EmulatorFlagsManager().withFlag("database-mode", "firestore-native"); |
| 6 | + |
| 7 | + const flags = flagsManager.expandFlags(); |
| 8 | + |
| 9 | + expect(flags.trim()).toEqual("--database-mode=firestore-native"); |
| 10 | + }); |
| 11 | + |
| 12 | + it("should add flag with --", async () => { |
| 13 | + const flagsManager = new EmulatorFlagsManager().withFlag("--database-mode", "firestore-native"); |
| 14 | + |
| 15 | + const flags = flagsManager.expandFlags(); |
| 16 | + |
| 17 | + expect(flags.trim()).toEqual("--database-mode=firestore-native"); |
| 18 | + }); |
| 19 | + |
| 20 | + it("should add many flags", async () => { |
| 21 | + const flagsManager = new EmulatorFlagsManager() |
| 22 | + .withFlag("database-mode", "firestore-native") |
| 23 | + .withFlag("--host-port", "0.0.0.0:8080"); |
| 24 | + |
| 25 | + const flags = flagsManager.expandFlags(); |
| 26 | + |
| 27 | + expect(flags.trim()).toEqual("--database-mode=firestore-native --host-port=0.0.0.0:8080"); |
| 28 | + }); |
| 29 | + |
| 30 | + it("should overwrite same flag if added more than once", async () => { |
| 31 | + const flagsManager = new EmulatorFlagsManager() |
| 32 | + .withFlag("database-mode", "firestore-native") |
| 33 | + .withFlag("--database-mode", "datastore-mode"); |
| 34 | + |
| 35 | + const flags = flagsManager.expandFlags(); |
| 36 | + |
| 37 | + expect(flags.trim()).toEqual("--database-mode=datastore-mode"); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should add flag with no value", async () => { |
| 41 | + const flagsManager = new EmulatorFlagsManager().withFlag("database-mode", "").withFlag("--host-port", ""); |
| 42 | + |
| 43 | + const flags = flagsManager.expandFlags(); |
| 44 | + |
| 45 | + expect(flags.trim()).toEqual("--database-mode --host-port"); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should throw if flag name not set", async () => { |
| 49 | + expect(() => new EmulatorFlagsManager().withFlag("", "firestore-native")).toThrowError(); |
| 50 | + }); |
| 51 | + |
| 52 | + it("should clear all flags added", async () => { |
| 53 | + const flagsManager = new EmulatorFlagsManager() |
| 54 | + .withFlag("database-mode", "firestore-native") |
| 55 | + .withFlag("host-port", "0.0.0.0:8080"); |
| 56 | + |
| 57 | + flagsManager.clearFlags(); |
| 58 | + const flags = flagsManager.expandFlags(); |
| 59 | + |
| 60 | + expect(flags.trim()).toEqual(""); |
| 61 | + }); |
| 62 | +}); |
0 commit comments