3
3
getInspectInfo ,
4
4
getPort ,
5
5
getUrl ,
6
- WrappedStartCliFlags ,
7
- } from '../../../src/runtime/cli/config' ;
6
+ StartCliConfig ,
7
+ StartCliFlags ,
8
+ } from '../../src/config/start' ;
8
9
9
10
jest . mock ( 'ngrok' , ( ) => {
10
11
return {
@@ -20,32 +21,26 @@ jest.mock('ngrok', () => {
20
21
describe ( 'getUrl' , ( ) => {
21
22
test ( 'returns localhost if ngrok is not passed' , async ( ) => {
22
23
const config = ( {
23
- flags : {
24
- ngrok : undefined ,
25
- } ,
26
- } as unknown ) as WrappedStartCliFlags ;
24
+ ngrok : undefined ,
25
+ } as unknown ) as StartCliFlags ;
27
26
28
27
const url = await getUrl ( config , 3000 ) ;
29
28
expect ( url ) . toBe ( 'http://localhost:3000' ) ;
30
29
} ) ;
31
30
32
31
test ( 'calls ngrok if ngrok is defined' , async ( ) => {
33
32
const config = ( {
34
- flags : {
35
- ngrok : '' ,
36
- } ,
37
- } as unknown ) as WrappedStartCliFlags ;
33
+ ngrok : '' ,
34
+ } as unknown ) as StartCliFlags ;
38
35
39
36
const url = await getUrl ( config , 3000 ) ;
40
37
expect ( url ) . toBe ( 'https://random.ngrok.io' ) ;
41
38
} ) ;
42
39
43
40
test ( 'calls ngrok with custom subdomain if passed' , async ( ) => {
44
41
const config = ( {
45
- flags : {
46
- ngrok : 'dom' ,
47
- } ,
48
- } as unknown ) as WrappedStartCliFlags ;
42
+ ngrok : 'dom' ,
43
+ } as unknown ) as StartCliFlags ;
49
44
50
45
const url = await getUrl ( config , 3000 ) ;
51
46
expect ( url ) . toBe ( 'https://dom.ngrok.io' ) ;
@@ -69,10 +64,8 @@ describe('getPort', () => {
69
64
70
65
test ( 'returns default 3000 if nothing is passed' , ( ) => {
71
66
const config = ( {
72
- flags : {
73
- port : undefined ,
74
- } ,
75
- } as unknown ) as WrappedStartCliFlags ;
67
+ port : undefined ,
68
+ } as unknown ) as StartCliFlags ;
76
69
77
70
delete process . env . PORT ;
78
71
const port = getPort ( config ) ;
@@ -81,10 +74,8 @@ describe('getPort', () => {
81
74
82
75
test ( 'checks for process.env.PORT and returns number' , ( ) => {
83
76
const config = ( {
84
- flags : {
85
- port : undefined ,
86
- } ,
87
- } as unknown ) as WrappedStartCliFlags ;
77
+ port : undefined ,
78
+ } as unknown ) as StartCliFlags ;
88
79
89
80
process . env . PORT = '9999' ;
90
81
const port = getPort ( config ) ;
@@ -94,10 +85,8 @@ describe('getPort', () => {
94
85
95
86
test ( 'port passed via flag takes preference' , ( ) => {
96
87
const config = ( {
97
- flags : {
98
- port : 1234 ,
99
- } ,
100
- } as unknown ) as WrappedStartCliFlags ;
88
+ port : 1234 ,
89
+ } as unknown ) as StartCliFlags ;
101
90
102
91
process . env . PORT = '9999' ;
103
92
const port = getPort ( config ) ;
@@ -107,10 +96,8 @@ describe('getPort', () => {
107
96
108
97
test ( 'handles strings and returns number' , ( ) => {
109
98
const config = ( {
110
- flags : {
111
- port : '8080' ,
112
- } ,
113
- } as unknown ) as WrappedStartCliFlags ;
99
+ port : '8080' ,
100
+ } as unknown ) as StartCliFlags ;
114
101
115
102
process . env . PORT = '9999' ;
116
103
const port = getPort ( config ) ;
@@ -138,79 +125,65 @@ describe('getBaseDirectory', () => {
138
125
139
126
test ( 'handles current working directory if none is passed' , ( ) => {
140
127
const config = ( {
141
- flags : {
142
- dir : undefined ,
143
- cwd : undefined ,
144
- } ,
145
- } as unknown ) as WrappedStartCliFlags ;
128
+ dir : undefined ,
129
+ cwd : undefined ,
130
+ } as unknown ) as StartCliFlags ;
146
131
147
132
const result = getBaseDirectory ( config ) ;
148
133
expect ( result ) . toBe ( '/home' ) ;
149
134
} ) ;
150
135
151
136
test ( 'supports dir argument' , ( ) => {
152
137
const config = ( {
153
- flags : {
154
- dir : '/usr/local' ,
155
- cwd : undefined ,
156
- } ,
157
- } as unknown ) as WrappedStartCliFlags ;
138
+ dir : '/usr/local' ,
139
+ cwd : undefined ,
140
+ } as unknown ) as StartCliFlags ;
158
141
159
142
const result = getBaseDirectory ( config ) ;
160
143
expect ( result ) . toBe ( '/usr/local' ) ;
161
144
} ) ;
162
145
163
146
test ( 'prefers cwd over dir argument' , ( ) => {
164
147
const config = ( {
165
- flags : {
166
- dir : '/usr/local' ,
167
- cwd : '/usr/bin' ,
168
- } ,
169
- } as unknown ) as WrappedStartCliFlags ;
148
+ dir : '/usr/local' ,
149
+ cwd : '/usr/bin' ,
150
+ } as unknown ) as StartCliFlags ;
170
151
171
152
const result = getBaseDirectory ( config ) ;
172
153
expect ( result ) . toBe ( '/usr/bin' ) ;
173
154
} ) ;
174
155
175
156
test ( 'handles relative path for dir' , ( ) => {
176
157
let config = ( {
177
- flags : {
178
- dir : 'demo' ,
179
- cwd : undefined ,
180
- } ,
181
- } as unknown ) as WrappedStartCliFlags ;
158
+ dir : 'demo' ,
159
+ cwd : undefined ,
160
+ } as unknown ) as StartCliFlags ;
182
161
183
162
let result = getBaseDirectory ( config ) ;
184
163
expect ( result ) . toBe ( '/home/demo' ) ;
185
164
186
165
config = ( {
187
- flags : {
188
- dir : '../demo' ,
189
- cwd : undefined ,
190
- } ,
191
- } as unknown ) as WrappedStartCliFlags ;
166
+ dir : '../demo' ,
167
+ cwd : undefined ,
168
+ } as unknown ) as StartCliFlags ;
192
169
193
170
result = getBaseDirectory ( config ) ;
194
171
expect ( result ) . toBe ( '/demo' ) ;
195
172
} ) ;
196
173
197
174
test ( 'handles relative path for cwd' , ( ) => {
198
175
let config = ( {
199
- flags : {
200
- dir : undefined ,
201
- cwd : 'demo' ,
202
- } ,
203
- } as unknown ) as WrappedStartCliFlags ;
176
+ dir : undefined ,
177
+ cwd : 'demo' ,
178
+ } as unknown ) as StartCliFlags ;
204
179
205
180
let result = getBaseDirectory ( config ) ;
206
181
expect ( result ) . toBe ( '/home/demo' ) ;
207
182
208
183
config = ( {
209
- flags : {
210
- dir : undefined ,
211
- cwd : '../demo' ,
212
- } ,
213
- } as unknown ) as WrappedStartCliFlags ;
184
+ dir : undefined ,
185
+ cwd : '../demo' ,
186
+ } as unknown ) as StartCliFlags ;
214
187
215
188
result = getBaseDirectory ( config ) ;
216
189
expect ( result ) . toBe ( '/demo' ) ;
@@ -220,59 +193,49 @@ describe('getBaseDirectory', () => {
220
193
describe ( 'getInspectInfo' , ( ) => {
221
194
test ( 'returns undefined if nothing is passed' , ( ) => {
222
195
const config = ( {
223
- flags : {
224
- inspect : undefined ,
225
- inspectBrk : undefined ,
226
- } ,
227
- } as unknown ) as WrappedStartCliFlags ;
196
+ inspect : undefined ,
197
+ inspectBrk : undefined ,
198
+ } as unknown ) as StartCliFlags ;
228
199
229
200
const result = getInspectInfo ( config ) ;
230
201
expect ( result ) . toBeUndefined ( ) ;
231
202
} ) ;
232
203
233
204
test ( 'handles present but empty inspect flag' , ( ) => {
234
205
const config = ( {
235
- flags : {
236
- inspect : '' ,
237
- inspectBrk : undefined ,
238
- } ,
239
- } as unknown ) as WrappedStartCliFlags ;
206
+ inspect : '' ,
207
+ inspectBrk : undefined ,
208
+ } as unknown ) as StartCliFlags ;
240
209
241
210
const result = getInspectInfo ( config ) ;
242
211
expect ( result ) . toEqual ( { hostPort : '' , break : false } ) ;
243
212
} ) ;
244
213
245
214
test ( 'handles present but empty inspectBrk flag' , ( ) => {
246
215
const config = ( {
247
- flags : {
248
- inspect : undefined ,
249
- inspectBrk : '' ,
250
- } ,
251
- } as unknown ) as WrappedStartCliFlags ;
216
+ inspect : undefined ,
217
+ inspectBrk : '' ,
218
+ } as unknown ) as StartCliFlags ;
252
219
253
220
const result = getInspectInfo ( config ) ;
254
221
expect ( result ) . toEqual ( { hostPort : '' , break : true } ) ;
255
222
} ) ;
256
223
257
224
test ( 'handles passed port in inspect flag' , ( ) => {
258
225
const config = ( {
259
- flags : {
260
- inspect : '9999' ,
261
- inspectBrk : undefined ,
262
- } ,
263
- } as unknown ) as WrappedStartCliFlags ;
226
+ inspect : '9999' ,
227
+ inspectBrk : undefined ,
228
+ } as unknown ) as StartCliFlags ;
264
229
265
230
const result = getInspectInfo ( config ) ;
266
231
expect ( result ) . toEqual ( { hostPort : '9999' , break : false } ) ;
267
232
} ) ;
268
233
269
234
test ( 'handles passed port in inspect flag' , ( ) => {
270
235
const config = ( {
271
- flags : {
272
- inspect : undefined ,
273
- inspectBrk : '1234' ,
274
- } ,
275
- } as unknown ) as WrappedStartCliFlags ;
236
+ inspect : undefined ,
237
+ inspectBrk : '1234' ,
238
+ } as unknown ) as StartCliFlags ;
276
239
277
240
const result = getInspectInfo ( config ) ;
278
241
expect ( result ) . toEqual ( { hostPort : '1234' , break : true } ) ;
0 commit comments