Skip to content

Commit

Permalink
Replace node-fetch with Node.js' native fetch (#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurre authored Jul 27, 2024
1 parent 6152416 commit fe7b00a
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 154 deletions.
121 changes: 11 additions & 110 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions packages/modules/couchbase/src/couchbase-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ describe("CouchbaseContainer", () => {
// connectAndQuery {
it("should connect and query using enterprise image", async () => {
const bucketDefinition = new BucketDefinition("mybucket");
const container = await new CouchbaseContainer(COUCHBASE_IMAGE_ENTERPRISE).withBucket(bucketDefinition);
const container = new CouchbaseContainer(COUCHBASE_IMAGE_ENTERPRISE).withBucket(bucketDefinition);

startedTestContainer = await container.start();

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

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

startedTestContainer = await container.start();
cluster = new couchbase.Cluster(startedTestContainer.getConnectionString(), {
cluster = await couchbase.Cluster.connect(startedTestContainer.getConnectionString(), {
username: startedTestContainer.getUsername(),
password: startedTestContainer.getPassword(),
});
Expand Down Expand Up @@ -105,10 +105,10 @@ describe("CouchbaseContainer", () => {

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

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

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

startedTestContainer = await container.start();
cluster = new couchbase.Cluster(startedTestContainer.getConnectionString(), {
cluster = await couchbase.Cluster.connect(startedTestContainer.getConnectionString(), {
username: startedTestContainer.getUsername(),
password: startedTestContainer.getPassword(),
});
Expand All @@ -140,7 +140,7 @@ describe("CouchbaseContainer", () => {
});

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

it("should throw error if eventing service enabled with community version", async () => {
const container = await new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY).withEnabledServices(
const container = new CouchbaseContainer(COUCHBASE_IMAGE_COMMUNITY).withEnabledServices(
CouchbaseService.KV,
CouchbaseService.EVENTING
);
Expand Down
7 changes: 3 additions & 4 deletions packages/modules/couchbase/src/couchbase-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { BoundPorts } from "testcontainers/src/utils/bound-ports";
import { ContainerRuntimeClient, getContainerRuntimeClient } from "testcontainers/src/container-runtime";
import { CouchbaseService } from "./couchbase-service";
import { BucketDefinition } from "./bucket-definition";
import fetch, { Response } from "node-fetch";
import PORTS from "./ports";
import { IntervalRetry } from "testcontainers/src/common";

Expand Down Expand Up @@ -194,7 +193,7 @@ export class CouchbaseContainer extends GenericContainer {
);
let jsonResponse;
try {
jsonResponse = await response.json();
jsonResponse = (await response.json()) as { isEnterprise: boolean };
} catch (e) {
throw new Error("Couchbase /pools did not return valid JSON");
}
Expand Down Expand Up @@ -447,7 +446,7 @@ export class CouchbaseContainer extends GenericContainer {
if (response === undefined) {
return false;
}
const jsonResponse = await response.json();
const jsonResponse = (await response.json()) as { results: Array<{ present: boolean }> };
return jsonResponse.results[0].present;
},
() => {
Expand Down Expand Up @@ -508,7 +507,7 @@ export class CouchbaseContainer extends GenericContainer {
if (response === undefined) {
return false;
}
const jsonResponse = await response.json();
const jsonResponse = (await response.json()) as { results: Array<{ online: boolean }> };
return jsonResponse.results[0].online;
},
() => {
Expand Down
6 changes: 3 additions & 3 deletions packages/modules/ollama/src/ollama-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("OllamaContainer", () => {
// }
const response = await fetch(`${container.getEndpoint()}/api/version`);
expect(response.status).toEqual(200);
const body = await response.json();
const body = (await response.json()) as { version: string };
expect(body.version).toEqual("0.1.44");
await container.stop();
});
Expand All @@ -22,7 +22,7 @@ describe("OllamaContainer", () => {
console.log(execResult.output);
const response = await fetch(`${container.getEndpoint()}/api/tags`);
expect(response.status).toEqual(200);
const body = await response.json();
const body = (await response.json()) as { models: { name: string }[] };
expect(body.models[0].name).toContain("all-minilm");

const newImageName: string = "tc-ollama-allminilm-" + (Math.random() + 1).toString(36).substring(4).toLowerCase();
Expand All @@ -36,7 +36,7 @@ describe("OllamaContainer", () => {
// }
const response2 = await fetch(`${newContainer.getEndpoint()}/api/tags`);
expect(response2.status).toEqual(200);
const body2 = await response2.json();
const body2 = (await response2.json()) as { models: { name: string }[] };
expect(body2.models[0].name).toContain("all-minilm");
await newContainer.stop();
});
Expand Down
3 changes: 1 addition & 2 deletions packages/modules/redpanda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"testcontainers": "^10.10.4"
},
"devDependencies": {
"kafkajs": "^2.2.4",
"node-fetch": "^3.3.2"
"kafkajs": "^2.2.4"
}
}
5 changes: 2 additions & 3 deletions packages/testcontainers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@
"docker-compose": "^0.24.8",
"dockerode": "^3.3.5",
"get-port": "^5.1.1",
"node-fetch": "^2.7.0",
"proper-lockfile": "^4.1.2",
"properties-reader": "^2.3.0",
"ssh-remote-port-forward": "^1.0.4",
"tar-fs": "^3.0.6",
"tmp": "^0.2.3"
"tmp": "^0.2.3",
"undici": "^5.28.4"
},
"devDependencies": {
"@types/archiver": "^5.3.4",
"@types/async-lock": "^1.4.2",
"@types/byline": "^4.2.36",
"@types/debug": "^4.1.12",
"@types/node-fetch": "^2.6.11",
"@types/proper-lockfile": "^4.1.4",
"@types/properties-reader": "^2.1.3",
"@types/tar-fs": "^2.0.4",
Expand Down
Loading

0 comments on commit fe7b00a

Please sign in to comment.