Skip to content

Commit 0d65b30

Browse files
mdjastrzebskiclaude
andcommitted
docs: complete runner and typescript setup in readme
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 027e3ee commit 0d65b30

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ Vitest, Bun test and Jest are all supported. Add the setup entry for your runner
1919
**Vitest** (`vitest.config.ts`):
2020

2121
```ts
22+
import { defineConfig } from 'vitest/config'
23+
2224
export default defineConfig({
2325
test: {
26+
// Lets tests use `test` and `expect` without importing them.
27+
globals: true,
2428
setupFiles: ['nitro-ui-testing-library/vitest-setup'],
29+
// NitroUI packages ship TypeScript sources, so compile them too.
2530
server: { deps: { inline: [/nitro-ui-/] } },
2631
},
2732
})
@@ -47,6 +52,40 @@ module.exports = {
4752
}
4853
```
4954

55+
Jest compiles TypeScript and JSX with Babel:
56+
57+
```sh
58+
bun add --dev jest babel-jest @babel/core @babel/preset-env @babel/preset-typescript @babel/preset-react @babel/plugin-syntax-decorators
59+
```
60+
61+
```js
62+
// babel.config.cjs
63+
module.exports = {
64+
presets: [
65+
['@babel/preset-env', { targets: { node: 'current' } }],
66+
'@babel/preset-typescript',
67+
['@babel/preset-react', { runtime: 'automatic' }],
68+
],
69+
// NitroUI's native module specs use decorators.
70+
plugins: [['@babel/plugin-syntax-decorators', { version: '2023-11' }]],
71+
}
72+
```
73+
74+
**TypeScript**: the NitroUI template's `tsconfig.json` loads no global types, so add your runner's test types. On Vitest and Bun, also add the setup entry, which adds the matcher types (on Jest, importing the library adds them):
75+
76+
```jsonc
77+
{
78+
"extends": "nitro-ui-cli/tsconfig.json",
79+
"compilerOptions": {
80+
// Jest: ["jest"] (with @types/jest)
81+
// Vitest: ["vitest/globals", "nitro-ui-testing-library/vitest-setup"]
82+
// Bun: ["bun", "bun-types/test-globals", "nitro-ui-testing-library/bun-setup"] (with @types/bun)
83+
"types": ["vitest/globals", "nitro-ui-testing-library/vitest-setup"],
84+
},
85+
"include": ["src"],
86+
}
87+
```
88+
5089
See [`examples/basic`](examples/basic) for a complete NitroUI app tested on all three runners.
5190

5291
## ✨ Example

0 commit comments

Comments
 (0)