@@ -2,6 +2,27 @@ import { Emulators } from "./types";
2
2
import { EmulatorRegistry } from "./registry" ;
3
3
import { expect } from "chai" ;
4
4
import { FakeEmulator } from "./testing/fakeEmulator" ;
5
+ import { shouldStart } from "./controller" ;
6
+ import { Options } from "../options" ;
7
+
8
+ function createMockOptions (
9
+ only : string | undefined ,
10
+ configValues : { [ key : string ] : any } ,
11
+ ) : Options {
12
+ const config = {
13
+ get : ( key : string ) => configValues [ key ] ,
14
+ has : ( key : string ) => ! ! configValues [ key ] ,
15
+ src : {
16
+ emulators : configValues ,
17
+ functions : configValues . functions ,
18
+ } ,
19
+ } ;
20
+ return {
21
+ only,
22
+ config,
23
+ project : "test-project" ,
24
+ } as any ;
25
+ }
5
26
6
27
describe ( "EmulatorController" , ( ) => {
7
28
afterEach ( async ( ) => {
@@ -19,4 +40,68 @@ describe("EmulatorController", () => {
19
40
expect ( EmulatorRegistry . isRunning ( name ) ) . to . be . true ;
20
41
expect ( EmulatorRegistry . getInfo ( name ) ! . port ) . to . eql ( fake . getInfo ( ) . port ) ;
21
42
} ) ;
43
+
44
+ describe ( "shouldStart" , ( ) => {
45
+ it ( "should start the hub if a project is specified" , ( ) => {
46
+ const options = { project : "test-project" } as Options ;
47
+ expect ( shouldStart ( options , Emulators . HUB ) ) . to . be . true ;
48
+ } ) ;
49
+
50
+ it ( "should not start the hub if no project is specified" , ( ) => {
51
+ const options = { } as Options ;
52
+ expect ( shouldStart ( options , Emulators . HUB ) ) . to . be . false ;
53
+ } ) ;
54
+
55
+ it ( "should start the UI if options.ui is true" , ( ) => {
56
+ const options = createMockOptions ( undefined , { } ) ;
57
+ options . ui = true ;
58
+ expect ( shouldStart ( options , Emulators . UI ) ) . to . be . true ;
59
+ } ) ;
60
+
61
+ it ( "should start the UI if a project is specified and a UI-supported emulator is running" , ( ) => {
62
+ const options = createMockOptions ( "firestore" , { firestore : { } } ) ;
63
+ expect ( shouldStart ( options , Emulators . UI ) ) . to . be . true ;
64
+ } ) ;
65
+
66
+ it ( "should not start the UI if no project is specified" , ( ) => {
67
+ const options = createMockOptions ( "firestore" , { firestore : { } } ) ;
68
+ delete options . project ;
69
+ expect ( shouldStart ( options , Emulators . UI ) ) . to . be . false ;
70
+ } ) ;
71
+
72
+ it ( "should not start the UI if no UI-supported emulator is running" , ( ) => {
73
+ const options = createMockOptions ( undefined , { } ) ;
74
+ expect ( shouldStart ( options , Emulators . UI ) ) . to . be . false ;
75
+ } ) ;
76
+
77
+ it ( "should start an emulator if it's in the only string" , ( ) => {
78
+ const options = createMockOptions ( "functions,hosting" , {
79
+ functions : { source : "functions" } ,
80
+ hosting : { } ,
81
+ } ) ;
82
+ expect ( shouldStart ( options , Emulators . FUNCTIONS ) ) . to . be . true ;
83
+ } ) ;
84
+
85
+ it ( "should not start an emulator if it's not in the only string" , ( ) => {
86
+ const options = createMockOptions ( "functions" , {
87
+ functions : { source : "functions" } ,
88
+ hosting : { } ,
89
+ } ) ;
90
+ expect ( shouldStart ( options , Emulators . HOSTING ) ) . to . be . false ;
91
+ } ) ;
92
+
93
+ it ( "should not start an emulator if it's in the only string but has no config" , ( ) => {
94
+ const options = createMockOptions ( "hosting,functions" , {
95
+ hosting : { } ,
96
+ } ) ;
97
+ expect ( shouldStart ( options , Emulators . FUNCTIONS ) ) . to . be . false ;
98
+ } ) ;
99
+
100
+ it ( "should not start functions emulator if source directory is not configured" , ( ) => {
101
+ const options = createMockOptions ( "functions" , {
102
+ functions : { } , // Config is present, but no source
103
+ } ) ;
104
+ expect ( shouldStart ( options , Emulators . FUNCTIONS ) ) . to . be . false ;
105
+ } ) ;
106
+ } ) ;
22
107
} ) . timeout ( 2000 ) ;
0 commit comments