neotest-jest
neotest-jest copied to clipboard
"No tests found" when using separate directory and config for eg e2e tests
Problem:
I can't figure out how to configure this.
Plugin Setup:
All dependencies installed.
'nvim-neotest/neotest',
dependencies = {
'nvim-lua/plenary.nvim',
'nvim-treesitter/nvim-treesitter',
'antoinemadec/FixCursorHold.nvim',
'haydenmeade/neotest-jest',
Setup Call
require('neotest').setup {
adapters = {
require('neotest-jest')({
jestCommand = "npx jest",
jestConfigFile = "package.json",
cwd = function(path)
return vim.fn.getcwd()
end,
}),
},
}
Project Setup:
Unit Tests:
Jest config is in package.json
{
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"moduleNameMapper": {
"src/(.*)$": "<rootDir>/$1"
}
}
}
Test files are in src/*.spec.ts
Normal test cases work, eg <Cmd>lua require('neotest').run.run()<CR>
in src/app.controller.spec.ts
e2e tests:
Jest config is in test/jest-e2e.json
{
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"moduleNameMapper": {
"src/(.*)$": "<rootDir>/../src/$1"
}
}
Test files are in test/app/app.e2e-spec.ts
Running tests with cli works:
NODE_ENV=test jest --config ./test/jest-e2e.json
Running tests with neotest doesn't work:
:lua require('neotest').run.run({env={NODE_ENV='test'}, jestConfigFile='./test/jest-e2e.json'})<cr>
in test/app/app.e2e-spec.ts
produces "No tests found".
Thank you for your work!
I'm also seeing "No tests found" but I think this might be a recent regression, this was working fine just a couple of weeks ago!
Yep, as I thought, if I pin the version to this commit: 3853b842b5d4850a2d5495f75802dabb3cda246c
then it works fine. Curious to know if that helps you
Probably a duplicate of #60. The problem is commit 0c0dad7 updated the detection logic so that jest
has to appear in the dependencies/devDependencies of the package.json, otherwise it will refuse to detect any tests.
Curious to know if that helps you
~/.local/share/nvim/site/pack/packer/start/neotest-jest $ git status
HEAD detached at 3853b84
nothing to commit, working tree clean
:lua require('neotest').run.run({env={NODE_ENV='test'}, jestConfigFile='./test/jest-e2e.json'})<cr>
in test/app/app.e2e-spec.ts
still produces "No tests found".
I had to take it back a few commits before the dependency logic was added. Try commit 219033658bf8de6b91e201036a5cc5456905d9d2
. In my case my package.json looks like"
"devDependencies": {
...
"@types/jest": "^27.4.1",
...
},
@haydenmeade what's the rationale for locking this down so tightly?
I have the same issue. It just ignores .e2e-spec.ts but works fine with .spec.ts
I've added a related PR https://github.com/nvim-neotest/neotest-jest/pull/92. Ideally, it should be a configurable list of prefixes.