Vitest is used to ensure that code is working as expected. Ideally, all packages should have 100% test coverage.
Please follow the MetaMask unit testing guidelines when writing tests.
Vitest does not add describe, it, and expect as globals, so import them from vitest in each test file:
import { describe, expect, it } from 'vitest';Every package shares the configuration in vitest.config.packages.ts at the root. If you need to customize the behavior of Vitest for a package, see vitest.config.ts within that package. It is also where the package sets its coverage thresholds.
- Run
yarn workspace <workspaceName> run testto run all tests for a package. - Run
yarn workspace <workspaceName> run test <file>to run a single test file within the context of a package. - Run
yarn workspace <workspaceName> run test:watchto re-run tests as you change files. - Run
yarn testto run tests for all packages, plus the tests for the scripts inscripts/.
Note
workspaceNamein these commands is thenamefield within a package'spackage.json, e.g.,@metamask/greetings, not the directory where it is located, e.g.,packages/greetings.