从命令行运行测试
【Running tests from the command line】
可以通过在命令行传递 --test 标志来调用 Node.js 测试运行器:
【The Node.js test runner can be invoked from the command line by passing the
--test flag:】
node --test 默认情况下,Node.js 会递归搜索当前目录中符合特定命名约定的 JavaScript 源文件。匹配的文件会作为测试文件执行。有关预期测试文件命名约定和行为的更多信息,可以参见 测试运行器执行模型 部分。
【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.】
或者,可以将一个或多个路径作为 Node.js 命令的最终参数提供,如下所示。
【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/ 在这个例子中,测试运行器将执行文件 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.】