Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing code lens for wrapped test method #572

Open
zumoshi opened this issue Nov 7, 2021 · 5 comments
Open

Testing code lens for wrapped test method #572

zumoshi opened this issue Nov 7, 2021 · 5 comments

Comments

@zumoshi
Copy link

zumoshi commented Nov 7, 2021

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
Copy link
Contributor

kitsonk commented Nov 7, 2021

@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
Copy link
Member

dsherret commented Nov 8, 2021

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
Copy link
Contributor

kitsonk commented Nov 8, 2021

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
Copy link
Contributor

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
Copy link

rivy commented Jun 14, 2022

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants