测试运行器执行模型
¥Test runner execution model
当启用进程级测试隔离时,每个匹配的测试文件都会在单独的子进程中执行。任何时候运行的子进程的最大数量由 --test-concurrency
标志控制。如果子进程以退出代码 0 结束,则认为测试通过。否则,认为测试失败。测试文件必须是 Node.js 可执行文件,但不需要在内部使用 node:test
模块。
¥When process-level test isolation is enabled, each matching test file is
executed in a separate child process. The maximum number of child processes
running at any time is controlled by the --test-concurrency
flag. If the
child process finishes with an exit code of 0, the test is considered passing.
Otherwise, the test is considered to be a failure. Test files must be executable
by Node.js, but are not required to use the node:test
module internally.
每个测试文件都像常规脚本一样执行。也就是说,如果测试文件本身使用 node:test
来定义测试,则所有这些测试都将在单个应用线程中执行,而不管 test()
的 concurrency
选项的值如何。
¥Each test file is executed as if it was a regular script. That is, if the test
file itself uses node:test
to define tests, all of those tests will be
executed within a single application thread, regardless of the value of the
concurrency
option of test()
.
当禁用进程级测试隔离时,每个匹配的测试文件都会导入到测试运行器进程中。加载所有测试文件后,将以并发数 1 执行顶层测试。由于测试文件都在同一个上下文中运行,因此测试可以以启用隔离时不可能的方式相互交互。例如,如果测试依赖于全局状态,则该状态可能会被源自另一个文件的测试修改。
¥When process-level test isolation is disabled, each matching test file is imported into the test runner process. Once all test files have been loaded, the top level tests are executed with a concurrency of one. Because the test files are all run within the same context, it is possible for tests to interact with each other in ways that are not possible when isolation is enabled. For example, if a test relies on global state, it is possible for that state to be modified by a test originating from another file.