一个文件中的测试是否在 Jest 中并行运行? [英] Are tests inside one file run in parallel in Jest?
问题描述
文档中的 Jest 状态:Jest 虚拟化 JavaScript 环境并在工作进程中并行运行测试."
Jest states in docs: "Jest virtualizes JavaScript environments and runs tests in parallel across worker processes."
但是对于一个文件中的多个测试,它们是并行运行还是仅适用于测试文件呢?我可以假设一个文件中的测试按出现顺序和串行运行吗?
But what about multiple tests inside one file, do they run in parallel or this statement applies just to the test files? Can I assume that tests in one file run in order of appearance and in serial?
推荐答案
是的,您可以放心地假设单个文件中的测试将按出现的顺序运行.您可以通过在每个 it
块中放置一个 console.log
来证明这一点.
Yes, you can safely assume tests inside a single file will run in the order of appearance. You could prove this by putting a console.log
in each it
block.
可能值得一提的是,依赖执行顺序/外部状态通常是不好的做法……而且您永远不会知道,Jest(或当前的底层测试运行程序 Jasmine)可能会决定以随机顺序运行它们在较新的版本中.
It's probably worth mentioning that it's generally bad practice to rely on the order of execution / external state...and you never know, Jest (or the current underlying test runner, Jasmine) may decide to run them in a random order in a newer version.
这篇关于一个文件中的测试是否在 Jest 中并行运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!