Skip to content

Commit 1ca4827

Browse files
committed
chore: migrate setupFile to globalSetup
1 parent 25a0b1d commit 1ca4827

File tree

4 files changed

+48
-34
lines changed

4 files changed

+48
-34
lines changed

packages/client/globalSetup.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { TestProject } from 'vitest/node';
2+
3+
import { CredentialManager, XRPC } from '@atcute/client';
4+
import { TestNetwork } from '@atcute/internal-dev-env';
5+
6+
let network: TestNetwork;
7+
8+
export async function setup(project: TestProject) {
9+
network = await TestNetwork.create({});
10+
console.log(
11+
`🌐 Created test network:\n- pds: ${network.pds.url}\n- plc: ${network.plc.url}`,
12+
);
13+
14+
const manager = new CredentialManager({ service: network.pds.url });
15+
const rpc = new XRPC({
16+
handler: manager,
17+
});
18+
19+
await createAccount(rpc, 'alice.test');
20+
await createAccount(rpc, 'bob.test');
21+
22+
project.provide('testPdsUrl', network.pds.url);
23+
project.provide('testPlcUrl', network.plc.url);
24+
}
25+
26+
export async function teardown() {
27+
await network.close();
28+
}
29+
30+
const createAccount = async (rpc: XRPC, handle: string) => {
31+
await rpc.call('com.atproto.server.createAccount', {
32+
data: {
33+
handle: handle,
34+
email: `${handle}@example.com`,
35+
password: 'password',
36+
},
37+
});
38+
console.log(`🙋 Created new account: @${handle}`);
39+
};
40+
41+
declare module 'vitest' {
42+
export interface ProvidedContext {
43+
testPdsUrl: string;
44+
testPlcUrl: string;
45+
}
46+
}

packages/client/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"verbatimModuleSyntax": true,
3232
"skipLibCheck": true
3333
},
34-
"include": ["./src/**/*", "vitest.setup.ts"],
34+
"include": ["./src/**/*", "globalSetup.ts"],
3535
"typedocOptions": {
3636
"out": "./docs",
3737
"theme": "default",

packages/client/vitest.config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineConfig } from 'vitest/config';
22

33
export default defineConfig({
44
test: {
5-
setupFiles: 'vitest.setup.ts',
5+
globalSetup: 'globalSetup.ts',
66
coverage: {
77
provider: 'istanbul',
88
reporter: ['text', 'json-summary', 'json', 'html'],

packages/client/vitest.setup.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)