Skip to content

Commit 90adb75

Browse files
vitest
1 parent cfae102 commit 90adb75

File tree

2 files changed

+68
-52
lines changed

2 files changed

+68
-52
lines changed

packages/test/package.json

+14-10
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,29 @@
55
"type": "module",
66
"types": "dist/index.d.ts",
77
"dependencies": {
8-
"@ai16z/eliza": "workspace:*",
9-
"@ai16z/plugin-solana": "workspace:*",
10-
"@ai16z/plugin-node": "workspace:*",
11-
"@ai16z/plugin-bootstrap": "workspace:*",
8+
"@ai16z/adapter-sqlite": "workspace:*",
129
"@ai16z/adapter-sqljs": "workspace:*",
1310
"@ai16z/adapter-supabase": "workspace:*",
14-
"@ai16z/adapter-sqlite": "workspace:*",
15-
"tsup": "^8.3.5",
11+
"@ai16z/eliza": "workspace:*",
12+
"@ai16z/plugin-bootstrap": "workspace:*",
13+
"@ai16z/plugin-node": "workspace:*",
14+
"@ai16z/plugin-solana": "workspace:*",
15+
"@coral-xyz/anchor": "^0.30.1",
1616
"@solana/spl-token": "0.4.9",
1717
"@solana/web3.js": "1.95.4",
18-
"@coral-xyz/anchor": "^0.30.1",
18+
"@types/jest": "^29.5.14",
1919
"bignumber": "1.1.0",
2020
"bignumber.js": "9.1.2",
21+
"jest": "^29.7.0",
22+
"node-cache": "5.1.2",
2123
"pumpdotfun-sdk": "1.3.2",
22-
"node-cache": "5.1.2"
24+
"ts-jest": "^29.2.5",
25+
"tsup": "^8.3.5",
26+
"vitest": "^2.1.4"
2327
},
2428
"scripts": {
25-
"test": "jest --runInBand",
26-
"test:watch": "jest --runInBand --watch"
29+
"test": "vitest",
30+
"test:watch": "vitest --watch"
2731
},
2832
"peerDependencies": {
2933
"whatwg-url": "7.1.0"

packages/test/src/tests/actions.test.ts

+54-42
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import dotenv from "dotenv";
2+
import { describe, test, expect, beforeAll, afterAll } from "vitest";
23
import { createRuntime } from "../test_resources/createRuntime.js";
34
import { getOrCreateRelationship } from "../test_resources/getOrCreateRelationship.js";
45
import { runAiTest } from "../test_resources/runAiTest.js";
56
import { messageHandlerTemplate } from "../test_resources/templates.js";
67
import { TEST_ACTION, TEST_ACTION_FAIL } from "../test_resources/testAction.js";
7-
import { type User } from "../test_resources/types.js";
8+
import { User } from "../test_resources/types.js";
89
import {
910
MemoryManager,
1011
Content,
1112
IAgentRuntime,
1213
ModelClass,
1314
State,
14-
type Memory,
15-
type UUID,
15+
Memory,
16+
UUID,
1617
stringToUuid,
1718
composeContext,
1819
generateMessageResponse,
@@ -220,46 +221,57 @@ describe("Actions", () => {
220221
});
221222

222223
// Validate that TEST_ACTION is in the state
223-
test("Validate that TEST_ACTION is in the state", async () => {
224-
await runAiTest("Validate TEST_ACTION is in the state", async () => {
225-
const message: Memory = {
226-
agentId: runtime.agentId,
227-
userId: user.id as UUID,
228-
content: {
229-
text: "Please respond with the message 'ok' and the action TEST_ACTION",
230-
},
231-
roomId,
232-
};
233-
234-
const response = await handleMessage(runtime, message);
235-
return response.action === "TEST_ACTION"; // Return true if the expected action matches
236-
});
237-
}, 60000);
224+
test(
225+
"Validate that TEST_ACTION is in the state",
226+
async () => {
227+
await runAiTest(
228+
"Validate TEST_ACTION is in the state",
229+
async () => {
230+
const message: Memory = {
231+
agentId: runtime.agentId,
232+
userId: user.id as UUID,
233+
content: {
234+
text: "Please respond with the message 'ok' and the action TEST_ACTION",
235+
},
236+
roomId,
237+
};
238+
239+
const response = await handleMessage(runtime, message);
240+
return response.action === "TEST_ACTION"; // Return true if the expected action matches
241+
}
242+
);
243+
},
244+
{ timeout: 60000 }
245+
);
238246

239247
// Test that TEST_ACTION action handler is called properly
240-
test("Test action handler is called", async () => {
241-
await runAiTest("Test action handler is called", async () => {
242-
const testAction = runtime.actions.find(
243-
(action) => action.name === "TEST_ACTION"
244-
);
245-
if (!testAction || !testAction.handler) {
246-
console.error(
247-
"Continue action or its handler function is undefined"
248+
test(
249+
"Test action handler is called",
250+
async () => {
251+
await runAiTest("Test action handler is called", async () => {
252+
const testAction = runtime.actions.find(
253+
(action) => action.name === "TEST_ACTION"
248254
);
249-
return false; // Return false to indicate the test setup failed
250-
}
251-
252-
const mockMessage: Memory = {
253-
userId: user.id as UUID,
254-
agentId: runtime.agentId,
255-
content: {
256-
text: "Test message for TEST action",
257-
},
258-
roomId,
259-
};
260-
261-
const response = await testAction.handler(runtime, mockMessage);
262-
return response !== undefined; // Return true if the handler returns a defined response
263-
});
264-
}, 60000); // You can adjust the timeout if needed
255+
if (!testAction || !testAction.handler) {
256+
console.error(
257+
"Continue action or its handler function is undefined"
258+
);
259+
return false; // Return false to indicate the test setup failed
260+
}
261+
262+
const mockMessage: Memory = {
263+
userId: user.id as UUID,
264+
agentId: runtime.agentId,
265+
content: {
266+
text: "Test message for TEST action",
267+
},
268+
roomId,
269+
};
270+
271+
const response = await testAction.handler(runtime, mockMessage);
272+
return response !== undefined; // Return true if the handler returns a defined response
273+
});
274+
},
275+
{ timeout: 60000 }
276+
); // You can adjust the timeout if needed
265277
});

0 commit comments

Comments
 (0)