无效的测试模式 -- 使用 react-scripts 和 Mono Repo 的 jest.config.js。

11

我试图通过以下方式为react-scripts设置自定义的jest.config:

"test": "react-scripts test -- --config=jest.config.js",

值得一提的是,我有一个单体存储库。

但是这导致了以下错误:

Invalid testPattern --config=jest.config.js|--watch|--config|{"roots":["<rootDir>/src"],"collectCoverageFrom":["src/**/*.{js,jsx,ts,tsx}","!src/**/*.d.ts"],"setupFiles":["/var/www/tractable/property-estimating/node_modules/react-app-polyfill/jsdom.js"],"setupFilesAfterEnv":["<rootDir>/src/setupTests.ts"],"testMatch":["<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}","<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"],"testEnvironment":"jsdom","testRunner":"/var/www/tractable/property-estimating/node_modules/jest-circus/runner.js","transform":{"^.+\\.(js|jsx|mjs|cjs|ts|tsx)$":"/var/www/tractable/property-estimating/node_modules/react-scripts/config/jest/babelTransform.js","^.+\\.css$":"/var/www/tractable/property-estimating/node_modules/react-scripts/config/jest/cssTransform.js","^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)":"/var/www/tractable/property-estimating/node_modules/react-scripts/config/jest/fileTransform.js"},"transformIgnorePatterns":["[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$","^.+\\.module\\.(css|sass|scss)$"],"modulePaths":["/var/www/tractable/property-estimating/frontend/claim-handler/src"],"moduleNameMapper":{"^react-native$":"react-native-web","^.+\\.module\\.(css|sass|scss)$":"identity-obj-proxy"},"moduleFileExtensions":["web.js","js","web.ts","ts","web.tsx","tsx","json","web.jsx","jsx","node"],"watchPlugins":["jest-watch-typeahead/filename","jest-watch-typeahead/testname"],"resetMocks":true,"rootDir":"/var/www/tractable/property-estimating/frontend/claim-handler"}|--env|/var/www/tractable/property-estimating/node_modules/jest-config/node_modules/jest-environment-jsdom/build/index.js supplied. Running all tests instead.

版本

"react-scripts": "4.0.3",
2个回答

4

我也遇到了同样的问题。将脚本替换为以下内容:

"test": "react-scripts test -- --config=jest.config.js",

使用

"test": "jest",

由于react-scripts已经内置了jest,因此不需要显式安装它。


-5
你尝试过:"test": "react-scripts test --config=jest.config.js" 吗?
这可能有效。

这样做是不起作用的,因为它直接传递给jest而不是选项。谢谢您的帮助。 - Jamie Hutber
请提供更多上下文,说明它如何有用,或者任何可能帮助 OP 的链接。 - Gaurav Chauhan
好的。我参考了这个链接:https://create-react-app.dev/docs/running-tests/#disabling-jsdom。在这里,`env` 直接传递而不是使用额外的 -- - Amit Singh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接