Skip to content

Commit 3e36347

Browse files
committed
test(test-utils): prepare agent instances for alice and bob beforehand
1 parent 0469fbb commit 3e36347

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

packages/client/test-utils.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
import { inject } from 'vitest';
2+
3+
import type { Agent } from '~/agent';
24
import { createAgent } from '~/tsky';
35

4-
/**
5-
* Get Agent instance for testing accounts.
6-
* There are `@alice.test` and `@bob.test` now.
7-
* @param handle - handle name for test agent (without `@`)
8-
*/
9-
export async function getTestAgent(handle: 'alice.test' | 'bob.test') {
10-
const agent = await createAgent(
6+
type Handle = 'alice.test' | 'bob.test';
7+
8+
const testAgents: Record<Handle, Agent> = {
9+
'alice.test': await createTestAgent('alice.test'),
10+
'bob.test': await createTestAgent('bob.test'),
11+
};
12+
13+
function createTestAgent(handle: Handle) {
14+
return createAgent(
1115
{
1216
identifier: handle,
1317
password: 'password',
1418
},
1519
{ service: inject('testPdsUrl') },
1620
);
21+
}
1722

18-
return agent;
23+
/**
24+
* Get Agent instance for testing accounts.
25+
* There are `@alice.test` and `@bob.test` now.
26+
* @param handle - handle name for test agent (without `@`)
27+
*/
28+
export async function getTestAgent(handle: Handle) {
29+
return testAgents[handle];
1930
}

0 commit comments

Comments
 (0)