You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **`vitest.config.ts`** (or `.js`) configures the testing framework. Make sure to import `defineConfig` from `vitest/config` (and not for `vite`). This configuration will work with Vitest v4 and higher.
120
+
121
+
{% code expandable="true" %}
122
+
```typescript
123
+
import { defineConfig } from"vitest/config";
124
+
import {
125
+
vitestSetupFilePath,
126
+
getClarinetVitestsArgv,
127
+
} from"@stacks/clarinet-sdk/vitest";
128
+
129
+
/*
130
+
In this file, Vitest is configured so that it works seamlessly with Clarinet and the Simnet.
131
+
The `vitest-environment-clarinet` will initialise the clarinet-sdk
132
+
and make the `simnet` object available globally in the test files.
133
+
`vitestSetupFilePath` points to a file in the `@stacks/clarinet-sdk` package that does two things:
134
+
- run `before` hooks to initialize the simnet and `after` hooks to collect costs and coverage reports.
135
+
- load custom vitest matchers to work with Clarity values (such as `expect(...).toBeUint()`)
136
+
The `getClarinetVitestsArgv()` will parse options passed to the command `vitest run --`
137
+
- vitest run -- --manifest ./Clarinet.toml # pass a custom path
138
+
- vitest run -- --coverage --costs # collect coverage and cost reports
139
+
*/
127
140
128
141
exportdefaultdefineConfig({
129
142
test: {
130
-
environment:"clarinet", // use vitest-environment-clarinet
143
+
// use vitest-environment-clarinet
144
+
environment: "clarinet",
131
145
pool: "forks",
132
-
poolOptions: {
133
-
threads: { singleThread:true },
134
-
forks: { singleFork:true },
135
-
},
146
+
// clarinet handles test isolation by resetting the simnet between tests
147
+
isolate: false,
148
+
maxWorkers: 1,
136
149
setupFiles: [
137
150
vitestSetupFilePath,
138
151
// custom setup files can be added here
@@ -146,6 +159,7 @@ export default defineConfig({
146
159
},
147
160
});
148
161
```
162
+
{% endcode %}
149
163
150
164
This configuration enables:
151
165
@@ -154,10 +168,58 @@ This configuration enables:
154
168
***Coverage tracking**: Generate reports in multiple formats
155
169
***Custom setup**: Add project-specific test utilities
156
170
171
+
<details>
172
+
173
+
<summary>For Vitest v3 and earlier, use the configuration below.</summary>
174
+
175
+
```typescript
176
+
import { defineConfig } from"vitest/config";
177
+
import {
178
+
vitestSetupFilePath,
179
+
getClarinetVitestsArgv,
180
+
} from"@stacks/clarinet-sdk/vitest";
181
+
182
+
/*
183
+
In this file, Vitest is configured so that it works seamlessly with Clarinet and the Simnet.
184
+
The `vitest-environment-clarinet` will initialise the clarinet-sdk
185
+
and make the `simnet` object available globally in the test files.
186
+
`vitestSetupFilePath` points to a file in the `@hirosystems/clarinet-sdk` package that does two things:
187
+
- run `before` hooks to initialize the simnet and `after` hooks to collect costs and coverage reports.
188
+
- load custom vitest matchers to work with Clarity values (such as `expect(...).toBeUint()`)
189
+
The `getClarinetVitestsArgv()` will parse options passed to the command `vitest run --`
190
+
- vitest run -- --manifest ./Clarinet.toml # pass a custom path
191
+
- vitest run -- --coverage --costs # collect coverage and cost reports
192
+
*/
193
+
194
+
exportdefaultdefineConfig({
195
+
test: {
196
+
// use vitest-environment-clarinet
197
+
environment: "clarinet",
198
+
pool: "forks",
199
+
poolOptions: {
200
+
forks: { singleFork: true },
201
+
},
202
+
setupFiles: [
203
+
vitestSetupFilePath,
204
+
// custom setup files can be added here
205
+
],
206
+
environmentOptions: {
207
+
clarinet: {
208
+
...getClarinetVitestsArgv(),
209
+
// add or override options
210
+
},
211
+
},
212
+
},
213
+
});
214
+
```
215
+
216
+
</details>
217
+
157
218
### TypeScript configuration
158
219
159
220
The **tsconfig.json** provides TypeScript support:
160
221
222
+
{% code expandable="true" %}
161
223
```json
162
224
{
163
225
"compilerOptions": {
@@ -185,6 +247,7 @@ The **tsconfig.json** provides TypeScript support:
185
247
]
186
248
}
187
249
```
250
+
{% endcode %}
188
251
189
252
Properly setting the `include` property ensures TypeScript picks up the helpers defined in the Clarinet SDK package along with your tests.
0 commit comments