Skip to content

Commit fe7b00a

Browse files
authored
Replace node-fetch with Node.js' native fetch (#777)
1 parent 6152416 commit fe7b00a

File tree

11 files changed

+53
-154
lines changed

11 files changed

+53
-154
lines changed

package-lock.json

Lines changed: 11 additions & 110 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/modules/couchbase/src/couchbase-container.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ describe("CouchbaseContainer", () => {
5050
// connectAndQuery {
5151
it("should connect and query using enterprise image", async () => {
5252
const bucketDefinition = new BucketDefinition("mybucket");
53-
const container = await new CouchbaseContainer(COUCHBASE_IMAGE_ENTERPRISE).withBucket(bucketDefinition);
53+
const container = new CouchbaseContainer(COUCHBASE_IMAGE_ENTERPRISE).withBucket(bucketDefinition);
5454

5555
startedTestContainer = await container.start();
5656

57-
cluster = new couchbase.Cluster(startedTestContainer.getConnectionString(), {
57+
cluster = await couchbase.Cluster.connect(startedTestContainer.getConnectionString(), {
5858
username: startedTestContainer.getUsername(),
5959
password: startedTestContainer.getPassword(),
6060
});
@@ -68,10 +68,10 @@ describe("CouchbaseContainer", () => {
6868

6969
it("should flush bucket if flushEnabled and check any document exists", async () => {
7070
const bucketDefinition = new BucketDefinition("mybucket").withFlushEnabled(true);
71-
const container = await new CouchbaseContainer(COUCHBASE_IMAGE_ENTERPRISE).withBucket(bucketDefinition);
71+
const container = new CouchbaseContainer(COUCHBASE_IMAGE_ENTERPRISE).withBucket(bucketDefinition);
7272

7373
startedTestContainer = await container.start();
74-
cluster = new couchbase.Cluster(startedTestContainer.getConnectionString(), {
74+
cluster = await couchbase.Cluster.connect(startedTestContainer.getConnectionString(), {
7575
username: startedTestContainer.getUsername(),
7676
password: startedTestContainer.getPassword(),
7777
});
@@ -105,10 +105,10 @@ describe("CouchbaseContainer", () => {
105105

106106
it("should connect and query using community image", async () => {
107107
const bucketDefinition = new BucketDefinition("mybucket");
108-
const container = await new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY).withBucket(bucketDefinition);
108+
const container = new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY).withBucket(bucketDefinition);
109109

110110
startedTestContainer = await container.start();
111-
cluster = new couchbase.Cluster(startedTestContainer.getConnectionString(), {
111+
cluster = await couchbase.Cluster.connect(startedTestContainer.getConnectionString(), {
112112
username: startedTestContainer.getUsername(),
113113
password: startedTestContainer.getPassword(),
114114
});
@@ -121,10 +121,10 @@ describe("CouchbaseContainer", () => {
121121

122122
it("should flush bucket if flushEnabled and check any document exists", async () => {
123123
const bucketDefinition = new BucketDefinition("mybucket").withFlushEnabled(true);
124-
const container = await new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY).withBucket(bucketDefinition);
124+
const container = new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY).withBucket(bucketDefinition);
125125

126126
startedTestContainer = await container.start();
127-
cluster = new couchbase.Cluster(startedTestContainer.getConnectionString(), {
127+
cluster = await couchbase.Cluster.connect(startedTestContainer.getConnectionString(), {
128128
username: startedTestContainer.getUsername(),
129129
password: startedTestContainer.getPassword(),
130130
});
@@ -140,7 +140,7 @@ describe("CouchbaseContainer", () => {
140140
});
141141

142142
it("should throw error if analytics service enabled with community version", async () => {
143-
const container = await new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY).withEnabledServices(
143+
const container = new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY).withEnabledServices(
144144
CouchbaseService.KV,
145145
CouchbaseService.ANALYTICS
146146
);
@@ -151,7 +151,7 @@ describe("CouchbaseContainer", () => {
151151
});
152152

153153
it("should throw error if eventing service enabled with community version", async () => {
154-
const container = await new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY).withEnabledServices(
154+
const container = new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY).withEnabledServices(
155155
CouchbaseService.KV,
156156
CouchbaseService.EVENTING
157157
);

packages/modules/couchbase/src/couchbase-container.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { BoundPorts } from "testcontainers/src/utils/bound-ports";
1111
import { ContainerRuntimeClient, getContainerRuntimeClient } from "testcontainers/src/container-runtime";
1212
import { CouchbaseService } from "./couchbase-service";
1313
import { BucketDefinition } from "./bucket-definition";
14-
import fetch, { Response } from "node-fetch";
1514
import PORTS from "./ports";
1615
import { IntervalRetry } from "testcontainers/src/common";
1716

@@ -194,7 +193,7 @@ export class CouchbaseContainer extends GenericContainer {
194193
);
195194
let jsonResponse;
196195
try {
197-
jsonResponse = await response.json();
196+
jsonResponse = (await response.json()) as { isEnterprise: boolean };
198197
} catch (e) {
199198
throw new Error("Couchbase /pools did not return valid JSON");
200199
}
@@ -447,7 +446,7 @@ export class CouchbaseContainer extends GenericContainer {
447446
if (response === undefined) {
448447
return false;
449448
}
450-
const jsonResponse = await response.json();
449+
const jsonResponse = (await response.json()) as { results: Array<{ present: boolean }> };
451450
return jsonResponse.results[0].present;
452451
},
453452
() => {
@@ -508,7 +507,7 @@ export class CouchbaseContainer extends GenericContainer {
508507
if (response === undefined) {
509508
return false;
510509
}
511-
const jsonResponse = await response.json();
510+
const jsonResponse = (await response.json()) as { results: Array<{ online: boolean }> };
512511
return jsonResponse.results[0].online;
513512
},
514513
() => {

packages/modules/ollama/src/ollama-container.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("OllamaContainer", () => {
99
// }
1010
const response = await fetch(`${container.getEndpoint()}/api/version`);
1111
expect(response.status).toEqual(200);
12-
const body = await response.json();
12+
const body = (await response.json()) as { version: string };
1313
expect(body.version).toEqual("0.1.44");
1414
await container.stop();
1515
});
@@ -22,7 +22,7 @@ describe("OllamaContainer", () => {
2222
console.log(execResult.output);
2323
const response = await fetch(`${container.getEndpoint()}/api/tags`);
2424
expect(response.status).toEqual(200);
25-
const body = await response.json();
25+
const body = (await response.json()) as { models: { name: string }[] };
2626
expect(body.models[0].name).toContain("all-minilm");
2727

2828
const newImageName: string = "tc-ollama-allminilm-" + (Math.random() + 1).toString(36).substring(4).toLowerCase();
@@ -36,7 +36,7 @@ describe("OllamaContainer", () => {
3636
// }
3737
const response2 = await fetch(`${newContainer.getEndpoint()}/api/tags`);
3838
expect(response2.status).toEqual(200);
39-
const body2 = await response2.json();
39+
const body2 = (await response2.json()) as { models: { name: string }[] };
4040
expect(body2.models[0].name).toContain("all-minilm");
4141
await newContainer.stop();
4242
});

packages/modules/redpanda/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"testcontainers": "^10.10.4"
3434
},
3535
"devDependencies": {
36-
"kafkajs": "^2.2.4",
37-
"node-fetch": "^3.3.2"
36+
"kafkajs": "^2.2.4"
3837
}
3938
}

packages/testcontainers/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,18 @@
3939
"docker-compose": "^0.24.8",
4040
"dockerode": "^3.3.5",
4141
"get-port": "^5.1.1",
42-
"node-fetch": "^2.7.0",
4342
"proper-lockfile": "^4.1.2",
4443
"properties-reader": "^2.3.0",
4544
"ssh-remote-port-forward": "^1.0.4",
4645
"tar-fs": "^3.0.6",
47-
"tmp": "^0.2.3"
46+
"tmp": "^0.2.3",
47+
"undici": "^5.28.4"
4848
},
4949
"devDependencies": {
5050
"@types/archiver": "^5.3.4",
5151
"@types/async-lock": "^1.4.2",
5252
"@types/byline": "^4.2.36",
5353
"@types/debug": "^4.1.12",
54-
"@types/node-fetch": "^2.6.11",
5554
"@types/proper-lockfile": "^4.1.4",
5655
"@types/properties-reader": "^2.1.3",
5756
"@types/tar-fs": "^2.0.4",

0 commit comments

Comments
 (0)