Provide integration with VS Code using the node:test runner. Simply install the extension and start running tests, no setup required.*
This extension requires Node.js >=19: node:test is quite new and did not offer features we need in prior versions.
-
The extension looks for files that use the Node.js test runner naming convention. Make sure your files are named correctly!
-
The Node.js test runner only supports running JavaScript files. If you have a compilation step, you'll need to make sure that runs with sourcemaps so we can figure out where tests appear in your source code. For example, for TypeScript, set
"sourceMap": truein your tsconfig.json. -
If tests aren't initially found in your workspace folder, this extension won't keep watching for changes. Manually run the "refresh tests" action if you later add some (or just reload your window.)
Theme: Codesong
-
nodejs-testing.includeis the list of directories in which to look for test files, relative to your workspace folder. Defaults to['./']. -
nodejs-testing.excludeis the list of glob patterns that should be excluded from the search. Defaults to['**/node_modules/**']. -
nodejs-testing.concurrencyis how many test files to run in parallel. Setting it to 0 (default) will use the number of CPU cores - 1. -
nodejs-testing.nodejsPathis the path to the Node.js binary to use for running tests. If unset, will try to find Node on your PATH. -
nodejs-testing.pretestis a command to execute before tests are run. For example["npm", "run", "pretest"]. The working directory for the script is the workspace folder. -
nodejs-testing.debugOptionsis an options object used for debugging, normally found in your launch.json. See documentation here. -
nodejs-testing.extensionsis a list of test extensions to search for, and optional additional Node.js parameters to pass when running those test files. It defaults to[ { "extensions": ["mjs", "cjs", "js"], "parameters": [] } ]...but is useful for configuring loaders for other file types. For example, to run TypeScript tests, you could use
{ "nodejs-testing.extensions": [ { "extensions": ["mjs", "cjs", "js"], "parameters": [] }, { "extensions": ["mts", "cts", "ts"], "parameters": ["--import", "tsx"] } ] }You can also import other helpers by adding parameters like
["--import", "${workspaceFolder}/path/to/file.js"]. See the Node.js command line API for a full list of options.Finally, in addition to an
extensionsoption, you can inspect specify afilePatternoption if you want to name your files differently than the default naming scheme.