在测试运行期间隐藏编译警告



我们正在用vscode构建一个反应应用程序,使用jest来运行单元测试。

当我们运行测试时,我们看到node_modules文件中文件的编译器警告。

PASS  src/components/Common/IonicWrappers/__tests__/KorSelect.test.tsx
PASS  src/components/Common/IonicWrappers/__tests__/KorHeader.test.tsx
● Console
console.warn node_modules/react-dom/cjs/react-dom.development.js:11494
Warning: componentWillReceiveProps has been renamed, and is not recommended for use.

我们使用npm test运行我们的测试,其中 package,json 包含:

"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test-react": "react-scripts test --transformIgnorePatterns "node_modules/(?!(@ionic|ionicons|capacitor-data-storage-sqlite))"",
"test": "npm run test-react",
[...]
},

.vscode/settings.json 是:

{
"jest.pathToJest": "--runInBand --no-cache --watchAll=false --transformIgnorePatterns='node_modules/(?!(@ionic|ionicons|capacitor-data-storage-sqlite))'",
"jest.runAllTestsFirst": false,
"jest.enableInlineErrorMessages": false,
"jest.pathToConfig": "./node_modules/.bin/react-scripts",
"jestrunner.jestCommand": "npm test --runInBand --no-cache --watchAll=false --transformIgnorePatterns='node_modules/(?!(@ionic|ionicons|capacitor-data-storage-sqlite))'"
}

现在这些警告很有价值,我们确实需要知道node_modules中有一些我们可能需要考虑更新的包,但我不需要在每次测试运行时都看到它们。

而且它们使得很难看到测试的实际结果。

有没有办法配置东西来抑制它们?

> https://jestjs.io/docs/en/cli#silent

--沉默

阻止测试通过控制台打印消息。

最新更新