Skip to content

Commit f4f5232

Browse files
committed
feat(tests): add integration test script to package.json
1 parent e82a06f commit f4f5232

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"test": "pnpm test:node && pnpm test:edge",
3939
"test:edge": "vitest --config vitest.edge.config.mjs --run",
4040
"test:node": "vitest --config vitest.node.config.mjs --run",
41+
"test:integration": "vitest --config vitest.node.config.mjs --run src/__tests__/integration/",
4142
"coverage": "vitest run --coverage",
4243
"type-check": "tsc --noEmit",
4344
"prettier-check": "prettier --check \"./**/*.ts*\"",
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Integration tests for reranking models with real API.
3+
*
4+
* Run manually with: pnpm test:integration
5+
* Requires DASHSCOPE_API_KEY environment variable.
6+
*/
7+
import { rerank } from "ai"
8+
import { describe, expect, it } from "vitest"
9+
import { createQwen } from "../../qwen-provider"
10+
import "dotenv/config"
11+
12+
// Skip if no API key
13+
const SKIP_INTEGRATION = !process.env.DASHSCOPE_API_KEY
14+
15+
const qwen = createQwen({
16+
baseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1",
17+
})
18+
19+
const testDocuments = [
20+
"The quick brown fox jumps over the lazy dog.",
21+
"A lazy cat naps in the sun.",
22+
"The dog barks loudly at the mailman.",
23+
"The fox is a cunning animal.",
24+
]
25+
26+
describe.skipIf(SKIP_INTEGRATION)("reranking Integration Tests", () => {
27+
describe("gte-rerank-v2 (DashScope native API)", () => {
28+
it("should rerank documents successfully", async () => {
29+
const result = await rerank({
30+
model: qwen.rerankingModel("gte-rerank-v2"),
31+
documents: testDocuments,
32+
query: "animals that are not lazy",
33+
topN: 2,
34+
})
35+
36+
expect(result.ranking).toHaveLength(2)
37+
expect(result.ranking[0]).toHaveProperty("originalIndex")
38+
expect(result.ranking[0]).toHaveProperty("score")
39+
expect(result.rerankedDocuments).toHaveLength(2)
40+
})
41+
})
42+
43+
describe("qwen3-rerank (OpenAI-compatible API)", () => {
44+
it("should rerank documents successfully", async () => {
45+
const result = await rerank({
46+
model: qwen.rerankingModel("qwen3-rerank"),
47+
documents: testDocuments,
48+
query: "animals that are not lazy",
49+
topN: 2,
50+
})
51+
52+
expect(result.ranking).toHaveLength(2)
53+
expect(result.ranking[0]).toHaveProperty("originalIndex")
54+
expect(result.ranking[0]).toHaveProperty("score")
55+
expect(result.rerankedDocuments).toHaveLength(2)
56+
})
57+
58+
it("should support custom instruction", async () => {
59+
const result = await rerank({
60+
model: qwen.rerankingModel("qwen3-rerank", {
61+
instruct: "Retrieve semantically similar text.",
62+
}),
63+
documents: testDocuments,
64+
query: "animals that are not lazy",
65+
topN: 2,
66+
})
67+
68+
expect(result.ranking).toHaveLength(2)
69+
expect(result.rerankedDocuments).toHaveLength(2)
70+
})
71+
})
72+
})

0 commit comments

Comments
 (0)