deno test
命令行用法
o test [选项] [文件]... [-- [脚本参数]...]
使用 Deno 内置的测试运行器运行测试。
评估给定的模块,运行所有使用 Deno.test()
声明的测试,并将结果报告到标准输出:
deno test src/fetch_test.ts src/signal_test.ts
目录参数会扩展为所有匹配 glob {*_,*.,}test.{js,mjs,ts,mts,jsx,tsx}
或 **/__tests__/**
的文件:
deno test src/
了解更多: https://docs.deno.com/go/test
不稳定选项 Jump to heading
--unstable
Jump to heading
--unstable
标志已被弃用。请改用细粒度的 --unstable-*
标志.
--unstable-bare-node-builtins
Jump to heading
启用不稳定的裸 Node 内置功能.
--unstable-broadcast-channel
Jump to heading
启用不稳定的 BroadcastChannel
API.
--unstable-cron
Jump to heading
启用不稳定的 Deno.cron API.
--unstable-detect-cjs
Jump to heading
在更多情况下将模棱两可的 .js, .jsx, .ts, .tsx 文件视为 CommonJS 模块.
--unstable-kv
Jump to heading
启用不稳定的键值存储 API.
--unstable-net
Jump to heading
启用不稳定的网络 API.
--unstable-node-globals
Jump to heading
在所有地方暴露 Node 全局变量.
--unstable-sloppy-imports
Jump to heading
启用不稳定的通过扩展探测、.js 到 .ts 以及目录探测来解析模块的功能.
--unstable-temporal
Jump to heading
启用不稳定的 Temporal API.
--unstable-unsafe-proto
Jump to heading
启用不安全的 proto 支持。这是一个安全风险。.
--unstable-worker-options
Jump to heading
启用不稳定的 Web Worker API.
Options Jump to heading
--allow-scripts
Jump to heading
允许运行给定包的 npm 生命周期脚本
注意:只有在使用 node_modules 目录时才会执行脚本(--node-modules-dir
).
--cert
Jump to heading
从 PEM 编码的文件加载证书颁发机构.
--config
Jump to heading
Short flag: -c
配置 deno 的不同方面,包括 TypeScript、代码格式化和代码格式化
通常配置文件会被称为 deno.json
或 deno.jsonc
并自动检测;在这种情况下,此标志不是必需的。
文档:https://docs.deno.com/go/config.
--env-file
Jump to heading
从本地文件加载环境变量 只有第一个具有给定键的环境变量会被使用。 现有的进程环境变量不会被覆盖,因此如果环境中已经存在相同名称的变量,它们的值将被保留。 如果 .env 文件中有多个相同环境变量的声明,则应用第一个遇到的声明。这由您作为参数传递的文件的顺序决定。.
--ext
Jump to heading
设置提供文件的内容类型.
--hide-stacktraces
Jump to heading
隐藏失败测试结果中的错误堆栈跟踪。.
--ignore
Jump to heading
忽略文件.
--location
Jump to heading
某些 web API 使用的 globalThis.location 的值.
--no-config
Jump to heading
禁用自动加载配置文件.
--parallel
Jump to heading
并行运行测试模块。并行度默认为可用 CPU 数量或 DENO_JOBS 环境变量的值.
--seed
Jump to heading
设置随机数生成器的种子.
--unstable-webgpu
Jump to heading
启用不稳定的 WebGPU
API.
--v8-flags
Jump to heading
要查看所有可用标志的列表,请使用 --v8-flags=--help
标志也可以通过 DENO_V8_FLAGS 环境变量设置。
使用此标志设置的任何标志都会附加在 DENO_V8_FLAGS 环境变量之后.
类型检查选项 Jump to heading
--check
Jump to heading
设置类型检查行为。此子命令默认会检查本地模块,因此添加 --check
是多余的
如果提供了 "all" 值,远程模块将被包含。
或者,可以使用 'deno check' 子命令.
--no-check
Jump to heading
跳过类型检查。如果提供了 "remote" 值,远程模块的诊断错误将被忽略.
依赖管理选项 Jump to heading
--cached-only
Jump to heading
要求远程依赖已经缓存.
--frozen
Jump to heading
如果锁文件过期则报错.
--import-map
Jump to heading
从本地文件或远程 URL 加载导入映射文件 文档:https://docs.deno.com/runtime/manual/basics/import_maps.
--lock
Jump to heading
检查指定的锁文件。(如果未提供值,默认为 "./deno.lock").
--no-lock
Jump to heading
禁用自动发现锁文件.
--no-npm
Jump to heading
不解析 npm 模块.
--no-remote
Jump to heading
不解析远程模块.
--node-modules-dir
Jump to heading
设置 npm 包的 node 模块管理模式.
--reload
Jump to heading
Short flag: -r
重新加载源代码缓存(重新编译 TypeScript) 无值 重新加载所有内容 jsr:@std/http/file-server,jsr:@std/assert/assert-equals 重新加载特定模块 npm: 重新加载所有 npm 模块 npm:chalk 重新加载特定 npm 模块.
--vendor
Jump to heading
切换本地 vendor 文件夹用于远程模块和 node_modules 文件夹用于 npm 包.
调试选项 Jump to heading
--inspect
Jump to heading
在 host:port 上激活检查器 [默认:127.0.0.1:9229]
--inspect-brk
Jump to heading
在 host:port 上激活检查器,等待调试器连接并在用户脚本开始时中断.
--inspect-wait
Jump to heading
在 host:port 上激活检查器并等待调试器连接后再运行用户代码.
测试选项 Jump to heading
--clean
Jump to heading
在运行测试之前清空临时覆盖率配置文件数据目录。
注意:对同一覆盖率目录连续或并行运行多个 deno test
--clean`` 调用可能会导致竞争条件。.
--coverage
Jump to heading
将覆盖率配置文件数据收集到 DIR 中。如果未指定 DIR,则使用 'coverage/'.
--doc
Jump to heading
评估 JSDoc 和 Markdown 中的代码块.
--fail-fast
Jump to heading
在 N 次错误后停止。默认在第一次失败后停止.
--filter
Jump to heading
运行测试名称中包含此字符串或正则表达式模式的测试.
--junit-path
Jump to heading
将 JUnit XML 测试报告写入 PATH。使用 '-' 写入 stdout,这是未提供 PATH 时的默认行为.
--no-run
Jump to heading
缓存测试模块,但不运行测试.
--permit-no-files
Jump to heading
如果未找到测试文件,则不返回错误代码.
--reporter
Jump to heading
选择要使用的报告器。默认为 'pretty'.
--shuffle
Jump to heading
随机化测试运行的顺序.
--trace-leaks
Jump to heading
启用泄漏跟踪。在调试测试中的泄漏操作时很有用,但会影响测试执行时间.
文件监视选项 Jump to heading
--no-clear-screen
Jump to heading
在监视模式下不清除终端屏幕.
--watch
Jump to heading
监视文件更改并自动重启进程。 默认情况下,会监视入口点模块图中的本地文件。 可以通过将此标志的参数传递给此标志来监视其他路径。.
--watch-exclude
Jump to heading
从监视模式中排除提供的文件/模式.
附加信息 Jump to heading
它可以在监视模式下执行(--watch
),支持并行执行(--parallel
),并且可以配置为以随机顺序运行测试(--shuffle
)。此外,还内置了对代码覆盖率(--coverage
)和内存泄漏检测(--trace-leaks
)的支持。
示例 Jump to heading
运行测试
deno test
运行特定文件中的测试
deno test src/fetch_test.ts src/signal_test.ts
运行匹配 glob 模式的测试
deno test src/*.test.ts
运行测试并跳过类型检查
deno test --no-check
运行测试,并在文件更改时重新运行
deno test --watch