Skip to content

Commit d78c75e

Browse files
authored
test(mongodb): fix mongodb tests (#9276)
1 parent 831168a commit d78c75e

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

libs/providers/langchain-mongodb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"lint:fix": "pnpm lint:eslint --fix && pnpm lint:dpdm",
2323
"clean": "rm -rf .turbo dist/",
2424
"test:watch": "vitest",
25-
"test:int": "vitest run --mode int --testTimeout 100000 --maxWorkers=50%",
25+
"test:int": "vitest run --mode int --testTimeout 10000 --maxWorkers=50%",
2626
"format": "prettier --config .prettierrc --write \"src\"",
2727
"format:check": "prettier --config .prettierrc --check \"src\""
2828
},

libs/providers/langchain-mongodb/src/tests/storage.int.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, test, expect, beforeAll, afterAll } from "vitest";
1+
import { describe, test, expect, beforeAll, afterAll, afterEach } from "vitest";
22
import { v4 as uuidv4 } from "uuid";
33
import { Collection, MongoClient, ServerApiVersion } from "mongodb";
44
import { MongoDBStore } from "../storage.js";

libs/providers/langchain-mongodb/src/tests/vectorstores.int.test.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { beforeAll, expect, vi, test, type MockInstance } from "vitest";
1+
import {
2+
afterAll,
3+
beforeAll,
4+
beforeEach,
5+
describe,
6+
expect,
7+
vi,
8+
test,
9+
type MockInstance,
10+
} from "vitest";
211
import { Collection, MongoClient } from "mongodb";
312
import { setTimeout } from "timers/promises";
413
import { OpenAIEmbeddings, AzureOpenAIEmbeddings } from "@langchain/openai";
@@ -33,7 +42,7 @@ beforeAll(async () => {
3342
client = new MongoClient(uri(), { monitorCommands: true });
3443
await client.connect();
3544

36-
const namespace = "langchain.test";
45+
const namespace = "langchain_test_db.langchain_test";
3746
const [dbName, collectionName] = namespace.split(".");
3847
collection = await client.db(dbName).createCollection(collectionName);
3948

@@ -108,13 +117,13 @@ function getEmbeddings() {
108117
}
109118

110119
test("MongoDBStore sets client metadata", () => {
111-
const spy = jest.spyOn(client, "appendMetadata");
120+
const spy = vi.spyOn(client, "appendMetadata");
112121
// eslint-disable-next-line no-new
113122
new PatchedVectorStore(getEmbeddings(), {
114123
collection,
115124
});
116125
expect(spy).toHaveBeenCalledWith({ name: "langchainjs_vector" });
117-
jest.clearAllMocks();
126+
vi.clearAllMocks();
118127
});
119128

120129
test("MongoDBAtlasVectorSearch with external ids", async () => {
@@ -199,7 +208,7 @@ test("MongoDBAtlasVectorSearch with Maximal Marginal Relevance", async () => {
199208

200209
const standardRetriever = await vectorStore.asRetriever();
201210

202-
const standardRetrieverOutput = await standardRetriever.getRelevantDocuments(
211+
const standardRetrieverOutput = await standardRetriever._getRelevantDocuments(
203212
"foo"
204213
);
205214
expect(output).toHaveLength(texts.length);
@@ -218,7 +227,7 @@ test("MongoDBAtlasVectorSearch with Maximal Marginal Relevance", async () => {
218227
},
219228
});
220229

221-
const retrieverOutput = await retriever.getRelevantDocuments("foo");
230+
const retrieverOutput = await retriever._getRelevantDocuments("foo");
222231
expect(output).toHaveLength(texts.length);
223232

224233
const retrieverActual = retrieverOutput.map((doc) => doc.pageContent);

0 commit comments

Comments
 (0)