deno icon indicating copy to clipboard operation
deno copied to clipboard

Question about `only` option in TestDefinition

Open kt3k opened this issue 2 years ago • 3 comments

related https://github.com/denoland/deno_std/issues/2979

only option looks scoped to a file. (i.e. if one test case in a_test.ts has only: true, then other test cases in a_test.ts are skipped, but if there are other test files (b_test.ts), then those test cases in other test files are still executed with deno test command).

Is this the intended behavior?

kt3k avatar Jan 04 '23 09:01 kt3k

deno test with the following files:

a_test.ts

Deno.test("A 1", () => {});
Deno.test("A 2", { only: true }, () => {});

b_test.ts

Deno.test("B", () => {});

This results with the below executions:

$ deno test    
running 1 test from ./a_test.ts
A 2 ... ok (7ms)
running 1 test from ./b_test.ts
B ... ok (6ms)

ok | 2 passed | 0 failed | 1 filtered out (68ms)

The case A 1 is filtered out, but B is not

kt3k avatar Jan 04 '23 09:01 kt3k

Good question - I'm not sure if we can figure out upfront which test cases from which files we need to run because test steps with .only option might be deeply nested. @dsherret any idea?

bartlomieju avatar Jan 04 '23 12:01 bartlomieju

I know that other test runners like jasmine won't run tests from other files if one file has a focused test. This has been a bit of a pain point for me working with deno because you have to pass a file argument to the test command to be able to focus a file. I use many flags and have a shorthand in my deno task list. I end up needing to modify it if I want to focus a specific file that has the test I want to focus.

I think it would be a good change to make it so that if any file has focused tests, only those files will run.

KyleJune avatar Dec 22 '23 00:12 KyleJune