nvim-neotest / neotest-jest

MIT License
116 stars 77 forks source link

"No tests found" when using separate directory and config for eg e2e tests #61

Open aMOPel opened 1 year ago

aMOPel commented 1 year ago

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!

CallumHoward commented 1 year ago

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!

CallumHoward commented 1 year 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

HugoArts commented 1 year ago

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.

aMOPel commented 1 year ago

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".

stephenmckinney commented 1 year ago

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",
...
  },
stephenmckinney commented 1 year ago

@haydenmeade what's the rationale for locking this down so tightly?

tolik505 commented 9 months ago

I have the same issue. It just ignores .e2e-spec.ts but works fine with .spec.ts

tolik505 commented 8 months ago

I've added a related PR https://github.com/nvim-neotest/neotest-jest/pull/92. Ideally, it should be a configurable list of prefixes.