fredrikaverpil / neotest-golang

Reliable Neotest adapter for running Go tests in Neovim.
MIT License
144 stars 17 forks source link

Fail and time is not displaying #22

Closed quolpr closed 6 months ago

quolpr commented 6 months ago

Here how it looks:

image

While on your screenshot I can see "Fail" + how much took near test

The output:

=== RUN   TestIssuer_IssueCourier
=== PAUSE TestIssuer_IssueCourier
=== CONT  TestIssuer_IssueCourier
=== RUN   TestIssuer_IssueCourier/fail_on_invalid_code
=== PAUSE TestIssuer_IssueCourier/fail_on_invalid_code
=== CONT  TestIssuer_IssueCourier/fail_on_invalid_code
2024/05/30 21:36:25 github.com/testcontainers/testcontainers-go - Connected to docker: 
  Server Version: 25.0.5
  API Version: 1.44
  Operating System: OrbStack
  Total Memory: 28017 MB
  Resolved Docker Host: unix:///var/run/docker.sock
  Resolved Docker Socket Path: /var/run/docker.sock
  Test SessionID: 1e91dce613a1c591607522012d8bfddf2816252be0f49b137a666046f03d1e2c
  Test ProcessID: 2fa38b55-7a6f-4387-8e7b-7564e6649a25
2024/05/30 21:36:25 🐳 Creating container for image testcontainers/ryuk:0.6.0
2024/05/30 21:36:25 ✅ Container created: 703a9f2dadac
2024/05/30 21:36:25 🐳 Starting container: 703a9f2dadac
2024/05/30 21:36:26 ✅ Container started: 703a9f2dadac
2024/05/30 21:36:26 🚧 Waiting for container id 703a9f2dadac image: testcontainers/ryuk:0.6.0. Waiting for: &{Port:8080/tcp timeout:<nil> PollInterval:100ms}
2024/05/30 21:36:26 🔔 Container is ready: 703a9f2dadac
2024/05/30 21:36:26 🐳 Creating container for image postgres:16-alpine
2024/05/30 21:36:26 ✅ Container created: ae2cd46b8adb
2024/05/30 21:36:26 🐳 Starting container: ae2cd46b8adb
2024/05/30 21:36:26 ✅ Container started: ae2cd46b8adb
2024/05/30 21:36:26 🚧 Waiting for container id ae2cd46b8adb image: postgres:16-alpine. Waiting for: &{timeout:<nil> deadline:0xc00050d8a8 Strategies:[0xc0004d2e40]}
2024/05/30 21:36:33 🔔 Container is ready: ae2cd46b8adb
    issuer_test.go:76: 
                Error Trace:    /Users/quolpr/projects/service/mag-collect-service/internal/service/order/issuer_test.go:76
                Error:          Target error should be in err chain:
                                expected: "Invalid issue code"
                                in chain: "failed to process issue: failed to issue assembly: failed to issue assembly: Can't issue this assembly, status must be 'start_issuing' "
                                        "failed to issue assembly: failed to issue assembly: Can't issue this assembly, status must be 'start_issuing' "
                                        "failed to issue assembly: Can't issue this assembly, status must be 'start_issuing' "
                                        "Can't issue this assembly, status must be 'start_issuing' "
                Test:           TestIssuer_IssueCourier/fail_on_invalid_code
--- FAIL: TestIssuer_IssueCourier (0.00s)
    --- FAIL: TestIssuer_IssueCourier/fail_on_invalid_code (9.01s)
FAIL
coverage: 7.9% of statements
FAIL    service/mag_collect_service/internal/service/order       9.463s

Config:

local neotest = require 'neotest'

local config = { -- Specify configuration
  go_test_args = {
    '-v',
    '-race',
    '-count=1',
    '-timeout=60s',
    '-coverprofile=' .. vim.fn.getcwd() .. '/coverage.out',
  },
}

---@diagnostic disable-next-line: missing-fields
neotest.setup {
  output = {
    enabled = true,
    open_on_run = false,
  },
  -- your neotest config here
  adapters = {
    require 'neotest-golang'(config), -- Registration
  },
}

Also, I am curious, is it possible to add how much time test took even for green tests?

Great job btw! Thank you for the plugin 🙂

fredrikaverpil commented 6 months ago

Hi @quolpr 😄

Yes, this was actually something I removed in #20. Basically, for each error that occurs, you are supposed to register it in a lua table, which looks like this:

errors = {
  { message = "foo", line = 42 },
  { message = "bar", line = 69 },
}

https://github.com/fredrikaverpil/neotest-golang/blob/2e42066c0a28712f0d2d2516c6f48c41fc374834/lua/neotest-golang/init.lua#L272-L276

For each error, diagnostics are also registered, which you can see at the bottom of my screenshots in the #20 PR. Notice how the first one shows (incorrectly) 10 problems while the second screenshot shows the (accurate) 1 problem.

I was previously excessively recording too many error messages, which had the side-effect of showing the FAIL stuff along with the time. But this also messed with other things, such as the number of diagnostics errors, as you can also see by the number of icons in front of the diagnostics with the time duration.

This means if you want to view the details around your test run, such as the time info, you'll have to either open the output window or the output panel.

quolpr commented 6 months ago

@fredrikaverpil ahh, got it! Thanks for clarifications