使用 jest.run() 或 jest.runCLI() 运行所有测试或以编程方式运行 jest 的方法 [英] Use jest.run() or jest.runCLI() to run all tests or ways to run jest programmatically
问题描述
我如何使用 jest.run()
或 jest.runCLI()
以编程方式运行所有测试?我应该用什么作为论证?
How do I use jest.run()
or jest.runCLI()
to run all tests programmatically? What am I suppose to feed as an argument?
我试图找到有关它们的文档,但失败了.
I tried to find documentation regarding them but fail.
如果上述函数不起作用,如果我想以编程方式运行 jest 应该调用什么?
And if the above functions don't work, what am I supposed to call if I want to run jest programmatically?
推荐答案
Jest 不应该以编程方式运行.也许将来会.
Jest is not supposed to be run programmatically. Maybe it will in the future.
尝试运行以下命令:
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);
});
作为 then
回调中的 success
一个对象将被传递,包含 globalConfig
和 results
键.看看他们,也许对你有帮助.
As success
in then
callback an object will be passed, containing globalConfig
and results
keys. Have a look on them, maybe it will help you.
这篇关于使用 jest.run() 或 jest.runCLI() 运行所有测试或以编程方式运行 jest 的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!