【发布时间】:2022-01-01 07:14:19
【问题描述】:
我收到此错误消息:
Make sure to close all open resource handles returned from Deno APIs before
finishing test case.
当我运行这个 Deno 测试函数时:
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
Deno.test("fetch example", async function (): Promise<void> {
await fetch("http://www.google.com.br").then(data => {
console.log('completed')
});
assertEquals("world", "world");
});
我用来运行它的命令是:
deno test --allow-net
我查看了documentation,但找不到解决方法。
这是完整的错误堆栈:
$ deno test --allow-net
Compile file:///<my_path>/isolated_test.ts
running 1 tests
test fetch example ... completed
FAILED (199ms)
failures:
fetch example
AssertionError: Test case is leaking resources.
Before: {
"0": "stdin",
"1": "stdout",
"2": "stderr"
}
After: {
"0": "stdin",
"1": "stdout",
"2": "stderr",
"3": "httpBody"
}
Make sure to close all open resource handles returned from Deno APIs before
finishing test case.
at Object.assert ($deno$/util.ts:33:11)
at Object.resourceSanitizer [as fn] ($deno$/testing.ts:81:5)
at async TestApi.[Symbol.asyncIterator] ($deno$/testing.ts:264:11)
at async Object.runTests ($deno$/testing.ts:346:20)
failures:
fetch example
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out (199ms)
我的 deno 版本
$ deno --version
deno 1.0.2
v8 8.4.300
typescript 3.9.2
【问题讨论】:
-
更新了我的答案。一旦
fetch支持AbortController,您就可以添加超时以自动关闭正文 -
很好,我会尽量记住这一点
标签: deno