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

Use the VS Code Test API #136

Open
anderseknert opened this issue Apr 6, 2024 · 0 comments
Open

Use the VS Code Test API #136

anderseknert opened this issue Apr 6, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@anderseknert
Copy link
Member

anderseknert commented Apr 6, 2024

That wasn't around when this extension was originally built, so the OPA test commands simply call out to OPA and display the output as provided. Using the Test API provides a nicer integration though, and allows things like running single tests or all tests in a file right from the editor view, as seen here from my late night POC:

Screenshot 2024-04-10 at 10 18 01

Since v1.88, there's also a native API for test coverage.

There are however some minor incompatibilities in how OPA runs tests vs. how IDEs like VS Code runs them:

  • IDE test runners work on the level of files or single tests — the OPA test runner will just run any tests it finds
  • There’s an option to --run only tests matching a filter, but there’s no guarantee that it’ll match only the test the user clicked as there could be many tests of the same name in the loaded workspace

One workaround, sort of, could be to actually run all tests always, but only display the result from the file or test the user asked for. This is doable as the JSON test output prints the file + test name for each result. For the single test case, we could do a combo of --run plus filter the result to only match the file where it’s clicked.

This would of course mean that we'd often be running a bunch of tests that nobody asked for, but since test execution in OPA is normally very fast, this will likely not be noticeable in anything but huge projects.

Long term solution would be to update the OPA test runner to allow loading all files, but only run tests from files that are explicitly provided.

@anderseknert anderseknert added the enhancement New feature or request label Apr 6, 2024
@anderseknert anderseknert changed the title Use the new VS Code test coverage API Use the new VS Code Test API Apr 10, 2024
@anderseknert anderseknert changed the title Use the new VS Code Test API Use the VS Code Test API Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant