@90poe/jest-performant-warnings-stats-reporter 中文文档教程

发布于 3年前 浏览 25 项目主页 更新于 3年前

@90poe/jest-performant-warnings-stats-reporter

这是一个自定义的笑话报告器,它在测试运行时递归地收集所有警告,并在之后通知用户改进性能。

Motivation

我们遇到了问题:

  1. Slow tests run on CI even with silent mode
  2. When running tests locally noise in the terminal slows tests enormously

List of superpowers

  • more performant than default one (check benchmark)
  • can provide statistics on warnings for every test suite (see example)
  • can show slowest tests (see example)

Installation

yarn add @90poe/jest-performant-warnings-stats-reporter --dev

或者

npm install @90poe/jest-performant-warnings-stats-reporter --save-dev

Usage

在您的 jest 配置中添加以下条目:

{
  reporters: [
        [
            '@90poe/jest-performant-warnings-stats-reporter',
            {
                showSlowest: false,
                maxSlowTests: 5,
                warnOnSlowerThan: 1000,
                showWarningSummary: false,
                warningsConfig: [
                    {
                        name: 'act(...) warnings',
                        regex: /act(...)/im,
                    },
                    {
                        name: 'React Key Issues',
                        regex: /Encountered two children with the same key/im,
                    },
                    // ...
                ],
            },
        ],
    ],
}

Configuration

@90poe/jest-performant-warnings-stats-reporter 配置基于 Jest,可用选项如下所示。

Option Description type Default value
showSlowest true / false flag whether to show slowest tests or not boolean false
maxSlowTests quantity of slowest tests to show, dependant on showSlowest flag number 5
warnOnSlowerThan a limit in milliseconds, used to identify slow tests number 400
showWarningSummary true / false flag whether to show detailed information on warnings boolean false
warningsConfig an array of objects with name and regexp props, where name is title for a warning and regexp is regular expression used to match the console warning. Dependant on showWarningSummary flag Array<{ name: string, regexp: RegExp }> []

Sample of output for different configurations

showSlowest: true

Sample of output if showSlowest=true

showWarningSummary: false

Sample of output if showWarningSummary=false

showWarningSummary: true

Sample of output if showWarningSummary=true

Benchmarks

使用 hyperfine 在实际项目中运行 130 个测试套件,我们可以看到与以下相比在性能上的优势:

  • default reporter (up to 20% improvement possible, varies by the number of warnings that exist)
  • default reporter with silent mode on (up to 5% improvement)

default jest reporter

Sample of benchmark for default jest reporter

default jest reporter with silent mode on

Sample of benchmark for default jest reporter with silent mode on

@90poe/jest-performant-warnings-stats-reporter

Sample of benchmark for @90poe/jest-performant-warnings-stats-reporter

Contribution

文档

Code of conduct

文档

Licence

麻省理工学院

@90poe/jest-performant-warnings-stats-reporter

This is a custom jest reporter that recursively collects all warnings while tests run and notifying user afterwards improving performance.

Motivation

We had problems with:

  1. Slow tests run on CI even with silent mode
  2. When running tests locally noise in the terminal slows tests enormously

List of superpowers

  • more performant than default one (check benchmark)
  • can provide statistics on warnings for every test suite (see example)
  • can show slowest tests (see example)

Installation

yarn add @90poe/jest-performant-warnings-stats-reporter --dev

or

npm install @90poe/jest-performant-warnings-stats-reporter --save-dev

Usage

In your jest config add the following entry:

{
  reporters: [
        [
            '@90poe/jest-performant-warnings-stats-reporter',
            {
                showSlowest: false,
                maxSlowTests: 5,
                warnOnSlowerThan: 1000,
                showWarningSummary: false,
                warningsConfig: [
                    {
                        name: 'act(...) warnings',
                        regex: /act(...)/im,
                    },
                    {
                        name: 'React Key Issues',
                        regex: /Encountered two children with the same key/im,
                    },
                    // ...
                ],
            },
        ],
    ],
}

Configuration

@90poe/jest-performant-warnings-stats-reporter configuration is based on Jest, available options are shown below.

Option Description type Default value
showSlowest true / false flag whether to show slowest tests or not boolean false
maxSlowTests quantity of slowest tests to show, dependant on showSlowest flag number 5
warnOnSlowerThan a limit in milliseconds, used to identify slow tests number 400
showWarningSummary true / false flag whether to show detailed information on warnings boolean false
warningsConfig an array of objects with name and regexp props, where name is title for a warning and regexp is regular expression used to match the console warning. Dependant on showWarningSummary flag Array<{ name: string, regexp: RegExp }> []

Sample of output for different configurations

showSlowest: true

Sample of output if showSlowest=true

showWarningSummary: false

Sample of output if showWarningSummary=false

showWarningSummary: true

Sample of output if showWarningSummary=true

Benchmarks

Using hyperfine for running 130 test suites in real world project, we can see advantage in performance comparing with:

  • default reporter (up to 20% improvement possible, varies by the number of warnings that exist)
  • default reporter with silent mode on (up to 5% improvement)

default jest reporter

Sample of benchmark for default jest reporter

default jest reporter with silent mode on

Sample of benchmark for default jest reporter with silent mode on

@90poe/jest-performant-warnings-stats-reporter

Sample of benchmark for @90poe/jest-performant-warnings-stats-reporter

Contribution

Document

Code of conduct

Document

Licence

MIT

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文