V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
yazoox

使用 jest 跑的 unit test,运行测试文件,花了 10s,怎么分析一下性能问题?

  •  
  •   yazoox · Aug 4, 2020 · 1946 views
    This topic created in 2095 days ago, the information mentioned may be changed or developed.

    typescript

    unit test 是用 jest 写的。

    很多测试文件,但有一部分测试文件,跑的时候,jest 显示“红色”10s 。

    这个应该是指明该测试文件有性能问题。unit test 跑的时间太长了。

    可是,如果我单独跑这个测试文件,大概 5s 左右,每一个小的 case 都是 10ms 以内 /左右。并看不出来哪个 test 有性能问题呢。

    node ".\node_modules\jest\bin\jest.js" ".\\xxx\\myname-test.ts"
    

    那,到底是哪里出了问题?怎么分析呢?

    谢谢!

    3 replies    2020-08-10 11:09:34 +08:00
    zhuweiyou
        1
    zhuweiyou  
       Aug 4, 2020
    把默认超时时间调大点就行了
    yazoox
        2
    yazoox  
    OP
       Aug 10, 2020
    @zhuweiyou 兄弟,没太看懂你的意思。
    这个,调节默认超时,为什么可以提高 unit test perf ?是因为 retry 减少了?
    另,这个“默认”在哪里调节?貌似只看到设置 describe/it 的 timeout,没有全局 jest 的这方面设置呢......
    谢谢。
    yazoox
        3
    yazoox  
    OP
       Aug 10, 2020
    @zhuweiyou
    https://jestjs.io/docs/en/configuration#testtimeout-number
    找到设置了。是这个么?我去试试。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   836 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 21:12 · PVG 05:12 · LAX 14:12 · JFK 17:12
    ♥ Do have faith in what you're doing.