Add Vitest
Here's how we added Vitest to Kitbook written here for maintenance reference.
pnpm -F kitbook add -D vitest- turn on
globalsoption and In-source testing by creating avitest.config.tsfile:
vitest.config.tstsimport {defineConfig } from 'vitest/config'export defaultdefineConfig ({test : {globals : true,includeSource : ['src/**/*.ts'],},})
- Acquaint Typescript:
tsconfig.jsonjson{"compilerOptions": {"types": ["vitest/globals","vitest/importMeta"]}}
- Add an inline test
tsif (import.meta.vitest) {test('capitalize turns bar into Bar', () => {expect(capitalize('bar')).toMatchInlineSnapshot('"Bar"')})}
- For a REPL like experience turn on VSCode autosave and run Vitest in update mode with the
-uflag to have the inline snapshot update as you type.