feat: make result for config --services command type safe

This commit is contained in:
Alexander Zeitler 2021-04-11 15:47:02 +02:00
parent a2f5a4ec0e
commit 6f105ca160
2 changed files with 19 additions and 5 deletions

View file

@ -27,6 +27,10 @@ export type DockerComposeConfigResult = {
}
}
export type DockerComposeConfigServicesResult = {
services: string[]
}
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
follow?: boolean
}
@ -316,10 +320,19 @@ export const config = async function (
}
}
export const configServices = function (
export const configServices = async function (
options?: IDockerComposeOptions
): Promise<IDockerComposeResult> {
return execCompose('config', ['--services'], options)
): Promise<TypedDockerComposeResult<DockerComposeConfigServicesResult>> {
try {
const result = await execCompose('config', ['--services'], options)
const services = result.out.split('\n')
return {
...result,
data: { services }
}
} catch (error) {
return Promise.reject(error)
}
}
export const configVolumes = function (

View file

@ -525,11 +525,12 @@ test('config show data for docker-compose files (services)', async (): Promise<v
const std = await compose.configServices({
cwd: path.join(__dirname),
log: logOutput,
config: 'docker-compose-42.yml'
config: 'docker-compose-build.yml'
})
expect(std.data.services.length).toBe(6)
expect(std.data.services[0]).toBe('build_test_1')
expect(std.err).toBeFalsy()
expect(std.out.includes('some-service')).toBeTruthy()
})
test('config show data for docker-compose files (volumes)', async (): Promise<void> => {