···38383939The `npx` command will execute the command either from a local `node_modules/.bin` installing any packages needed in order for the command to run. By default, npx will check whether command exists in $PATH, or in the local project binaries, and execute that. If command is not found, it will be installed prior to execution.
40404141+## Writing Tests
4242+4343+As an example, we will write a simple test that verifies the output of a function that adds two numbers.
4444+4545+``` js
4646+// sum.js
4747+export function sum(a, b) {
4848+ return a + b
4949+}
5050+```
5151+5252+``` js
5353+// sum.test.js
5454+import { expect, test } from 'vitest'
5555+import { sum } from './sum'
5656+5757+test('adds 1 + 2 to equal 3', () => {
5858+ expect(sum(1, 2)).toBe(3)
5959+})
6060+```
6161+6262+Next, in order to execute the test, add the following section to your `package.json`:
6363+6464+```json
6565+{
6666+ "scripts": {
6767+ "test": "vitest"
6868+ }
6969+}
7070+```
7171+7272+Finally, run `npm run test`, `yarn test`, or `pnpm test`, depending on your package manager, and Vitest will print this message:
7373+7474+```log
7575+✓ sum.test.js (1)
7676+ ✓ adds 1 + 2 to equal 3
7777+7878+Test Files 1 passed (1)
7979+ Tests 1 passed (1)
8080+ Start at 02:15:44
8181+ Duration 311ms (transform 23ms, setup 0ms, collect 16ms, tests 2ms, environment 0ms, prepare 106ms)
8282+```
8383+8484+Learn more about the usage of Vitest, see the [API](https://vitest.dev/api/) section.
8585+4186## Configuring Vitest
42874388One of the main advantages of Vitest is its unified configuration with Vite. If present, `vitest` will read your root `vite.config.ts` to match with the plugins and setup as your Vite app. For example, your Vite [resolve.alias](https://vitejs.dev/config/shared-options.html#resolve-alias) and [plugins](https://vitejs.dev/guide/using-plugins.html) configuration will work out-of-the-box. If you want a different configuration during testing, you can: