Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/src/content/docs/guides/using-vitest.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Create a `tsconfig.json` file:
"module": "ESNext",
"moduleDetection": "force",
"allowJs": true, // allow importing `.js` from `.ts`
"types": ["node"],
"types": ["node", "vitest"],

// Bundler mode
"moduleResolution": "bundler",
Expand All @@ -64,24 +64,24 @@ Create a `tsconfig.json` file:
The PocketIC server needs to be started before running tests and stopped once they're finished running. This can be done by creating a `global-setup.ts` file in your project's root directory:

```ts title="global-setup.ts"
import type { GlobalSetupContext } from 'vitest/node';
import type { TestProject } from 'vitest/node';
import { PocketIcServer } from '@dfinity/pic';

let pic: PocketIcServer | undefined;

export async function setup(ctx: GlobalSetupContext): Promise<void> {
export async function setup(project: TestProject): Promise<void> {
pic = await PocketIcServer.start();
const url = pic.getUrl();

ctx.provide('PIC_URL', url);
project.provide('PIC_URL', url);
}

export async function teardown(): Promise<void> {
await pic?.stop();
}
```

To improve type-safety for `ctx.provide('PIC_URL')` and (later) `inject('PIC_URL')`, create a `types.d.ts` file:
To improve type-safety for `project.provide('PIC_URL')` and (later) `inject('PIC_URL')`, create a `types.d.ts` file:

```ts title="types.d.ts"
export declare module 'vitest' {
Expand Down
Loading