使用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.
如果上述功能不起作用,如果我要以编程方式运行玩笑,我应该怎么称呼?
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屋!