如何根据文件名过滤DENO测试?

发布于 2025-01-27 03:15:39 字数 463 浏览 4 评论 0原文

如何根据文件名过滤DENO测试?

例如,我有以下文件:

number_1_test.ts
number_2_test.ts
string_test.ts

我想运行number*测试,

我无法使用以下命令:

deno test number*

也不:

deno test --filter number*

我应该怎么做?

DENO测试用法:

DENO TEST [option] [files] ... [ - < script_arg> ...]

- filter< filter>:使用此字符串或此字符串运行测试测试名称中的模式

How to filter Deno tests based on filename?

For example, I have the following files:

number_1_test.ts
number_2_test.ts
string_test.ts

I want to run number* tests,

I can't use the following command:

deno test number*

nor:

deno test --filter number*

What should I do?

Deno test usage:

deno test [OPTIONS] [files]... [-- <SCRIPT_ARG>...]

--filter <filter>: Run tests with this string or pattern in the test name

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

禾厶谷欠 2025-02-03 03:15:39

您可以使用 globbing shell的功能。这是一个使用bash的示例:

$ ls
number_1_test.ts  number_2_test.ts  string_test.ts

$ echo $(ls number*)
number_1_test.ts number_2_test.ts

$ deno test $(ls number*)
running 1 test from ./number_1_test.ts
number 1 ... ok (4ms)
running 1 test from ./number_2_test.ts
number 2 ... ok (6ms)

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (45ms)

You can do this using the globbing capabilities of your shell. Here's an example using bash:

$ ls
number_1_test.ts  number_2_test.ts  string_test.ts

$ echo $(ls number*)
number_1_test.ts number_2_test.ts

$ deno test $(ls number*)
running 1 test from ./number_1_test.ts
number 1 ... ok (4ms)
running 1 test from ./number_2_test.ts
number 2 ... ok (6ms)

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (45ms)
絕版丫頭 2025-02-03 03:15:39

您可以并排除测试文件通过deno.json(c)

就我而言,我将单元*。spec.ts与Integration *。test.ts测试:

{
  "tasks": {
    ...
    "test:ci": "deno test --allow-env --allow-read --allow-net --fail-fast",
    "test:integration": "deno task test:ci --parallel src/**/*.test.ts",
    "test:unit": "deno task test:ci --parallel src/**/*.spec.ts",
    "test": "deno task test:unit && deno task test:integration"
  },
  "test": {
    "include": [
      "src/**/*.spec.ts",
      "src/**/*.test.ts"
    ]
  }
}

使用相同的模式可以解决您的问题:> DENO TEST ./src/**/number*.ts

You can include and exclude test files via deno.json(c).

In my case, I was separating the unit *.spec.ts from integration *.test.ts tests:

{
  "tasks": {
    ...
    "test:ci": "deno test --allow-env --allow-read --allow-net --fail-fast",
    "test:integration": "deno task test:ci --parallel src/**/*.test.ts",
    "test:unit": "deno task test:ci --parallel src/**/*.spec.ts",
    "test": "deno task test:unit && deno task test:integration"
  },
  "test": {
    "include": [
      "src/**/*.spec.ts",
      "src/**/*.test.ts"
    ]
  }
}

With the same pattern you can solve your issue: deno test ./src/**/number*.ts

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文