Deno: Grouping tests by file

Created on 6 Apr 2020  路  3Comments  路  Source: denoland/deno

Currently, all tests from different test file are printed as if they are all from one file. This could be a problem on a large test suite where developer needs to find failed test case/file.

In Jest, tests are grouped per file. By default, only file names and names of failed tests are shown.

Alternative Proposals

  1. Show file names alongside test case.
  2. Display a tree of file names and test case. File names are branches, and test cases are leafs.
  3. Create a Deno.testGroup function that acts like describe in Jest, use it in .deno.test.ts to wrap import line of a test file.
  4. Log test file names before execution (similar to cargo test).
cli suggestion

Most helpful comment

There is an easier solution: log test file names before import 'test-file'. This would produce a result similar to cargo test.

All 3 comments

Alternative Proposals

  1. Show file names alongside test case.
  2. Display a tree of file names and test case. File names are branches, and test cases are leafs.

Test cases are registered programatically during runtime using Deno.test() API so it would require crufty solution like creating error and looking up filename in the stack trace - but that's really not reliable, eg. in cli/js/tests/ default Deno.test() API is wrapped in unitTest function - trying to sniff out file name from stack trace would always return unit_test_runner.ts

  1. Create a Deno.testGroup function that acts like describe in Jest, use it in .deno.test.ts to wrap import line of a test file.

Not long ago there was discussion about adding something like test suite to test framework, but it was decided that it's left for 3rd party libs to implement.

If https://github.com/denoland/deno/issues/4366 is implemented, doing this would be much easier.

But for now, how about altering Deno.test itself in .deno.test.ts to display different file names?

There is an easier solution: log test file names before import 'test-file'. This would produce a result similar to cargo test.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ry picture ry  路  3Comments

kitsonk picture kitsonk  路  3Comments

watilde picture watilde  路  3Comments

zugende picture zugende  路  3Comments

doutchnugget picture doutchnugget  路  3Comments