跳至主要内容

Jest

craco.config.js
module.exports = {
// ...
jest: {
babel: {
addPresets: true /* (default value) */,
addPlugins: true /* (default value) */,
},
configure: { /* ... */ },
configure: (jestConfig, { env, paths, resolve, rootDir }) => {
/* ... */
return jestConfig;
},
},
};
提示

上述大纲中两次列出的属性(例如 configure)可以被分配一个对象字面量或一个函数。有关详细信息,请参阅 配置提示

jest.babel

babel-jest 转换器的配置选项:https://jest.node.org.cn/docs/code-transformation

jest.babel.addPresets

boolean = true

是否应该添加 Babel 预设。

jest.babel.addPlugins

boolean = true

是否应该添加 Babel 插件。

jest.configure

JestConfig(config: JestConfig, { env, paths, resolve, rootDir }) => JestConfig

任何 Jest 配置选项:https://jest.node.org.cn/docs/configuration

configure 的函数版本在 上下文对象 中提供了两个额外属性

  • resolve - 由 CRA 提供
  • rootDir - 由 CRA 提供