From 3cea146b6ed413374e9767750dcb1b5e933c2e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Gonz=C3=A1lez?= Date: Thu, 15 Aug 2019 08:59:55 +0200 Subject: [PATCH] Add stopOne command --- readme.md | 1 + src/index.ts | 4 ++++ test/index.test.ts | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/readme.md b/readme.md index 15bffbe..b0055db 100644 --- a/readme.md +++ b/readme.md @@ -26,6 +26,7 @@ npm install --save-dev docker-compose * `down(options)` - Stops containers and removes containers, networks, volumes, and images created by `up` * `kill(options)` - Force stop service containers * `stop(options)` - Stop running containers without removing them +* `stopOne(service, options)` - Stops one container without removing it * `rm(options)` - Remove stopped service containers - always uses the `-f` flag due to non interactive mode * `exec(container, command, options)` - Exec `command` inside `container`, uses `-T` to properly handle stdin & stdout * `logs(services, options)` - Show logs of service(s). Use `options.follow` `true|false` to turn on `--follow` flag. diff --git a/src/index.ts b/src/index.ts index 424e3dd..d1c88ea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -128,6 +128,10 @@ export const stop = function (options?: IDockerComposeOptions): Promise { + return execCompose('stop', [ service ], options); +}; + export const kill = function (options?: IDockerComposeOptions): Promise { return execCompose('kill', [], options); }; diff --git a/test/index.test.ts b/test/index.test.ts index 11add9d..9964d16 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -172,6 +172,16 @@ test('ensure container gets stopped', async (): Promise => { await compose.down({ cwd: path.join(__dirname), log: logOutput }); }); +test('ensure only single container gets stopped', async (): Promise => { + await compose.upAll({ cwd: path.join(__dirname), log: logOutput }); + expect(await isContainerRunning('/compose_test_alpine')).toBeTruthy(); + + await compose.stopOne('alpine', { cwd: path.join(__dirname), log: logOutput }); + expect(await isContainerRunning('/compose_test_alpine')).toBeFalsy(); + expect(await isContainerRunning('/compose_test_nginx')).toBeTruthy(); + await compose.down({ cwd: path.join(__dirname), log: logOutput }); +}); + test('ensure container gets killed', async (): Promise => { await compose.upAll({ cwd: path.join(__dirname), log: logOutput }); expect(await isContainerRunning('/compose_test_nginx')).toBeTruthy();