| Level Navigation: 1 | (2ℹ️) | 3 | 4 | 5 | 6 | (7ℹ️) | (8ℹ️) | (9ℹ️) | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | (37ℹ️) | 38⚡ | 39⚡ | 40⚡ | 41⚡ | 42 | 43⚡ | 44⚡ | 45 | 46 | (47ℹ️) |
First, initialize your npm project and install Vitest:
npm init -y
npm install --save-dev vitest
Then, update your package.json to add the test script and set the module type:
{
"type": "module",
"scripts": {
"test": "vitest"
}
}
When you run npm init -y, it creates a basic package.json (see [npm](/codex-lv3-may-2025/VOCABULARY_LIST.html#npm) for more on npm commands). After adding the type and scripts fields, your complete package.json might look like this:
{
"name": "function-practice",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "vitest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"vitest": "^1.0.0"
}
}
Key points:
"type": "module" field enables ES6 module syntax (import/export)"scripts" section includes your test commandvitest appears in devDependencies after installationnpm init -yNow run the test command to verify Vitest is set up correctly (it will show no tests found, which is expected):
npm run test
package.json so tooling like Vitest is only installed for development, keeping production bundles lean."type": "module" unlocks ES module syntax. See the type: “module” entry for a refresher on why modern bundlers like Vite expect ESM by default.npm run test executes the script you defined. Review npm scripts to see how custom commands plug into your workflow.Press q to quit the test runner when you’re done checking.