Please note that the settings described on this page should only be used with Jest v23 and below.
Starting from Jest v24, no configuration is required to start using Wallaby. If you are using a previous version then we recommend updating your Jest package version and referring to our current jest docs.
Wallaby.js supports the Facebook Jest testing framework.
module.exports = function () {
return {
files: ['src/**/*.js', '!src/**/__tests__/*.js'],
tests: ['src/**/__tests__/*.js'],
env: {
type: 'node'
},
testFramework: 'jest'
};
};
You may find the working sample of wallaby.js configuration for Jest in this repository.
Please note that wallaby.js is using its own cache to run your tests from, not the local project folder. You should include all files (except node modules) that your tests need, for example __mocks__/*.*
, etc.
Jest configuration
If Jest in your project is configured using a package.json
or jest.config.js
/jest.config.json
file, then wallaby will automatically load the configuration. If you would like to adjust the configuration, you may use the setup
function, and pass require('./package.json').jest
(or require('./jest.config')
) to the wallaby.testFramework.configure
function. Don’t forget to include package.json
/jest.config.js
/jest.config.json
in your files
list in this case.
module.exports = function () {
return {
files: [
'src/**/*.js',
'package.json', // <--
'!src/**/__tests__/*.js'
],
tests: ['src/**/__tests__/*.js'],
env: {
type: 'node'
},
testFramework: 'jest',
setup: function (wallaby) {
var jestConfig = require('./package.json').jest;
/* for example:
* jestConfig.globals = { "__DEV__": true }; */
wallaby.testFramework.configure(jestConfig);
}
};
};
If you have some other Jest config, or would like to override some configuration values, you may pass any config object to the configure
function of the test framework in wallaby setup
function.
Babel
If you are using Babel compilation in your project, you need to add Babel compiler to your config:
module.exports = function (wallaby) {
return {
...
testFramework: 'jest',
compilers: {
'**/*.js': wallaby.compilers.babel()
}
};
};
TypeScript
TypeScript Jest configuration (ts-jest
modules to be more specific) requires the access to the tsconfig.json
file, so if you are using Jest with TypeScript, you’ll need to add the file to your files
list:
module.exports = function () {
return {
files: [
'tsconfig.json', // <--
'src/**/*.ts',
'!src/**/__tests__/*.ts'
],
tests: ['src/**/__tests__/*.ts'],
env: {
type: 'node'
},
testFramework: 'jest'
};
};
Jest with TypeScript and jest.mock
calls
If you are using TypeScript with Jest and your tests are making jest.mock
calls, then you will need to run Babel (babel-preset-jest
) transformation on top of TypeScript compilation (just like ts-jest
is doing) to hoist the calls:
module.exports = function (w) {
return {
files: [
...
],
tests: [
...
],
...
preprocessors: {
'**/*.js?(x)': file => require('@babel/core').transform(
file.content,
{sourceMap: true, filename: file.path, presets: [require('babel-preset-jest')]})
}
};
};
create-react-app
You may find the full config for create-react-app
generated app in this docs section.
You may find the full config for create-react-app --typescript
generated app in this sample repository.
Watchman
If you want to stop Jest to use watchman
when running from Wallaby, you may use the process.env.NO_WATCHMAN
setting.
module.exports = function () {
process.env.NO_WATCHMAN = true;
return {
...
};
};
Troubleshooting
If you have problems using an older version of Jest (v23 and below), first try upgrading your Jest version to v24+ and using Wallaby’s Automatic Configuration.
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.