testcontainers 8.16.0 → 9.0.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 (47) hide show
  1. package/README.md +115 -78
  2. package/dist/bound-ports.d.ts +4 -4
  3. package/dist/docker/docker-client.d.ts +1 -2
  4. package/dist/docker/functions/container/container-logs.js +1 -6
  5. package/dist/docker/functions/container/create-container.d.ts +5 -5
  6. package/dist/docker/functions/container/create-container.js +5 -6
  7. package/dist/docker/functions/container/exec-container.d.ts +2 -2
  8. package/dist/docker/functions/container/get-container.d.ts +1 -2
  9. package/dist/docker/functions/container/inspect-container.d.ts +2 -2
  10. package/dist/docker/functions/create-labels.d.ts +1 -1
  11. package/dist/docker/functions/image/build-image.d.ts +2 -2
  12. package/dist/docker/functions/run-in-container.d.ts +1 -2
  13. package/dist/docker/types.d.ts +23 -22
  14. package/dist/docker-compose/default-docker-compose-options.d.ts +1 -1
  15. package/dist/docker-compose/default-docker-compose-options.js +2 -2
  16. package/dist/docker-compose/docker-compose-options.d.ts +2 -2
  17. package/dist/docker-compose/functions/docker-compose-up.d.ts +1 -1
  18. package/dist/docker-compose-environment/docker-compose-environment.d.ts +5 -5
  19. package/dist/docker-compose-environment/docker-compose-environment.js +11 -11
  20. package/dist/generic-container/generic-container-builder.d.ts +3 -3
  21. package/dist/generic-container/generic-container-builder.js +2 -2
  22. package/dist/generic-container/generic-container.d.ts +16 -17
  23. package/dist/generic-container/generic-container.js +31 -27
  24. package/dist/generic-container/started-generic-container.d.ts +7 -8
  25. package/dist/modules/abstract-started-container.d.ts +6 -7
  26. package/dist/modules/arangodb/arangodb-container.js +2 -2
  27. package/dist/modules/elasticsearch/elasticsearch-container.js +2 -2
  28. package/dist/modules/kafka/kafka-container.d.ts +4 -5
  29. package/dist/modules/kafka/kafka-container.js +41 -34
  30. package/dist/modules/mongodb/mongodb-container.js +1 -1
  31. package/dist/modules/mysql/mysql-container.d.ts +1 -2
  32. package/dist/modules/mysql/mysql-container.js +7 -5
  33. package/dist/modules/nats/nats-container.d.ts +1 -1
  34. package/dist/modules/nats/nats-container.js +2 -2
  35. package/dist/modules/neo4j/neo4j-container.js +10 -4
  36. package/dist/modules/postgresql/postgresql-container.d.ts +1 -2
  37. package/dist/modules/postgresql/postgresql-container.js +5 -3
  38. package/dist/port-binder.d.ts +1 -2
  39. package/dist/port-check.d.ts +4 -6
  40. package/dist/port-forwarder.d.ts +1 -2
  41. package/dist/port-forwarder.js +2 -2
  42. package/dist/port-generator.d.ts +4 -5
  43. package/dist/port.d.ts +3 -5
  44. package/dist/reaper.js +1 -1
  45. package/dist/test-container.d.ts +16 -14
  46. package/dist/test-containers.d.ts +1 -2
  47. package/package.json +29 -25
@@ -15,7 +15,7 @@ const uuid_1 = require("../../uuid");
15
15
  const abstract_started_container_1 = require("../abstract-started-container");
16
16
  const MYSQL_PORT = 3306;
17
17
  class MySqlContainer extends generic_container_1.GenericContainer {
18
- constructor(image = "mysql:8.0.26") {
18
+ constructor(image = "mysql:8.0.31") {
19
19
  super(image);
20
20
  this.database = "test";
21
21
  this.username = new uuid_1.RandomUuid().nextUuid();
@@ -44,10 +44,12 @@ class MySqlContainer extends generic_container_1.GenericContainer {
44
44
  });
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
46
  this.withExposedPorts(...(this.hasExposedPorts ? this.ports : [MYSQL_PORT]))
47
- .withEnv("MYSQL_DATABASE", this.database)
48
- .withEnv("MYSQL_ROOT_PASSWORD", this.rootPassword)
49
- .withEnv("MYSQL_USER", this.username)
50
- .withEnv("MYSQL_PASSWORD", this.userPassword)
47
+ .withEnvironment({
48
+ MYSQL_DATABASE: this.database,
49
+ MYSQL_ROOT_PASSWORD: this.rootPassword,
50
+ MYSQL_USER: this.username,
51
+ MYSQL_PASSWORD: this.userPassword,
52
+ })
51
53
  .withStartupTimeout(120000);
52
54
  return new StartedMySqlContainer(yield _super.start.call(this), this.database, this.username, this.userPassword, this.rootPassword);
53
55
  });
@@ -4,7 +4,7 @@ import { AbstractStartedContainer } from "../abstract-started-container";
4
4
  export declare class NatsContainer extends GenericContainer {
5
5
  private args;
6
6
  constructor(image?: string);
7
- withUser(user: string): this;
7
+ withUsername(user: string): this;
8
8
  withPass(pass: string): this;
9
9
  withArg(name: string, value: string): this;
10
10
  private static ensureDashInFrontOfArgumentName;
@@ -26,7 +26,7 @@ class NatsContainer extends generic_container_1.GenericContainer {
26
26
  this.args[USER_ARGUMENT_KEY] = new uuid_1.RandomUuid().nextUuid();
27
27
  this.args[PASS_ARGUMENT_KEY] = new uuid_1.RandomUuid().nextUuid();
28
28
  }
29
- withUser(user) {
29
+ withUsername(user) {
30
30
  this.args[USER_ARGUMENT_KEY] = user;
31
31
  return this;
32
32
  }
@@ -64,7 +64,7 @@ class NatsContainer extends generic_container_1.GenericContainer {
64
64
  }
65
65
  return result;
66
66
  }
67
- this.withCmd(buildCmdsFromArgs(this.args))
67
+ this.withCommand(buildCmdsFromArgs(this.args))
68
68
  .withExposedPorts(...(this.hasExposedPorts ? this.ports : [CLIENT_PORT, ROUTING_PORT_FOR_CLUSTERING, HTTP_MANAGEMENT_PORT]))
69
69
  .withWaitStrategy(wait_1.Wait.forLogMessage(new RegExp(".*Server is ready.*")))
70
70
  .withStartupTimeout(120000);
@@ -17,7 +17,7 @@ const BOLT_PORT = 7687;
17
17
  const HTTP_PORT = 7474;
18
18
  const USERNAME = "neo4j";
19
19
  class Neo4jContainer extends __1.GenericContainer {
20
- constructor(image = "neo4j:4.3.2") {
20
+ constructor(image = "neo4j:4.4.12") {
21
21
  super(image);
22
22
  this.password = new uuid_1.RandomUuid().nextUuid();
23
23
  this.apoc = false;
@@ -41,13 +41,19 @@ class Neo4jContainer extends __1.GenericContainer {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
42
  this.withExposedPorts(...(this.hasExposedPorts ? this.ports : [BOLT_PORT, HTTP_PORT]))
43
43
  .withWaitStrategy(__1.Wait.forLogMessage("Started."))
44
- .withEnv("NEO4J_AUTH", `${USERNAME}/${this.password}`)
44
+ .withEnvironment({ NEO4J_AUTH: `${USERNAME}/${this.password}` })
45
45
  .withStartupTimeout(120000);
46
46
  if (this.apoc) {
47
- this.withEnv("NEO4JLABS_PLUGINS", '["apoc"]').withEnv("NEO4J_dbms_security_procedures_unrestricted", "apoc.*");
47
+ this.withEnvironment({
48
+ NEO4JLABS_PLUGINS: '["apoc"]',
49
+ NEO4J_dbms_security_procedures_unrestricted: "apoc.*",
50
+ });
48
51
  }
49
52
  if (this.ttl) {
50
- this.withEnv("NEO4J_apoc_ttl_enabled", "true").withEnv("NEO4J_apoc_ttl_schedule", this.ttl.toString());
53
+ this.withEnvironment({
54
+ NEO4J_apoc_ttl_enabled: "true",
55
+ NEO4J_apoc_ttl_schedule: this.ttl.toString(),
56
+ });
51
57
  }
52
58
  return new StartedNeo4jContainer(yield _super.start.call(this), this.password);
53
59
  });
@@ -1,7 +1,6 @@
1
1
  import { GenericContainer } from "../../generic-container/generic-container";
2
2
  import { StartedTestContainer } from "../../test-container";
3
3
  import { AbstractStartedContainer } from "../abstract-started-container";
4
- import { Port } from "../../port";
5
4
  export declare class PostgreSqlContainer extends GenericContainer {
6
5
  private database;
7
6
  private username;
@@ -18,7 +17,7 @@ export declare class StartedPostgreSqlContainer extends AbstractStartedContainer
18
17
  private readonly password;
19
18
  private readonly port;
20
19
  constructor(startedTestContainer: StartedTestContainer, database: string, username: string, password: string);
21
- getPort(): Port;
20
+ getPort(): number;
22
21
  getDatabase(): string;
23
22
  getUsername(): string;
24
23
  getPassword(): string;
@@ -39,9 +39,11 @@ class PostgreSqlContainer extends generic_container_1.GenericContainer {
39
39
  });
40
40
  return __awaiter(this, void 0, void 0, function* () {
41
41
  this.withExposedPorts(...(this.hasExposedPorts ? this.ports : [POSTGRES_PORT]))
42
- .withEnv("POSTGRES_DB", this.database)
43
- .withEnv("POSTGRES_USER", this.username)
44
- .withEnv("POSTGRES_PASSWORD", this.password)
42
+ .withEnvironment({
43
+ POSTGRES_DB: this.database,
44
+ POSTGRES_USER: this.username,
45
+ POSTGRES_PASSWORD: this.password,
46
+ })
45
47
  .withStartupTimeout(120000);
46
48
  return new StartedPostgreSqlContainer(yield _super.start.call(this), this.database, this.username, this.password);
47
49
  });
@@ -1,8 +1,7 @@
1
1
  import { BoundPorts } from "./bound-ports";
2
- import { Port } from "./port";
3
2
  import { PortGenerator } from "./port-generator";
4
3
  export declare class PortBinder {
5
4
  private readonly portGenerator;
6
5
  constructor(portGenerator?: PortGenerator);
7
- bind(ports: Port[]): Promise<BoundPorts>;
6
+ bind(ports: number[]): Promise<BoundPorts>;
8
7
  }
@@ -1,19 +1,17 @@
1
- import { Port } from "./port";
2
- import { Host } from "./docker/types";
3
1
  import Dockerode from "dockerode";
4
2
  export interface PortCheck {
5
- isBound(port: Port): Promise<boolean>;
3
+ isBound(port: number): Promise<boolean>;
6
4
  }
7
5
  export declare class HostPortCheck implements PortCheck {
8
6
  private readonly host;
9
- constructor(host: Host);
10
- isBound(port: Port): Promise<boolean>;
7
+ constructor(host: string);
8
+ isBound(port: number): Promise<boolean>;
11
9
  }
12
10
  export declare class InternalPortCheck implements PortCheck {
13
11
  private readonly container;
14
12
  private isDistroless;
15
13
  private commandOutputs;
16
14
  constructor(container: Dockerode.Container);
17
- isBound(port: Port): Promise<boolean>;
15
+ isBound(port: number): Promise<boolean>;
18
16
  private commandOutputsKey;
19
17
  }
@@ -1,11 +1,10 @@
1
1
  import { SshConnection } from "ssh-remote-port-forward";
2
- import { Port } from "./port";
3
2
  import { StartedTestContainer } from "./test-container";
4
3
  export declare class PortForwarder {
5
4
  private readonly sshConnection;
6
5
  private readonly container;
7
6
  constructor(sshConnection: SshConnection, container: StartedTestContainer);
8
- exposeHostPort(port: Port): Promise<void>;
7
+ exposeHostPort(port: number): Promise<void>;
9
8
  getNetworkId(): string;
10
9
  getIpAddress(): string;
11
10
  private getNetworkName;
@@ -62,8 +62,8 @@ class PortForwarderInstance {
62
62
  const container = yield new generic_container_1.GenericContainer(images_1.SSHD_IMAGE)
63
63
  .withName(`testcontainers-port-forwarder-${session_id_1.sessionId}`)
64
64
  .withExposedPorts(containerPort)
65
- .withEnv("PASSWORD", password)
66
- .withCmd([
65
+ .withEnvironment({ PASSWORD: password })
66
+ .withCommand([
67
67
  "sh",
68
68
  "-c",
69
69
  `echo "${username}:$PASSWORD" | chpasswd && /usr/sbin/sshd -D -o PermitRootLogin=yes -o AddressFamily=inet -o GatewayPorts=yes`,
@@ -1,16 +1,15 @@
1
- import { Port } from "./port";
2
1
  export interface PortGenerator {
3
- generatePort(): Promise<Port>;
2
+ generatePort(): Promise<number>;
4
3
  }
5
4
  export declare class RandomUniquePortGenerator implements PortGenerator {
6
5
  private readonly portGenerator;
7
6
  private static readonly assignedPorts;
8
7
  constructor(portGenerator?: PortGenerator);
9
- generatePort(): Promise<Port>;
8
+ generatePort(): Promise<number>;
10
9
  }
11
10
  export declare class FixedPortGenerator implements PortGenerator {
12
11
  private readonly ports;
13
12
  private portIndex;
14
- constructor(ports: Port[]);
15
- generatePort(): Promise<Port>;
13
+ constructor(ports: number[]);
14
+ generatePort(): Promise<number>;
16
15
  }
package/dist/port.d.ts CHANGED
@@ -1,9 +1,7 @@
1
- export declare type Port = number;
2
- export declare type PortString = string;
3
1
  export declare type PortWithBinding = {
4
- container: Port;
5
- host: Port;
2
+ container: number;
3
+ host: number;
6
4
  };
7
- export declare type PortWithOptionalBinding = Port | PortWithBinding;
5
+ export declare type PortWithOptionalBinding = number | PortWithBinding;
8
6
  export declare const getContainerPort: (port: PortWithOptionalBinding) => number;
9
7
  export declare const hasHostBinding: (port: PortWithOptionalBinding) => port is PortWithBinding;
package/dist/reaper.js CHANGED
@@ -88,7 +88,7 @@ class ReaperInstance {
88
88
  const container = new generic_container_1.GenericContainer(images_1.REAPER_IMAGE)
89
89
  .withName(`testcontainers-ryuk-${session_id_1.sessionId}`)
90
90
  .withExposedPorts(containerPort)
91
- .withBindMount(dockerSocket, "/var/run/docker.sock")
91
+ .withBindMounts([{ source: dockerSocket, target: "/var/run/docker.sock" }])
92
92
  .withWaitStrategy(wait_1.Wait.forLogMessage(/.+ Started!/));
93
93
  if (this.isPrivileged()) {
94
94
  container.withPrivilegedMode();
@@ -1,31 +1,33 @@
1
1
  /// <reference types="node" />
2
- import { Port, PortWithOptionalBinding } from "./port";
2
+ import { PortWithOptionalBinding } from "./port";
3
3
  import { PullPolicy } from "./pull-policy";
4
4
  import { WaitStrategy } from "./wait-strategy";
5
5
  import { Readable } from "stream";
6
- import { BindMode, Command, ContainerName, Dir, EnvKey, EnvValue, ExecResult, ExtraHost, Host, Id, NetworkMode, TmpFs, Labels, Ulimits } from "./docker/types";
6
+ import { ExecResult, ExtraHost, TmpFs, Labels, Ulimits, BindMount, FileToCopy, ContentToCopy, Environment } from "./docker/types";
7
+ import { StartedNetwork } from "./network";
7
8
  export interface TestContainer {
8
9
  start(): Promise<StartedTestContainer>;
9
- withEnv(key: EnvKey, value: EnvValue): this;
10
- withCmd(cmd: Command[]): this;
10
+ withEnvironment(environment: Environment): this;
11
+ withCommand(command: string[]): this;
11
12
  withEntrypoint(entrypoint: string[]): this;
12
13
  withTmpFs(tmpFs: TmpFs): this;
13
14
  withUlimits(ulimits: Ulimits): this;
14
15
  withAddedCapabilities(...capabilities: string[]): this;
15
16
  withDroppedCapabilities(...capabilities: string[]): this;
16
17
  withExposedPorts(...ports: PortWithOptionalBinding[]): this;
17
- withBindMount(source: Dir, target: Dir, bindMode: BindMode): this;
18
+ withBindMounts(bindMounts: BindMount[]): this;
18
19
  withWaitStrategy(waitStrategy: WaitStrategy): this;
19
20
  withStartupTimeout(startupTimeout: number): this;
20
- withNetworkMode(networkMode: NetworkMode): this;
21
- withExtraHosts(...extraHosts: ExtraHost[]): this;
21
+ withNetwork(network: StartedNetwork): this;
22
+ withNetworkMode(networkMode: string): this;
23
+ withExtraHosts(extraHosts: ExtraHost[]): this;
22
24
  withDefaultLogDriver(): this;
23
25
  withPrivilegedMode(): this;
24
26
  withUser(user: string): this;
25
27
  withPullPolicy(pullPolicy: PullPolicy): this;
26
28
  withReuse(): this;
27
- withCopyFileToContainer(sourcePath: string, containerPath: string): this;
28
- withCopyContentToContainer(content: string | Buffer | Readable, containerPath: string): this;
29
+ withCopyFilesToContainer(filesToCopy: FileToCopy[]): this;
30
+ withCopyContentToContainer(contentsToCopy: ContentToCopy[]): this;
29
31
  }
30
32
  export interface RestartOptions {
31
33
  timeout: number;
@@ -46,15 +48,15 @@ export interface ExecOptions {
46
48
  export interface StartedTestContainer {
47
49
  stop(options?: Partial<StopOptions>): Promise<StoppedTestContainer>;
48
50
  restart(options?: Partial<RestartOptions>): Promise<void>;
49
- getHost(): Host;
50
- getMappedPort(port: Port): Port;
51
- getName(): ContainerName;
51
+ getHost(): string;
52
+ getMappedPort(port: number): number;
53
+ getName(): string;
52
54
  getLabels(): Labels;
53
- getId(): Id;
55
+ getId(): string;
54
56
  getNetworkNames(): string[];
55
57
  getNetworkId(networkName: string): string;
56
58
  getIpAddress(networkName: string): string;
57
- exec(command: Command[], options?: Partial<ExecOptions>): Promise<ExecResult>;
59
+ exec(command: string[], options?: Partial<ExecOptions>): Promise<ExecResult>;
58
60
  logs(): Promise<Readable>;
59
61
  }
60
62
  export interface StoppedTestContainer {
@@ -1,4 +1,3 @@
1
- import { Port } from "./port";
2
1
  export declare class TestContainers {
3
- static exposeHostPorts(...ports: Port[]): Promise<void>;
2
+ static exposeHostPorts(...ports: number[]): Promise<void>;
4
3
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "testcontainers",
3
3
  "author": "Cristian Greco",
4
- "version": "8.16.0",
4
+ "version": "9.0.0",
5
5
  "main": "dist/index",
6
6
  "types": "dist/index",
7
7
  "keywords": [
@@ -24,22 +24,23 @@
24
24
  "scripts": {
25
25
  "prepare": "npm run build && husky install",
26
26
  "pre-commit": "lint-staged",
27
- "build": "npm run clean && tsc",
27
+ "build": "npm run clean && tsc -p tsconfig.prod.json",
28
28
  "clean": "rimraf dist",
29
- "test": "cross-env DEBUG=testcontainers jest --runInBand",
29
+ "test": "cross-env DEBUG=testcontainers,testcontainers:exec jest --runInBand",
30
30
  "format": "prettier --write package.json \"src/**/*.ts\"",
31
31
  "lint": "eslint --fix package.json \"src/**/*.ts\"",
32
- "updateDeps": "npx npm-check-updates -u"
32
+ "updateDeps": "npx npm-check-updates -u",
33
+ "validateEngine": "npx ls-engines"
33
34
  },
34
35
  "dependencies": {
35
36
  "@balena/dockerignore": "^1.0.2",
36
37
  "@types/archiver": "^5.3.1",
37
- "@types/dockerode": "^3.3.8",
38
+ "@types/dockerode": "^3.3.12",
38
39
  "archiver": "^5.3.1",
39
40
  "byline": "^5.0.0",
40
41
  "debug": "^4.3.4",
41
42
  "docker-compose": "^0.23.17",
42
- "dockerode": "^3.3.1",
43
+ "dockerode": "^3.3.4",
43
44
  "get-port": "^5.1.1",
44
45
  "properties-reader": "^2.2.0",
45
46
  "ssh-remote-port-forward": "^1.0.4",
@@ -49,33 +50,33 @@
49
50
  "@elastic/elasticsearch": "^7.17.0",
50
51
  "@types/byline": "^4.2.33",
51
52
  "@types/debug": "4.1.7",
52
- "@types/jest": "^27.4.1",
53
- "@types/node": "^17.0.25",
54
- "@types/node-fetch": "^2.6.1",
53
+ "@types/jest": "^29.2.0",
54
+ "@types/node": "^18.11.7",
55
+ "@types/node-fetch": "^2.6.2",
55
56
  "@types/pg": "^8.6.5",
56
57
  "@types/properties-reader": "^2.1.1",
57
58
  "@types/tar-fs": "^2.0.1",
58
- "@typescript-eslint/eslint-plugin": "^5.19.0",
59
- "@typescript-eslint/parser": "^5.19.0",
60
- "arangojs": "^7.7.0",
59
+ "@typescript-eslint/eslint-plugin": "^5.41.0",
60
+ "@typescript-eslint/parser": "^5.41.0",
61
+ "arangojs": "^8.0.0",
61
62
  "cross-env": "^7.0.3",
62
- "eslint": "^8.13.0",
63
+ "eslint": "^8.26.0",
63
64
  "eslint-config-prettier": "^8.5.0",
64
- "husky": "^7.0.4",
65
- "jest": "^27.5.1",
66
- "kafkajs": "^1.16.0",
67
- "lint-staged": "^12.3.8",
65
+ "husky": "^8.0.1",
66
+ "jest": "^29.2.2",
67
+ "kafkajs": "^2.2.2",
68
+ "lint-staged": "^13.0.3",
68
69
  "mysql2": "^2.3.3",
69
- "mongoose": "^5.13.15",
70
- "nats": "^2.7.1",
71
- "neo4j-driver": "^4.4.5",
70
+ "mongoose": "^6.7.0",
71
+ "nats": "^2.8.0",
72
+ "neo4j-driver": "^5.2.0",
72
73
  "node-fetch": "^2.6.7",
73
- "pg": "^8.7.3",
74
- "prettier": "^2.6.2",
74
+ "pg": "^8.8.0",
75
+ "prettier": "^2.7.1",
75
76
  "rimraf": "^3.0.2",
76
- "ts-jest": "^27.1.4",
77
- "ts-node": "^10.7.0",
78
- "typescript": "^4.6.3",
77
+ "ts-jest": "^29.0.3",
78
+ "ts-node": "^10.9.1",
79
+ "typescript": "^4.8.4",
79
80
  "wait-for-expect": "^3.0.2"
80
81
  },
81
82
  "lint-staged": {
@@ -83,5 +84,8 @@
83
84
  "prettier --write",
84
85
  "eslint --fix"
85
86
  ]
87
+ },
88
+ "engines": {
89
+ "node": ">= 10.16"
86
90
  }
87
91
  }