从命令行运行测试
可以通过传入 --test
标志从命令行调用 Node.js 测试运行程序:
node --test
默认情况下,Node.js 将递归搜索当前目录以查找匹配特定命名约定的 JavaScript 源文件。 匹配文件作为测试文件执行。 有关预期测试文件命名约定和行为的更多信息可以在测试运行器执行模型章节中找到。
或者,可以提供一个或多个路径作为 Node.js 命令的最终参数,如下所示。
node --test test1.js test2.mjs custom_test_dir/
在本例中,测试运行程序将执行文件 test1.js
和 test2.mjs
。
测试运行器还将递归搜索 custom_test_dir/
目录以查找要执行的测试文件。
The Node.js test runner can be invoked from the command line by passing the
--test
flag:
node --test
By default, Node.js will recursively search the current directory for JavaScript source files matching a specific naming convention. Matching files are executed as test files. More information on the expected test file naming convention and behavior can be found in the test runner execution model section.
Alternatively, one or more paths can be provided as the final argument(s) to the Node.js command, as shown below.
node --test test1.js test2.mjs custom_test_dir/
In this example, the test runner will execute the files test1.js
and
test2.mjs
. The test runner will also recursively search the
custom_test_dir/
directory for test files to execute.