【问题标题】:Hide compile warnings during test runs在测试运行期间隐藏编译警告
【发布时间】:2019-08-28 21:02:51
【问题描述】:

我们正在 vscode 中构建一个 react 应用,使用 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 中有我们可能要考虑更新的包,但我不需要在每次测试运行时都看到它们。

而且他们很难看到测试的实际结果。

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

【问题讨论】:

    标签: reactjs visual-studio-code jestjs


    【解决方案1】:

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

    --静默

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 2012-11-20
      相关资源
      最近更新 更多