testcontainers 9.6.0 → 9.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/package.json +12 -12
  2. package/dist/src/docker/docker-client-config.js +42 -36
  3. package/dist/src/docker/docker-client.js +3 -3
  4. package/dist/src/docker/functions/container/attach-container.js +1 -1
  5. package/dist/src/docker/functions/container/create-container.js +6 -4
  6. package/dist/src/docker/functions/container/exec-container.js +7 -5
  7. package/dist/src/docker/functions/container/get-container.js +1 -1
  8. package/dist/src/docker/functions/container/inspect-container.js +1 -1
  9. package/dist/src/docker/functions/container/put-container-archive.js +1 -1
  10. package/dist/src/docker/functions/container/remove-container.js +1 -1
  11. package/dist/src/docker/functions/container/restart-container.js +1 -1
  12. package/dist/src/docker/functions/container/start-container.js +1 -1
  13. package/dist/src/docker/functions/container/stop-container.js +2 -2
  14. package/dist/src/docker/functions/create-labels.js +0 -3
  15. package/dist/src/docker/functions/image/build-image.js +8 -3
  16. package/dist/src/docker/functions/image/pull-image.js +3 -3
  17. package/dist/src/docker/functions/network/connect-network.js +3 -2
  18. package/dist/src/docker/functions/network/create-network.js +2 -1
  19. package/dist/src/docker/functions/network/remove-network.js +3 -2
  20. package/dist/src/docker/functions/run-in-container.js +6 -6
  21. package/dist/src/docker/pull-stream-parser.js +5 -1
  22. package/dist/src/docker/resolve-host.js +2 -2
  23. package/dist/src/docker-compose/default-docker-compose-options.js +4 -2
  24. package/dist/src/docker-compose/docker-compose-options.d.ts +2 -0
  25. package/dist/src/docker-compose/functions/docker-compose-down.js +1 -1
  26. package/dist/src/docker-compose/functions/docker-compose-pull.js +4 -4
  27. package/dist/src/docker-compose/functions/docker-compose-stop.js +1 -1
  28. package/dist/src/docker-compose/functions/docker-compose-up.js +1 -1
  29. package/dist/src/docker-compose-environment/docker-compose-environment.js +3 -6
  30. package/dist/src/generic-container/generic-container-builder.js +1 -1
  31. package/dist/src/generic-container/generic-container.d.ts +4 -0
  32. package/dist/src/generic-container/generic-container.js +18 -7
  33. package/dist/src/generic-container/started-generic-container.js +10 -5
  34. package/dist/src/images.js +1 -1
  35. package/dist/src/logger.d.ts +20 -31
  36. package/dist/src/logger.js +32 -42
  37. package/dist/src/modules/nats/nats-container.js +1 -1
  38. package/dist/src/network.js +6 -3
  39. package/dist/src/port-check.js +6 -2
  40. package/dist/src/port-forwarder.js +5 -3
  41. package/dist/src/reaper.js +11 -7
  42. package/dist/src/registry-auth-locator/credential-provider.js +3 -5
  43. package/dist/src/registry-auth-locator/get-auth-config.js +3 -3
  44. package/dist/src/system-info.js +2 -5
  45. package/dist/src/test-container.d.ts +1 -0
  46. package/dist/src/uuid.js +1 -1
  47. package/dist/src/wait-for-container.js +4 -4
  48. package/dist/src/wait-strategy/composite-wait-strategy.js +4 -4
  49. package/dist/src/wait-strategy/health-check-wait-strategy.js +8 -5
  50. package/dist/src/wait-strategy/host-port-wait-strategy.js +8 -8
  51. package/dist/src/wait-strategy/http-wait-strategy.js +7 -5
  52. package/dist/src/wait-strategy/log-wait-strategy.js +7 -7
  53. package/dist/src/wait-strategy/shell-wait-strategy.js +5 -5
  54. package/dist/src/wait-strategy/startup-check-strategy.js +6 -3
  55. package/dist/src/wait-strategy/wait-strategy.d.ts +6 -4
  56. package/dist/src/wait-strategy/wait-strategy.js +9 -2
  57. package/package.json +12 -12
@@ -30,28 +30,28 @@ class HostPortWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
30
30
  waitForHostPorts(portCheck, container, boundPorts) {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
32
  for (const [, hostPort] of boundPorts.iterator()) {
33
- logger_1.log.debug(`Waiting for host port ${hostPort} for ${container.id}`);
33
+ logger_1.log.debug(`Waiting for host port ${hostPort}...`, { containerId: container.id });
34
34
  yield this.waitForPort(container, hostPort, portCheck);
35
- logger_1.log.debug(`Host port ${hostPort} ready for ${container.id}`);
35
+ logger_1.log.debug(`Host port ${hostPort} ready`, { containerId: container.id });
36
36
  }
37
37
  });
38
38
  }
39
39
  waitForInternalPorts(portCheck, container, boundPorts) {
40
40
  return __awaiter(this, void 0, void 0, function* () {
41
41
  for (const [internalPort] of boundPorts.iterator()) {
42
- logger_1.log.debug(`Waiting for internal port ${internalPort} for ${container.id}`);
42
+ logger_1.log.debug(`Waiting for internal port ${internalPort}...`, { containerId: container.id });
43
43
  yield this.waitForPort(container, internalPort, portCheck);
44
- logger_1.log.debug(`Internal port ${internalPort} ready for ${container.id}`);
44
+ logger_1.log.debug(`Internal port ${internalPort} ready`, { containerId: container.id });
45
45
  }
46
46
  });
47
47
  }
48
48
  waitForPort(container, port, portCheck) {
49
- var _a;
50
49
  return __awaiter(this, void 0, void 0, function* () {
51
- const startupTimeout = (_a = this.startupTimeout) !== null && _a !== void 0 ? _a : wait_strategy_1.DEFAULT_STARTUP_TIMEOUT;
52
50
  yield new retry_strategy_1.IntervalRetryStrategy(100).retryUntil(() => portCheck.isBound(port), (isBound) => isBound, () => {
53
- throw new Error(`Port ${port} not bound after ${startupTimeout}ms for ${container.id}`);
54
- }, startupTimeout);
51
+ const message = `Port ${port} not bound after ${this.startupTimeout}ms`;
52
+ logger_1.log.error(message, { containerId: container.id });
53
+ throw new Error(message);
54
+ }, this.startupTimeout);
55
55
  });
56
56
  }
57
57
  }
@@ -18,6 +18,7 @@ const retry_strategy_1 = require("../retry-strategy");
18
18
  const node_fetch_1 = __importDefault(require("node-fetch"));
19
19
  const https_1 = __importDefault(require("https"));
20
20
  const docker_client_1 = require("../docker/docker-client");
21
+ const logger_1 = require("../logger");
21
22
  class HttpWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
22
23
  constructor(path, port) {
23
24
  super();
@@ -68,10 +69,9 @@ class HttpWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
68
69
  return this;
69
70
  }
70
71
  waitUntilReady(container, boundPorts) {
71
- var _a;
72
72
  return __awaiter(this, void 0, void 0, function* () {
73
+ logger_1.log.debug(`Waiting for HTTP...`, { containerId: container.id });
73
74
  const { host } = yield (0, docker_client_1.dockerClient)();
74
- const startupTimeout = (_a = this.startupTimeout) !== null && _a !== void 0 ? _a : wait_strategy_1.DEFAULT_STARTUP_TIMEOUT;
75
75
  yield new retry_strategy_1.IntervalRetryStrategy(this.readTimeout).retryUntil(() => __awaiter(this, void 0, void 0, function* () {
76
76
  try {
77
77
  const url = `${this.protocol}://${host}:${boundPorts.getBinding(this.port)}${this.path}`;
@@ -82,7 +82,7 @@ class HttpWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
82
82
  agent: this.getAgent(),
83
83
  });
84
84
  }
85
- catch (_b) {
85
+ catch (_a) {
86
86
  return undefined;
87
87
  }
88
88
  }), (response) => __awaiter(this, void 0, void 0, function* () {
@@ -102,8 +102,10 @@ class HttpWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
102
102
  return true;
103
103
  }
104
104
  }), () => {
105
- throw new Error(`URL ${this.path} not accessible after ${startupTimeout}ms for ${container.id}`);
106
- }, startupTimeout);
105
+ const message = `URL ${this.path} not accessible after ${this.startupTimeout}ms`;
106
+ logger_1.log.error(message, { containerId: container.id });
107
+ throw new Error(message);
108
+ }, this.startupTimeout);
107
109
  });
108
110
  }
109
111
  getAgent() {
@@ -24,17 +24,15 @@ class LogWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
24
24
  this.times = times;
25
25
  }
26
26
  waitUntilReady(container, boundPorts, startTime) {
27
- var _a;
28
27
  return __awaiter(this, void 0, void 0, function* () {
29
- logger_1.log.debug(`Waiting for log message "${this.message}" for ${container.id}`);
30
- const startupTimeout = (_a = this.startupTimeout) !== null && _a !== void 0 ? _a : wait_strategy_1.DEFAULT_STARTUP_TIMEOUT;
28
+ logger_1.log.debug(`Waiting for log message "${this.message}"...`, { containerId: container.id });
31
29
  const stream = yield (0, container_logs_1.containerLogs)(container, { since: startTime });
32
30
  return new Promise((resolve, reject) => {
33
31
  const timeout = setTimeout(() => {
34
- const message = `Log message "${this.message}" not received after ${startupTimeout}ms for ${container.id}`;
35
- logger_1.log.error(message);
32
+ const message = `Log message "${this.message}" not received after ${this.startupTimeout}ms`;
33
+ logger_1.log.error(message, { containerId: container.id });
36
34
  reject(new Error(message));
37
- }, startupTimeout);
35
+ }, this.startupTimeout);
38
36
  const comparisonFn = (line) => {
39
37
  if (this.message instanceof RegExp) {
40
38
  return this.message.test(line);
@@ -59,7 +57,9 @@ class LogWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
59
57
  .on("end", () => {
60
58
  stream.destroy();
61
59
  clearTimeout(timeout);
62
- reject(new Error(`Log stream ended and message "${this.message}" was not received for ${container.id}`));
60
+ const message = `Log stream ended and message "${this.message}" was not received`;
61
+ logger_1.log.error(message, { containerId: container.id });
62
+ reject(new Error(message));
63
63
  });
64
64
  });
65
65
  });
@@ -21,17 +21,17 @@ class ShellWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
21
21
  this.command = command;
22
22
  }
23
23
  waitUntilReady(container) {
24
- var _a;
25
24
  return __awaiter(this, void 0, void 0, function* () {
26
- logger_1.log.debug(`Waiting for successful shell command ${this.command} for ${container.id}`);
25
+ logger_1.log.debug(`Waiting for successful shell command "${this.command}"...`, { containerId: container.id });
27
26
  const { dockerode, provider } = yield (0, docker_client_1.dockerClient)();
28
- const startupTimeout = (_a = this.startupTimeout) !== null && _a !== void 0 ? _a : wait_strategy_1.DEFAULT_STARTUP_TIMEOUT;
29
27
  yield new retry_strategy_1.IntervalRetryStrategy(100).retryUntil(() => __awaiter(this, void 0, void 0, function* () {
30
28
  const { exitCode } = yield (0, exec_container_1.execContainer)(dockerode, provider, container, ["/bin/sh", "-c", this.command], false);
31
29
  return exitCode;
32
30
  }), (exitCode) => exitCode === 0, () => {
33
- throw new Error(`Shell command "${this.command}" not successful after ${startupTimeout}ms for ${container.id}`);
34
- }, startupTimeout);
31
+ const message = `Shell command "${this.command}" not successful after ${this.startupTimeout}ms`;
32
+ logger_1.log.error(message, { containerId: container.id });
33
+ throw new Error(message);
34
+ }, this.startupTimeout);
35
35
  });
36
36
  }
37
37
  }
@@ -13,13 +13,16 @@ exports.StartupCheckStrategy = void 0;
13
13
  const wait_strategy_1 = require("./wait-strategy");
14
14
  const retry_strategy_1 = require("../retry-strategy");
15
15
  const docker_client_1 = require("../docker/docker-client");
16
+ const logger_1 = require("../logger");
16
17
  class StartupCheckStrategy extends wait_strategy_1.AbstractWaitStrategy {
17
18
  waitUntilReady(container) {
18
- var _a;
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
20
  const { dockerode } = yield (0, docker_client_1.dockerClient)();
21
- const startupTimeout = (_a = this.startupTimeout) !== null && _a !== void 0 ? _a : wait_strategy_1.DEFAULT_STARTUP_TIMEOUT;
22
- const startupStatus = yield new retry_strategy_1.IntervalRetryStrategy(1000).retryUntil(() => __awaiter(this, void 0, void 0, function* () { return yield this.checkStartupState(dockerode, container.id); }), (startupStatus) => startupStatus === "SUCCESS" || startupStatus === "FAIL", () => new Error(`Container not accessible after ${startupTimeout}ms for ${container.id}`), startupTimeout);
21
+ const startupStatus = yield new retry_strategy_1.IntervalRetryStrategy(1000).retryUntil(() => __awaiter(this, void 0, void 0, function* () { return yield this.checkStartupState(dockerode, container.id); }), (startupStatus) => startupStatus === "SUCCESS" || startupStatus === "FAIL", () => {
22
+ const message = `Container not accessible after ${this.startupTimeout}ms`;
23
+ logger_1.log.error(message, { containerId: container.id });
24
+ return new Error(message);
25
+ }, this.startupTimeout);
23
26
  if (startupStatus instanceof Error) {
24
27
  throw startupStatus;
25
28
  }
@@ -1,14 +1,16 @@
1
1
  import { BoundPorts } from "../bound-ports";
2
2
  import Dockerode from "dockerode";
3
- export declare const DEFAULT_STARTUP_TIMEOUT = 60000;
4
3
  export interface WaitStrategy {
5
4
  waitUntilReady(container: Dockerode.Container, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
6
5
  withStartupTimeout(startupTimeout: number): WaitStrategy;
7
- getStartupTimeout(): number | undefined;
6
+ isStartupTimeoutSet(): boolean;
7
+ getStartupTimeout(): number;
8
8
  }
9
9
  export declare abstract class AbstractWaitStrategy implements WaitStrategy {
10
- protected startupTimeout?: number;
10
+ protected startupTimeout: number;
11
+ private startupTimeoutSet;
11
12
  abstract waitUntilReady(container: Dockerode.Container, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
12
13
  withStartupTimeout(startupTimeout: number): this;
13
- getStartupTimeout(): number | undefined;
14
+ isStartupTimeoutSet(): boolean;
15
+ getStartupTimeout(): number;
14
16
  }
@@ -1,12 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractWaitStrategy = exports.DEFAULT_STARTUP_TIMEOUT = void 0;
4
- exports.DEFAULT_STARTUP_TIMEOUT = 60000;
3
+ exports.AbstractWaitStrategy = void 0;
5
4
  class AbstractWaitStrategy {
5
+ constructor() {
6
+ this.startupTimeout = 60000;
7
+ this.startupTimeoutSet = false;
8
+ }
6
9
  withStartupTimeout(startupTimeout) {
7
10
  this.startupTimeout = startupTimeout;
11
+ this.startupTimeoutSet = true;
8
12
  return this;
9
13
  }
14
+ isStartupTimeoutSet() {
15
+ return this.startupTimeoutSet;
16
+ }
10
17
  getStartupTimeout() {
11
18
  return this.startupTimeout;
12
19
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "testcontainers",
3
3
  "author": "Cristian Greco",
4
- "version": "9.6.0",
4
+ "version": "9.7.0",
5
5
  "main": "dist/src/index",
6
6
  "types": "dist/src/index",
7
7
  "keywords": [
@@ -56,31 +56,31 @@
56
56
  "@types/async-lock": "^1.4.0",
57
57
  "@types/byline": "^4.2.33",
58
58
  "@types/debug": "4.1.7",
59
- "@types/jest": "^29.5.0",
60
- "@types/node": "^18.15.11",
59
+ "@types/jest": "^29.5.1",
60
+ "@types/node": "^18.16.2",
61
61
  "@types/node-fetch": "^2.6.3",
62
62
  "@types/pg": "^8.6.6",
63
63
  "@types/properties-reader": "^2.1.1",
64
64
  "@types/tar-fs": "^2.0.1",
65
- "@typescript-eslint/eslint-plugin": "^5.57.0",
66
- "@typescript-eslint/parser": "^5.57.0",
67
- "arangojs": "^8.2.0",
65
+ "@typescript-eslint/eslint-plugin": "^5.59.1",
66
+ "@typescript-eslint/parser": "^5.59.1",
67
+ "arangojs": "^8.2.1",
68
68
  "cross-env": "^7.0.3",
69
- "eslint": "^8.37.0",
69
+ "eslint": "^8.39.0",
70
70
  "eslint-config-prettier": "^8.8.0",
71
71
  "eslint-plugin-prettier": "^4.2.1",
72
72
  "husky": "^8.0.3",
73
73
  "jest": "^29.5.0",
74
74
  "kafkajs": "^2.2.4",
75
- "lint-staged": "^13.2.0",
76
- "mongoose": "^6.10.4",
75
+ "lint-staged": "^13.2.2",
76
+ "mongoose": "^6.10.5",
77
77
  "mysql2": "^2.3.3",
78
78
  "nats": "^2.13.1",
79
- "neo4j-driver": "^5.6.0",
79
+ "neo4j-driver": "^5.7.0",
80
80
  "pg": "^8.10.0",
81
- "prettier": "^2.8.7",
81
+ "prettier": "^2.8.8",
82
82
  "rimraf": "^3.0.2",
83
- "ts-jest": "^29.0.5",
83
+ "ts-jest": "^29.1.0",
84
84
  "ts-node": "^10.9.1",
85
85
  "typescript": "^4.9.5",
86
86
  "wait-for-expect": "^3.0.2"