首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于TS的Jest测试

基于TS的Jest测试
EN

Stack Overflow用户
提问于 2022-01-19 13:52:55
回答 1查看 1.1K关注 0票数 6

我有一个基于类型记录的React项目,在这个项目中,我正在运行开玩笑的测试(也是在TS中)。我可以很好地运行测试,但我试图分析一些需要相当长时间运行的测试的性能。我试过使用用于测试的Chrome Devtools,但是它失败了,因为它是TS而不是普通的Js。是否有任何方法可以单独分析我的测试,以查看性能问题在哪里发生?使用VS代码。

EN

回答 1

Stack Overflow用户

发布于 2022-11-17 17:49:49

对于我来说,这不是一个React项目,它只是一个常规的TypeScript库,但我敢打赌,这也适用于您的用例。我要把这个留在这里,如果它是有用的,或者是为了将来的我。

我发现唯一有效的解决方案是手动设置分析器V8-分析器-下一个

代码语言:javascript
复制
import v8Profiler from 'v8-profiler-next';
v8Profiler.setGenerateType(1);
const title = 'good-name';

describe('Should be able to generate with inputs', () => {
  v8Profiler.startProfiling(title, true);
  afterAll(() => {
    const profile = v8Profiler.stopProfiling(title);
    profile.export(function (error, result: any) {
      // if it doesn't have the extension .cpuprofile then
      // chrome's profiler tool won't like it.
      // examine the profile:
      //   Navigate to chrome://inspect
      //   Click Open dedicated DevTools for Node
      //   Select the profiler tab
      //   Load your file
      fs.writeFileSync(`${title}.cpuprofile`, result);
      profile.delete();
    });
  });
  test('....', async () => {
    // Add test
  });
});

这将为您提供这样的CPU配置文件,它可以很好地用于TypeScript。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70771838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档