deno - 使用橡木进行 deno 测试仅检查一个文件
问题描述
问题:测试检测到所有测试文件,但只运行一个文件。
环境
deno 1.12.2 (release, aarch64-apple-darwin)
v8 9.2.230.14
typescript 4.3.5
---
export {
assert,
assertEquals,
} from "https://deno.land/std@0.100.0/testing/asserts.ts";
export {
Application,
Router,
composeMiddleware,
testing,
} from "https://deno.land/x/oak@v7.7.0/mod.ts";
export type {
Context,
Middleware,
State,
} from "https://deno.land/x/oak@v7.7.0/mod.ts";
代码
脚本与官方文档中的脚本相同
import { testing, Middleware, assert, assertEquals } from "/deps.ts";
const mw: Middleware = async (ctx, next) => {
await next();
if (ctx.request.url.pathname === "/a") {
ctx.response.body = "Hello a";
ctx.response.headers.set("x-hello-a", "hello");
}
};
Deno.test({
name: "example test",
async fn() {
const ctx = testing.createMockContext({
path: "/a",
});
const next = testing.createMockNext();
await mw(ctx, next);
assertEquals(ctx.response.body, "Hello a");
assert(ctx.response.headers.has("x-hello-a"));
},
});
脚本
deno 测试 --allow-all --importmap importmap.json --unstable 测试*
文件
- 测试1.test.ts
- test2.test.ts 两个文件具有相同的内容但名称不同。
输出
Check file:///Users/dd/dd/dd/test1.test.ts
Check file:///Users/dd/dd/dd/test2.test.ts
running 1 test from file:///Users/ekwon/dev/search-api/test1.test.ts
test example test ... ok (8ms)
如果我在下面运行代码,则测试会运行这两个文件。因此,我认为 testing.createMockContext、testing.createMockNext、assertEquals 正在制造问题。当我删除它们时,测试会检查这两个文件。
import { delay } from "https://deno.land/std@0.104.0/async/delay.ts";
Deno.test("async hello world", async () => {
const x = 1 + 2;
// await some async task
await delay(100);
if (x !== 3) {
throw Error("x should be equal to 3");
}
});
任何关于这个问题的想法将不胜感激
解决方案
推荐阅读
- javascript - 标记geojson地图的特征:如何控制标签的位置
- r-markdown - Rmarkdown投影仪幻灯片不显示项目符号
- xml - 从 OLE 对象数据中导出 .docx
- c - 函数被重新声明
- googletest - Google Mock,期望在 2 个给定数字之间通话
- angular - 如何在Angular ng类中放置if包含条件
- javascript - 如何在 JavaScript / HTML / CSS 中处理带有跨度的关键字框
- curl - 将文件内容发布到 slackbot
- ios - 不在 LineChart iOS Swift 中从零开始 xAxis
- django - 生成随机字符串(用于唯一代码)不断返回相同的随机字符串