testcontainers 7.23.2 → 7.24.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.
package/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
  [![Node.js CI](https://github.com/testcontainers/testcontainers-node/actions/workflows/node.js.yml/badge.svg?branch=master)](https://github.com/testcontainers/testcontainers-node/actions/workflows/node.js.yml)
6
6
  [![npm version](https://badge.fury.io/js/testcontainers.svg)](https://www.npmjs.com/package/testcontainers)
7
7
  [![npm version](https://img.shields.io/npm/dm/testcontainers.svg)](https://www.npmjs.com/package/testcontainers)
8
+ [![Thundra Foresight](https://thundra-assets-prod.s3.us-west-2.amazonaws.com/images/badges/thundra-foresight-badge-enabled.svg)](https://foresight.thundra.live/testRuns/57175ecb-d5ac-4129-957a-9dd617fd27d0)
9
+ [![Foresight Test Summary](https://foresight.service.thundra.us/public/api/v1/badge/test/57175ecb-d5ac-4129-957a-9dd617fd27d0)](https://foresight.thundra.live/testruns/57175ecb-d5ac-4129-957a-9dd617fd27d0)
8
10
 
9
11
  ## Install
10
12
 
@@ -276,6 +278,22 @@ const fooContainer = await new GenericContainer("alpine")
276
278
  expect((await container.exec(["nslookup", "foo"])).exitCode).toBe(0);
277
279
  ```
278
280
 
281
+ Add hostname mappings:
282
+
283
+ ```javascript
284
+ const { GenericContainer } = require("testcontainers");
285
+
286
+ const container = await new GenericContainer("alpine")
287
+ .withExtraHosts([
288
+ { host: "foo", ipAddress: "10.11.12.13" },
289
+ { host: "bar", ipAddress: "11.12.13.14" }
290
+ ])
291
+ .start();
292
+
293
+ expect((await container.exec(["nslookup", "foo"])).exitCode).toBe(0);
294
+ expect((await container.exec(["nslookup", "bar"])).exitCode).toBe(0);
295
+ ```
296
+
279
297
  Specifying a pull policy. Note that if omitted will use the `DefaultPullPolicy` which will use a locally cached image
280
298
  if one already exists, this is usually the preferred option. In cases where there is a local image for a given tag
281
299
  but the remote image with the same tag may have changed (for example when using the `latest` tag), you can tell
@@ -19,18 +19,11 @@ const execContainer = (container, command) => __awaiter(void 0, void 0, void 0,
19
19
  AttachStderr: true,
20
20
  });
21
21
  const stream = yield startExec(exec);
22
- return yield new Promise((resolve) => {
23
- const chunks = [];
24
- stream.on("data", (chunk) => chunks.push(chunk));
25
- const interval = setInterval(() => __awaiter(void 0, void 0, void 0, function* () {
26
- const { running, exitCode } = yield inspectExec(exec);
27
- if (!running) {
28
- clearInterval(interval);
29
- stream.destroy();
30
- resolve({ output: chunks.join(""), exitCode });
31
- }
32
- }), 100);
33
- });
22
+ const chunks = [];
23
+ stream.on("data", (chunk) => chunks.push(chunk));
24
+ const exitCode = yield waitForExec(exec);
25
+ stream.destroy();
26
+ return { output: chunks.join(""), exitCode };
34
27
  }
35
28
  catch (err) {
36
29
  logger_1.log.error(`Failed to exec container ${container.id} with command "${command.join(" ")}": ${err}`);
@@ -72,3 +65,14 @@ const inspectExec = (exec) => __awaiter(void 0, void 0, void 0, function* () {
72
65
  throw err;
73
66
  }
74
67
  });
68
+ const waitForExec = (exec) => __awaiter(void 0, void 0, void 0, function* () {
69
+ return new Promise((resolve) => {
70
+ const interval = setInterval(() => __awaiter(void 0, void 0, void 0, function* () {
71
+ const { running, exitCode } = yield inspectExec(exec);
72
+ if (!running) {
73
+ clearInterval(interval);
74
+ resolve(exitCode);
75
+ }
76
+ }), 100);
77
+ });
78
+ });
@@ -6,7 +6,7 @@ import { PullPolicy } from "../pull-policy";
6
6
  import { StartedTestContainer, TestContainer } from "../test-container";
7
7
  import { WaitStrategy } from "../wait-strategy";
8
8
  import { Readable } from "stream";
9
- import { BindMode, BindMount, BuildContext, Command, ContainerName, Dir, Env, EnvKey, EnvValue, HealthCheck, NetworkMode, TmpFs } from "../docker/types";
9
+ import { BindMode, BindMount, BuildContext, Command, ContainerName, Dir, Env, EnvKey, EnvValue, ExtraHost, HealthCheck, NetworkMode, TmpFs } from "../docker/types";
10
10
  import { GenericContainerBuilder } from "./generic-container-builder";
11
11
  export declare class GenericContainer implements TestContainer {
12
12
  readonly image: string;
@@ -38,6 +38,7 @@ export declare class GenericContainer implements TestContainer {
38
38
  withTmpFs(tmpFs: TmpFs): this;
39
39
  withNetworkMode(networkMode: NetworkMode): this;
40
40
  withNetworkAliases(...networkAliases: string[]): this;
41
+ withExtraHosts(...extraHosts: ExtraHost[]): this;
41
42
  withExposedPorts(...ports: Port[]): this;
42
43
  withBindMount(source: Dir, target: Dir, bindMode?: BindMode): this;
43
44
  withHealthCheck(healthCheck: HealthCheck): this;
@@ -94,7 +94,11 @@ class GenericContainer {
94
94
  const portForwarderNetworkId = portForwarder.getNetworkId();
95
95
  const excludedNetworks = [portForwarderNetworkId, "none", "host"];
96
96
  if (!this.networkMode || !excludedNetworks.includes(this.networkMode)) {
97
- yield connect_network_1.connectNetwork({ containerId: container.id, networkId: portForwarderNetworkId, networkAliases: [] });
97
+ yield connect_network_1.connectNetwork({
98
+ containerId: container.id,
99
+ networkId: portForwarderNetworkId,
100
+ networkAliases: [],
101
+ });
98
102
  }
99
103
  }
100
104
  if (this.networkMode && this.networkAliases.length > 0) {
@@ -142,6 +146,10 @@ class GenericContainer {
142
146
  this.networkAliases = networkAliases;
143
147
  return this;
144
148
  }
149
+ withExtraHosts(...extraHosts) {
150
+ this.extraHosts.push(...extraHosts);
151
+ return this;
152
+ }
145
153
  withExposedPorts(...ports) {
146
154
  this.ports = ports;
147
155
  return this;
@@ -3,7 +3,7 @@ import { Port } 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, Host, Id, NetworkMode, TmpFs } from "./docker/types";
6
+ import { BindMode, Command, ContainerName, Dir, EnvKey, EnvValue, ExecResult, ExtraHost, Host, Id, NetworkMode, TmpFs } from "./docker/types";
7
7
  export interface TestContainer {
8
8
  start(): Promise<StartedTestContainer>;
9
9
  withEnv(key: EnvKey, value: EnvValue): this;
@@ -14,6 +14,7 @@ export interface TestContainer {
14
14
  withWaitStrategy(waitStrategy: WaitStrategy): this;
15
15
  withStartupTimeout(startupTimeout: number): this;
16
16
  withNetworkMode(networkMode: NetworkMode): this;
17
+ withExtraHosts(...extraHosts: ExtraHost[]): this;
17
18
  withDefaultLogDriver(): this;
18
19
  withPrivilegedMode(): this;
19
20
  withUser(user: string): this;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "testcontainers",
3
3
  "author": "Cristian Greco",
4
- "version": "7.23.2",
4
+ "version": "7.24.0",
5
5
  "main": "dist/index",
6
6
  "types": "dist/index",
7
7
  "keywords": [
@@ -26,7 +26,7 @@
26
26
  "pre-commit": "lint-staged",
27
27
  "build": "npm run clean && tsc",
28
28
  "clean": "rimraf dist",
29
- "test": "cross-env DEBUG=testcontainers jest --maxWorkers=2",
29
+ "test": "cross-env DEBUG=testcontainers jest --runInBand",
30
30
  "format": "prettier --write package.json \"src/**/*.ts\"",
31
31
  "lint": "eslint --fix package.json \"src/**/*.ts\"",
32
32
  "updateDeps": "npx npm-check-updates -u"