denoland / vscode_deno

Visual Studio Code plugin for Deno
https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno
MIT License
1.5k stars 146 forks source link

Testing code lens for wrapped test method #572

Open zumoshi opened 3 years ago

zumoshi commented 3 years ago

Is your feature request related to a problem? Please describe.

As Deno has declined to extend their test API with hooks such as before/after, in some cases it is needed to extend this capability by wrapping the test method. As has been done in test_suite.

However, when doing so the extension fails to detect the new wrapped method as a test and doesn't provide code lens to allow tests to be run individually.

image (line 10 has no Run test despite being recognized by Deno)

Describe the solution you'd like

Either a special syntax/annotation/type to mark a certain function as equivalent to Deno.test or tapping into Deno's test detection and possibly using stack trace at the time of test registration to find indirectly registered tests.

kitsonk commented 3 years ago

@dsherret you are closer to the direction of the test API at the moment, can you think of a clean way to detect this in the AST?

dsherret commented 3 years ago

For the same file it would be not too bad to get it working in some constrained scenarios, but it would be a bit of work to get it working across files.

A workaround right now might be to instead just wrap the test definition creation or the function rather than the entire call:

Deno.test(wrapped({
  name: "some test",
  fn: () => {
  },
});
Deno.test("some test", wrapped(() => {
}));
kitsonk commented 3 years ago

That doesn't even sound like a work-around, that seems like a much better overall solution. There will always be a limit of what we can detect from the AST, even the destructuring only works within a file.

I can't really see a drawback to that solution.

jespertheend commented 2 years ago

I'm using tincan for writing tests, which uses a Jest-like api. So using a wrapper as shown above is not really an option in this case I think.

rivy commented 2 years ago

@kitsonk @dsherret , any thoughts about revisiting this?

There are lots of alternative testing paradigms and frameworks. Some sort of code lens API or wrapper recognition signal would be quite helpful to encourage the ecosystem. Currently, the code lens doesn't recognize the BDD example tests included in std 0.143.0 (https://github.com/denoland/deno_std/blob/0.143.0/testing/bdd_examples/user_flat_test.ts).