|
1 | | -import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest' |
| 1 | +import { describe, it, expect, beforeEach, afterEach, vi, beforeAll } from 'vitest' |
2 | 2 | import Docker, { ContainerInfo } from 'dockerode' |
3 | 3 | import * as compose from '../../src/v2' |
4 | 4 | import * as path from 'path' |
@@ -1101,3 +1101,80 @@ describe('passed callback fn', (): void => { |
1101 | 1101 | await compose.downAll(config) |
1102 | 1102 | }) |
1103 | 1103 | }) |
| 1104 | + |
| 1105 | +describe('when upAll is called', () => { |
| 1106 | + // relying on bash echo to know when a container is up and has its stdout forwarded to this process (aka, not --detach) |
| 1107 | + const ECHO_MSG = 'hello from a container tst msg' |
| 1108 | + const options2test = [ |
| 1109 | + ['--attach', 'echo', true], |
| 1110 | + ['--exit-code-from', 'echo', true], |
| 1111 | + ['--abort-on-container-exit', 'echo', true], |
| 1112 | + ['--wait', 'echo', false] |
| 1113 | + ] |
| 1114 | + |
| 1115 | + beforeAll(async () => { |
| 1116 | + await compose.downAll({ |
| 1117 | + cwd: path.join(__dirname), |
| 1118 | + log: logOutput, |
| 1119 | + config: 'docker-compose-echo.yml' |
| 1120 | + }) |
| 1121 | + }) |
| 1122 | + |
| 1123 | + afterEach(async () => { |
| 1124 | + await compose.kill({ |
| 1125 | + cwd: path.join(__dirname), |
| 1126 | + log: logOutput, |
| 1127 | + config: 'docker-compose-echo.yml' |
| 1128 | + }) |
| 1129 | + }) |
| 1130 | + |
| 1131 | + options2test.forEach((optPair) => { |
| 1132 | + it(`with ${optPair[0]}, a container gets started ${ |
| 1133 | + optPair[2] ? 'not' : '' |
| 1134 | + } in the detached mode`, () => { |
| 1135 | + return new Promise((resolve, reject) => { |
| 1136 | + let doneFlag = false |
| 1137 | + compose |
| 1138 | + .upAll({ |
| 1139 | + cwd: path.join(__dirname), |
| 1140 | + log: logOutput, |
| 1141 | + config: 'docker-compose-echo.yml', |
| 1142 | + commandOptions: [[optPair[0], optPair[1]]], |
| 1143 | + callback: (chunk, streamType) => { |
| 1144 | + if ( |
| 1145 | + streamType === 'stdout' && |
| 1146 | + !doneFlag && |
| 1147 | + chunk.toString().includes('|') // else these are set-up messages, not echos from a container |
| 1148 | + ) { |
| 1149 | + doneFlag = true |
| 1150 | + expect(chunk.toString().includes(ECHO_MSG)).toBe(optPair[2]) |
| 1151 | + optPair[2] |
| 1152 | + ? resolve('all ok') |
| 1153 | + : reject( |
| 1154 | + `Container was run ${ |
| 1155 | + optPair[2] ? '' : 'not' |
| 1156 | + } in the detached mode.` |
| 1157 | + ) |
| 1158 | + } |
| 1159 | + } |
| 1160 | + }) |
| 1161 | + .then(() => { |
| 1162 | + optPair[2] |
| 1163 | + ? reject( |
| 1164 | + `Container was run ${ |
| 1165 | + optPair[2] ? 'not' : '' |
| 1166 | + } in the detached mode.` |
| 1167 | + ) |
| 1168 | + : resolve('all ok') |
| 1169 | + }) |
| 1170 | + .catch((e) => { |
| 1171 | + if (e.exitCode === 137) { |
| 1172 | + // swallowing this reject -- so it doesn't complain about being SIGKILLed |
| 1173 | + return |
| 1174 | + } |
| 1175 | + throw e // else re-throwing |
| 1176 | + }) |
| 1177 | + }) |
| 1178 | + }) |
| 1179 | + }) |
| 1180 | +}) |
0 commit comments