testcontainers 9.5.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 (78) hide show
  1. package/dist/package.json +14 -14
  2. package/dist/src/docker/docker-client-config.js +42 -36
  3. package/dist/src/docker/docker-client.d.ts +2 -0
  4. package/dist/src/docker/docker-client.js +6 -5
  5. package/dist/src/docker/functions/container/attach-container.js +1 -1
  6. package/dist/src/docker/functions/container/create-container.js +6 -4
  7. package/dist/src/docker/functions/container/exec-container.d.ts +2 -1
  8. package/dist/src/docker/functions/container/exec-container.js +15 -8
  9. package/dist/src/docker/functions/container/get-container.js +1 -1
  10. package/dist/src/docker/functions/container/inspect-container.js +1 -1
  11. package/dist/src/docker/functions/container/put-container-archive.js +5 -2
  12. package/dist/src/docker/functions/container/remove-container.js +1 -1
  13. package/dist/src/docker/functions/container/restart-container.js +1 -1
  14. package/dist/src/docker/functions/container/start-container.js +1 -1
  15. package/dist/src/docker/functions/container/stop-container.js +2 -2
  16. package/dist/src/docker/functions/create-labels.js +0 -3
  17. package/dist/src/docker/functions/image/build-image.js +8 -3
  18. package/dist/src/docker/functions/image/image-exists.js +11 -8
  19. package/dist/src/docker/functions/image/pull-image.js +3 -3
  20. package/dist/src/docker/functions/network/connect-network.js +3 -2
  21. package/dist/src/docker/functions/network/create-network.js +2 -1
  22. package/dist/src/docker/functions/network/remove-network.js +3 -2
  23. package/dist/src/docker/functions/run-in-container.js +6 -6
  24. package/dist/src/docker/pull-stream-parser.d.ts +0 -1
  25. package/dist/src/docker/pull-stream-parser.js +2 -41
  26. package/dist/src/docker/resolve-host.d.ts +2 -1
  27. package/dist/src/docker/resolve-host.js +7 -6
  28. package/dist/src/docker-compose/default-docker-compose-options.js +4 -2
  29. package/dist/src/docker-compose/docker-compose-options.d.ts +2 -0
  30. package/dist/src/docker-compose/functions/docker-compose-down.js +1 -1
  31. package/dist/src/docker-compose/functions/docker-compose-pull.js +4 -4
  32. package/dist/src/docker-compose/functions/docker-compose-stop.js +1 -1
  33. package/dist/src/docker-compose/functions/docker-compose-up.js +1 -1
  34. package/dist/src/docker-compose-environment/docker-compose-environment.d.ts +1 -1
  35. package/dist/src/docker-compose-environment/docker-compose-environment.js +11 -10
  36. package/dist/src/generic-container/generic-container-builder.js +1 -1
  37. package/dist/src/generic-container/generic-container.d.ts +6 -2
  38. package/dist/src/generic-container/generic-container.js +30 -17
  39. package/dist/src/generic-container/started-generic-container.d.ts +2 -0
  40. package/dist/src/generic-container/started-generic-container.js +26 -7
  41. package/dist/src/images.js +1 -1
  42. package/dist/src/logger.d.ts +20 -31
  43. package/dist/src/logger.js +32 -42
  44. package/dist/src/modules/elasticsearch/elasticsearch-container.js +1 -1
  45. package/dist/src/modules/nats/nats-container.js +1 -1
  46. package/dist/src/network.d.ts +1 -0
  47. package/dist/src/network.js +11 -5
  48. package/dist/src/port-check.d.ts +4 -1
  49. package/dist/src/port-check.js +10 -4
  50. package/dist/src/port-forwarder.js +5 -3
  51. package/dist/src/reaper.js +11 -7
  52. package/dist/src/registry-auth-locator/credential-provider.js +3 -5
  53. package/dist/src/registry-auth-locator/get-auth-config.js +3 -3
  54. package/dist/src/system-info.js +2 -5
  55. package/dist/src/test-container.d.ts +2 -6
  56. package/dist/src/uuid.js +1 -1
  57. package/dist/src/wait-for-container.d.ts +1 -1
  58. package/dist/src/wait-for-container.js +6 -6
  59. package/dist/src/wait-strategy/composite-wait-strategy.d.ts +11 -0
  60. package/dist/src/wait-strategy/composite-wait-strategy.js +54 -0
  61. package/dist/src/wait-strategy/health-check-wait-strategy.js +7 -3
  62. package/dist/src/wait-strategy/host-port-wait-strategy.d.ts +1 -5
  63. package/dist/src/wait-strategy/host-port-wait-strategy.js +21 -17
  64. package/dist/src/wait-strategy/http-wait-strategy.d.ts +1 -1
  65. package/dist/src/wait-strategy/http-wait-strategy.js +8 -2
  66. package/dist/src/wait-strategy/log-wait-strategy.d.ts +1 -1
  67. package/dist/src/wait-strategy/log-wait-strategy.js +8 -7
  68. package/dist/src/wait-strategy/shell-wait-strategy.js +7 -4
  69. package/dist/src/wait-strategy/startup-check-strategy.js +6 -1
  70. package/dist/src/wait-strategy/wait-strategy.d.ts +8 -3
  71. package/dist/src/wait-strategy/wait-strategy.js +8 -0
  72. package/dist/src/wait-strategy/wait.d.ts +3 -0
  73. package/dist/src/wait-strategy/wait.js +8 -0
  74. package/package.json +14 -14
  75. package/dist/src/docker/functions/image/list-images.d.ts +0 -3
  76. package/dist/src/docker/functions/image/list-images.js +0 -34
  77. package/dist/src/wait-strategy/default-wait-strategy.d.ts +0 -3
  78. package/dist/src/wait-strategy/default-wait-strategy.js +0 -7
@@ -14,6 +14,7 @@ const logger_1 = require("../logger");
14
14
  const wait_strategy_1 = require("./wait-strategy");
15
15
  const retry_strategy_1 = require("../retry-strategy");
16
16
  const exec_container_1 = require("../docker/functions/container/exec-container");
17
+ const docker_client_1 = require("../docker/docker-client");
17
18
  class ShellWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
18
19
  constructor(command) {
19
20
  super();
@@ -21,13 +22,15 @@ class ShellWaitStrategy extends wait_strategy_1.AbstractWaitStrategy {
21
22
  }
22
23
  waitUntilReady(container) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
- 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 });
26
+ const { dockerode, provider } = yield (0, docker_client_1.dockerClient)();
25
27
  yield new retry_strategy_1.IntervalRetryStrategy(100).retryUntil(() => __awaiter(this, void 0, void 0, function* () {
26
- const { exitCode } = yield (0, exec_container_1.execContainer)(container, ["/bin/sh", "-c", this.command], false);
28
+ const { exitCode } = yield (0, exec_container_1.execContainer)(dockerode, provider, container, ["/bin/sh", "-c", this.command], false);
27
29
  return exitCode;
28
30
  }), (exitCode) => exitCode === 0, () => {
29
- const timeout = this.startupTimeout;
30
- throw new Error(`Shell command not successful after ${timeout}ms for ${container.id}`);
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);
31
34
  }, this.startupTimeout);
32
35
  });
33
36
  }
@@ -13,11 +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
19
  return __awaiter(this, void 0, void 0, function* () {
19
20
  const { dockerode } = yield (0, docker_client_1.dockerClient)();
20
- 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 ${this.startupTimeout}ms for ${container.id}`), this.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);
21
26
  if (startupStatus instanceof Error) {
22
27
  throw startupStatus;
23
28
  }
@@ -1,11 +1,16 @@
1
1
  import { BoundPorts } from "../bound-ports";
2
2
  import Dockerode from "dockerode";
3
3
  export interface WaitStrategy {
4
- waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
4
+ waitUntilReady(container: Dockerode.Container, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
5
5
  withStartupTimeout(startupTimeout: number): WaitStrategy;
6
+ isStartupTimeoutSet(): boolean;
7
+ getStartupTimeout(): number;
6
8
  }
7
9
  export declare abstract class AbstractWaitStrategy implements WaitStrategy {
8
10
  protected startupTimeout: number;
9
- abstract waitUntilReady(container: Dockerode.Container, host: string, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
10
- withStartupTimeout(startupTimeout: number): WaitStrategy;
11
+ private startupTimeoutSet;
12
+ abstract waitUntilReady(container: Dockerode.Container, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
13
+ withStartupTimeout(startupTimeout: number): this;
14
+ isStartupTimeoutSet(): boolean;
15
+ getStartupTimeout(): number;
11
16
  }
@@ -4,10 +4,18 @@ exports.AbstractWaitStrategy = void 0;
4
4
  class AbstractWaitStrategy {
5
5
  constructor() {
6
6
  this.startupTimeout = 60000;
7
+ this.startupTimeoutSet = false;
7
8
  }
8
9
  withStartupTimeout(startupTimeout) {
9
10
  this.startupTimeout = startupTimeout;
11
+ this.startupTimeoutSet = true;
10
12
  return this;
11
13
  }
14
+ isStartupTimeoutSet() {
15
+ return this.startupTimeoutSet;
16
+ }
17
+ getStartupTimeout() {
18
+ return this.startupTimeout;
19
+ }
12
20
  }
13
21
  exports.AbstractWaitStrategy = AbstractWaitStrategy;
@@ -2,7 +2,10 @@ import { WaitStrategy } from "./wait-strategy";
2
2
  import { HttpWaitStrategy } from "./http-wait-strategy";
3
3
  import { Log } from "./log-wait-strategy";
4
4
  import { ShellWaitStrategy } from "./shell-wait-strategy";
5
+ import { CompositeWaitStrategy } from "./composite-wait-strategy";
5
6
  export declare class Wait {
7
+ static forAll(waitStrategies: WaitStrategy[]): CompositeWaitStrategy;
8
+ static forListeningPorts(): WaitStrategy;
6
9
  static forLogMessage(message: Log | RegExp, times?: number): WaitStrategy;
7
10
  static forHealthCheck(): WaitStrategy;
8
11
  static forHttp(path: string, port: number): HttpWaitStrategy;
@@ -5,7 +5,15 @@ const http_wait_strategy_1 = require("./http-wait-strategy");
5
5
  const health_check_wait_strategy_1 = require("./health-check-wait-strategy");
6
6
  const log_wait_strategy_1 = require("./log-wait-strategy");
7
7
  const shell_wait_strategy_1 = require("./shell-wait-strategy");
8
+ const host_port_wait_strategy_1 = require("./host-port-wait-strategy");
9
+ const composite_wait_strategy_1 = require("./composite-wait-strategy");
8
10
  class Wait {
11
+ static forAll(waitStrategies) {
12
+ return new composite_wait_strategy_1.CompositeWaitStrategy(waitStrategies);
13
+ }
14
+ static forListeningPorts() {
15
+ return new host_port_wait_strategy_1.HostPortWaitStrategy();
16
+ }
9
17
  static forLogMessage(message, times = 1) {
10
18
  return new log_wait_strategy_1.LogWaitStrategy(message, times);
11
19
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "testcontainers",
3
3
  "author": "Cristian Greco",
4
- "version": "9.5.0",
4
+ "version": "9.7.0",
5
5
  "main": "dist/src/index",
6
6
  "types": "dist/src/index",
7
7
  "keywords": [
@@ -27,8 +27,8 @@
27
27
  "build": "npm run clean && tsc -p tsconfig.prod.json",
28
28
  "docs:serve": "docker-compose up",
29
29
  "clean": "rimraf dist",
30
- "test": "cross-env DEBUG=testcontainers,testcontainers:exec,testcontainers:containers jest",
31
- "test:ci": "cross-env DEBUG=testcontainers,testcontainers:exec,testcontainers:containers jest --runInBand --coverage",
30
+ "test": "cross-env DEBUG=testcontainers* jest",
31
+ "test:ci": "npm run test -- --runInBand --coverage",
32
32
  "format": "prettier --write package.json \"src/**/*.ts\"",
33
33
  "lint": "eslint --fix package.json \"src/**/*.ts\"",
34
34
  "lint:ci": "eslint package.json \"src/**/*.ts\" --max-warnings=0",
@@ -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"
@@ -1,3 +0,0 @@
1
- import { DockerImageName } from "../../../docker-image-name";
2
- import Dockerode from "dockerode";
3
- export declare const listImages: (dockerode: Dockerode) => Promise<DockerImageName[]>;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.listImages = void 0;
13
- const docker_image_name_1 = require("../../../docker-image-name");
14
- const logger_1 = require("../../../logger");
15
- const listImages = (dockerode) => __awaiter(void 0, void 0, void 0, function* () {
16
- try {
17
- const images = yield dockerode.listImages();
18
- return images.reduce((dockerImageNames, image) => {
19
- var _a;
20
- if (isDanglingImage(image)) {
21
- return dockerImageNames;
22
- }
23
- const repoTags = (_a = image.RepoTags) !== null && _a !== void 0 ? _a : [];
24
- const dockerImageNamesForImage = repoTags.map((imageRepoTag) => docker_image_name_1.DockerImageName.fromString(imageRepoTag));
25
- return [...dockerImageNames, ...dockerImageNamesForImage];
26
- }, []);
27
- }
28
- catch (err) {
29
- logger_1.log.error(`Failed to list images: ${err}`);
30
- throw err;
31
- }
32
- });
33
- exports.listImages = listImages;
34
- const isDanglingImage = (image) => image.RepoTags === null;
@@ -1,3 +0,0 @@
1
- import Dockerode from "dockerode";
2
- import { HostPortWaitStrategy } from "./host-port-wait-strategy";
3
- export declare const defaultWaitStrategy: (host: string, container: Dockerode.Container) => HostPortWaitStrategy;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultWaitStrategy = void 0;
4
- const host_port_wait_strategy_1 = require("./host-port-wait-strategy");
5
- const port_check_1 = require("../port-check");
6
- const defaultWaitStrategy = (host, container) => new host_port_wait_strategy_1.HostPortWaitStrategy(new port_check_1.HostPortCheck(host), new port_check_1.InternalPortCheck(container));
7
- exports.defaultWaitStrategy = defaultWaitStrategy;