使用 jest.run() 或 jest.runCLI() 运行所有测试或以编程方式运行 jest 的方法

2023-12-24

我该如何使用jest.run() or jest.runCLI()以编程方式运行所有测试?我应该用什么作为论据?

我试图找到有关它们的文档但失败了。

如果上述函数不起作用,如果我想以编程方式运行 jest,我应该调用什么?


Jest 不应该以编程方式运行。也许将来会。

尝试运行以下命令:

const jest = require("jest");

const options = {
  projects: [__dirname],
  silent: true,
};

jest
  .runCLI(options, options.projects)
  .then((success) => {
    console.log(success);
  })
  .catch((failure) => {
    console.error(failure);
  });

As success in then回调将传递一个对象,包含globalConfig and results键。看看它们,也许会对您有所帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 jest.run() 或 jest.runCLI() 运行所有测试或以编程方式运行 jest 的方法 的相关文章

随机推荐