@@ -132,3 +132,47 @@ describe('loading environments', async () => {
132132 } )
133133 } )
134134} )
135+
136+ describe ( 'getEnvironmentNames' , ( ) => {
137+ test ( 'returns all environment names' , async ( ) => {
138+ await inTemporaryDirectory ( async ( tmpDir ) => {
139+ // Given
140+ const filePath = joinPath ( tmpDir , fileName )
141+ await writeFile ( filePath , tomlEncode ( { environments : { environment1, environment2} } ) )
142+
143+ // When
144+ const names = await environments . getEnvironmentNames ( fileName , { from : tmpDir } )
145+
146+ // Then
147+ expect ( names ) . toEqual ( [ 'environment1' , 'environment2' ] )
148+ } )
149+ } )
150+
151+ describe ( 'when no environment file exists' , ( ) => {
152+ test ( 'returns empty array' , async ( ) => {
153+ await inTemporaryDirectory ( async ( tmpDir ) => {
154+ // When
155+ const names = await environments . getEnvironmentNames ( fileName , { from : tmpDir } )
156+
157+ // Then
158+ expect ( names ) . toEqual ( [ ] )
159+ } )
160+ } )
161+ } )
162+
163+ describe ( 'when environment file is empty' , ( ) => {
164+ test ( 'returns empty array' , async ( ) => {
165+ await inTemporaryDirectory ( async ( tmpDir ) => {
166+ // Given
167+ const filePath = joinPath ( tmpDir , fileName )
168+ await writeFile ( filePath , '# no content' )
169+
170+ // When
171+ const names = await environments . getEnvironmentNames ( fileName , { from : tmpDir } )
172+
173+ // Then
174+ expect ( names ) . toEqual ( [ ] )
175+ } )
176+ } )
177+ } )
178+ } )
0 commit comments