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

[Feature] Code Coverage Indicators #312

Closed
sand4rt opened this issue Nov 11, 2023 · 1 comment
Closed

[Feature] Code Coverage Indicators #312

sand4rt opened this issue Nov 11, 2023 · 1 comment

Comments

@sand4rt
Copy link

sand4rt commented Nov 11, 2023

First of all, thank you for this awesome plugin!

It would probably be a lot of work, but it would be great to have code coverage indicators ala Wallaby.js:

image

When executing your tests and code, Wallaby calculates code coverage to identify which statements of your code have been executed and which statements have not.

Code coverage for your application code is displayed in the left margin of your editor and is updated in real-time. As soon as you start changing your code, the coverage will be automatically updated.

*https://wallabyjs.com/docs/intro/coverage.html#editor-code-coverage-indicators

What the coverage indicators mean:

  • Gray: if you see a gray square next to a line of code, it means that the line of code is not covered by any of your tests.
  • Yellow: if you see a yellow square next to a line of code, it means that the line of code is only partially covered by your tests.
  • Green: if you see a green square next to a line of code, it means that the line of code is covered by at least one of your tests.
  • Pink: if you see a pink square next to a line of code, it means that the line of code is on the execution path of a failing test.
  • Red: if you see a red square next to a line of code, it means that the line of code is the source of an error or failed expectation, or in the stack of an error.
@jan-xyz
Copy link
Contributor

jan-xyz commented Nov 12, 2023

I am achieving this by using https://github.com/andythigpen/nvim-coverage. You can setup custom arguments for your test runner to export coverage data and then just display it. E.g. for Go I am doing this:

local nt = require("neotest")
local cov = require("coverage")

cov.setup()
nt.setup({
  adapters = {
    require("neotest-go")({
      args = { "-coverprofile=coverage.out" },
    }),
  },
})

and then I run

nt.run.run(vim.fn.getcwd())
cov.load(true)

How it looks like (the green bars are the coverage report):
image

@sand4rt sand4rt closed this as completed Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants