Open brianfiszman opened 5 months ago
I've tried to reproduce your problem but without much luck. You didn't provide your neovim version or expect library although I'm guessing it's chai
from the example. I'm getting a "No tests found" instead.
neotest-mocha
works by invoking the tests with the json
reporter along with --reporter-options=output=<json_output_file>
which writes the json output to a file which the adapter uses to produce the diagnostics etc. However, the --reporter-options
for json output was only introduced in mocha v9.1.0 so the json output goes to stdout instead (I verified this by running the resulting test command directly on the commandline) which is likely why the adapter doesn't work and reports an error instead. I'll make an update to the README to specify the mocha version requirement.
You could probably get around this by instead redirecting the output of the test command to the results_path
file but I don't think this is something the maintainer would want to support as it's a very old version. Sucks you're stuck three major versions behind :/
Which vscode plugin are you using? I'm curious to know if they just redirect file output for older versions or using a custom reporter.
I've tried to reproduce your problem but without much luck. You didn't provide your neovim version or expect library although I'm guessing it's
chai
from the example. I'm getting a "No tests found" instead.
neotest-mocha
works by invoking the tests with thejson
reporter along with--reporter-options=output=<json_output_file>
which writes the json output to a file which the adapter uses to produce the diagnostics etc. However, the--reporter-options
for json output was only introduced in mocha v9.1.0 so the json output goes to stdout instead (I verified this by running the resulting test command directly on the commandline) which is likely why the adapter doesn't work and reports an error instead. I'll make an update to the README to specify the mocha version requirement.You could probably get around this by instead redirecting the output of the test command to the
results_path
file but I don't think this is something the maintainer would want to support as it's a very old version. Sucks you're stuck three major versions behind :/Which vscode plugin are you using? I'm curious to know if they just redirect file output for older versions or using a custom reporter.
Yeah, it sucks being stuck 3 versions behind but it happens a lot, lots of industrial software projects involve working with a bit of legacy software, sad but true.
These are the plugins I'm using for Mocha on VSCode:
Name: Mocha
Id: Compulim.vscode-mocha
Description: Runs Mocha tests
Version: 0.1.1
Publisher: Compulim
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=Compulim.vscode-mocha
Name: Mocha Test Explorer
Id: hbenl.vscode-mocha-test-adapter
Description: Run your Mocha tests in the Sidebar of Visual Studio Code
Version: 2.14.1
Publisher: Holger Benl
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-mocha-test-adapter
About my Neovim version:
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1703358377
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.5/share/nvim"
I installed it using Brew, using it on a Macbook Pro M3 Pro 14".
This is the config I'm using for the adapter:
require("neotest").setup {
quickfix = {
open = function()
require("trouble").open({ mode = "quickfix", focus = false })
end
},
discovery = {
enabled = false,
},
icons = {
passed = "",
running = "",
failed = "",
skipped = "",
unknown = "",
child_indent = "│",
child_prefix = "├",
collapsed = "",
expanded = "",
final_child_indent = " ",
final_child_prefix = "╰",
non_collapsed = "",
watching = "",
running_animated = { "⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷" },
},
status = { virtual_text = true },
output = { open_on_run = true },
log_level = 3,
adapters = {
require("neotest-vim-test")({
ignore_file_types = { "python", "vim", "lua" },
}),
require "neotest-python" {
dap = { justMyCode = false },
},
require "neotest-vitest",
require "neotest-plenary",
require "neotest-zig",
require "neotest-go",
require('neotest-mocha')({
command = "yarn test:neovim",
env = { CI = true },
cwd = function() return vim.fn.getcwd() end,
}),
require('neotest-jest')({
jestCommand = "yarn test --silent",
jestConfigFile = "scripts/vscode-mocharc.yml",
env = { CI = true },
cwd = function() return vim.fn.getcwd() end,
}),
},
}
end
Chai Version is ^4.3.4
You can find more on My Dotfiles
Regarding the output, here it is. Also I'll keep the upper comment updated for any questions about versions:
Thanks for the details of your setup.
I took a look at the plugins you posted and as indicated by my comment in #14 they are using a custom reporter to gather results. However, neotest
adapters typically write results to a file, parse them, and convert them for neotest
consumption. Here's some useful resources (that you might already have found but anyway...):
spec
and json
reporters). See the two linked projects as well.Feel free to ping me if I can be of any more help :) let's leave the issue open for now but I'll consider it "resolved" as the issue was an outdated version of mocha.
@MisanthropicBit BTW is another issue, Table Driven Tests arent working no matter the version, I tried with a newer one and it didnt do the trick.
I don't know what Table Driven Tests are but I suspect it's something like jest's test.each
? In that regard, mocha suggests just using javascript.
If you're using a third-party plugin to do the table-driven tests, I think that's out of the scope of this adapter and the queries for recognising tests are confined to support mocha's builtins only.
Well.. its basically creating an array of test cases as objects with data and then iterate that array while calling the function
it()
It's native Javascript huh.
Thanks for confirming. Then it's as described in the second link.
I'll try to confirm that this doesn't work when I have time but the issue is that a single it
in the source gets expanded to multiple tests when run.
neotest-jest
(on which this repo is based) has support for parameterized tests like this by running jest again but only to collect the tests that would actually be run and then updating the positions in the tree. This is unfortunately not something neotest-mocha can do at the moment.
I was using the test runner and its throwing me the error icon even when it shouldnt. So I have to check the logs to know if the test are okay or not. Mocha Version: ^7.2.0 The test that you can see in the image is really simple. I tried using this with a newer mocha version and it worked but the project I'm working wouldnt let me upgrade mocha version so all I have left is creating this issue. If I cant work with testing on this editor I would have to move back to VSCode because its working correctly on that editor lol