Skip to content

node:test

Wallaby’s integration with node:test requires node v22.3.0 or higher.

Starting Wallaby on a project using node:test

To start Wallaby in VS Code you may run Select Configuration command and then select Automatic Configuration <project directory> option once. After that you may keep using Wallaby Start command as usual and it will start Wallaby with automatic configuration.

To start Wallaby in Sublime Text you may use the Select for Wallaby.js Automatic Configuration context menu item for your project folder in the project’s file tree. After that you may keep using Wallaby Start command as usual and it will start Wallaby with automatic configuration.

To start Wallaby in Visual Studio, you may use the Start Wallaby.js (Automatic Configuration) context menu item for your project folder in the Solution Explorer. After the first start, the selected project will be remembered for your solution and Wallaby can be started with Tools->Start Wallaby.js (Alt-W, 1).

To start Wallaby in JetBrains IDEs, you may edit (or create a new) wallaby.js Run Configuration by selecting Edit configurations from the drop-down menu in the top right-hand corner of the navigation bar, or from the Run menu. In the run configuration editor set Configuration Type filed value to Automatic.

Configuration Defaults

Wallaby will attempt to automatically detect and configure your project if it uses node:test; for most projects, you will not need to provide any additional configuration or create a configuration file.

Default File and Test Patterns

Wallaby provides default settings for files and tests and requires that at least one test file imports node:test to detect and configure your project. The default settings are shown below:

module.exports = () => ({
autoDetect: ['node:test'],
// Defaults source file patterns
files: [
// Excludes
'!**/node_modules/**',
'!**/dist/**',
'!**/cypress/**',
'!**/.{idea,git,cache,output,temp}/**',
'!**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*'
'!**/*.{test,spec}.?(c|m)[jt]s?(x)',
// Include all other files
'**/**',
],
// Default test file name pattern
tests: [
'**/*.{test,spec}.?(c|m)[jt]s?(x)',
]
});

TypeScript Compilers

If you are using TypeScript, Wallaby will automatically detect and configure your TypeScript compiler settings. Wallaby provides built-in support for TypeScript and will attempt to resolve the TypeScript compiler based on your project dependencies in the following order:

  1. @swc-node/register
  2. ts-node
  3. tsx
  4. esbuild-register (does not support ESM projects)

If you have one of the above TypeScript compilers installed in your project, there is no need to do anything else. If you do not have one of the above TypeScript compilers installed, you will need to install one of them in your project.

Wallaby’s TypeScript compiler resolution is set automatically using Wallaby’s esmHooks and preloadModules settings. You may override these settings in your Wallaby configuration file if you need to use a different TypeScript compiler, or if you need to configure another esm hook or preload module.

module.exports = () => ({
autoDetect: ['node:test'],
// Default override esm hooks settings if not specified
esmHooks: [
'@swc-node/register/esm-register',
'ts-node/esm',
'tsx/esm',
],
// Default preload modules settings if not specified
preloadModules: [
'@swc-node/register',
'ts-node/register',
'tsx/cjs',
'esbuild-register',
]
});

Limiting Automatic Configuration to node:test

If your project uses multiple testing frameworks supported by Wallaby’s automatic configuration, they will be resolved first and node:test will be ignored. To explicitly specify for Wallaby to only try to use node:test, you must set the autoDetect setting by providing and using a Wallaby configuration file:

module.exports = () => ({
autoDetect: ['node:test']
});

Overriding Automatic Configuration

Sometimes you may want to add/override some Wallaby configuration settings to the automatically detected settings. For example, if you want to exclude some tests when you are using Wallaby but not when you are running tests from the command-line or Continuous Integration build. You may configure an override in a configuration file or package.json section.

After creating Wallaby config file to override automatic defaults in VS Code you need to run Select Configuration command and then select the config file once. After that you may keep using Wallaby Start command as usual and it will start Wallaby with the configuration file.

After creating Wallaby config file to override automatic defaults in JetBrains IDEs, you may edit (or create a new) wallaby.js Run Configuration by selecting Edit configurations from the drop-down menu in the top right-hand corner of the navigation bar, or from the Run menu. In the run configuration editor set Configuration Type filed value to Configuration File.

Note that if you are adding/overriding files/tests, then you need to add the autoDetect: true setting:

module.exports = () => ({
autoDetect: true, // or autoDetect: ['node:test']
// modify `files` automatic configuration settings
files: {
override: (filePatterns) => {
// TODO: modify `filePatterns` array as required
return filePatterns;
}
},
// modify `tests` automatic configuration settings
tests: {
override: (testPatterns) => {
// TODO: modify `testPatterns` array as required
return testPatterns;
}
}
});

Troubleshooting

The first step of troubleshooting your project is to identify whether the same results are returned using node --test ... from the command-line. Running node --test ... from the command-line will usually show/highlight the cause of your problem.

If Wallaby is not working but node --test ... CLI is working, please report this to the Wallaby team.

If you get stuck or something isn’t working for you, you may find further troubleshooting steps here or else find a similar solved issue in our github issues repository. If you can’t find a solution, create a new issue.