nvim-neotest / neotest-jest

MIT License
116 stars 79 forks source link

Unable to find tests that contain `[]` in the file path #108

Closed conermurphy closed 5 months ago

conermurphy commented 5 months ago

When I try to run the tests in a file and that file's path contains the characters [] neotest is unable to find the test and returns a No tests found, exiting with code 1 error.

I came across this closed issue but it seems this bug still happens.

As an example this test file path would get the above no tests error: ./foo/[bar]/foo.test.ts.

However, this file path would be fine and run as expected ./foo/bar/foo.test.ts.

I've checked and the tests with the [] in the filename are correctly found by running Jest in the CLI and are able to be run in the VSCode Jest extension so I think the issue is specific to Neovim.

imfaber commented 5 months ago

I have - in my paths and now they are no longer found with this change

conermurphy commented 5 months ago

@imfaber, not sure what's happening there. I just tried with a test that has a path like this /foo/foo-bar/bar.test.ts and it picks it up okay in the summary page and runs the test correctly as well. Is your - in the directories or the file name of the test?

imfaber commented 5 months ago

@conermurphy in the directory but actually the overall path doesn't look good. It should have only 2 \\

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\Users\fabri\dev\EnergyShop.HomeQgo-v2\Api\ClientApp
  1014 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 171 matches
  testPathIgnorePatterns: \\node_modules\\, \\e2e - 994 matches
  testRegex:  - 0 matches
Pattern: C:\\\Users\\\fabri\\\dev\\\EnergyShop.HomeQgo\-v2\\\ClientApp\\\core\\\campaign.spec.ts - 0 matches

If I revert this change it works

Test Suites: 1 passed, 1 total
Tests:       1 skipped, 1 passed, 2 total
Snapshots:   0 total
Time:        3.103 s
Ran all test suites matching /C:\\Users\\fabri\\dev\\EnergyShop.HomeQgo-v2\\ClientApp\\core\\campaign.spec.ts/
conermurphy commented 5 months ago

@imfaber, are you running this on Windows? I'm presuming so by the C:/, maybe the issue is related to #44, this issue doesn't happen on MacOS so I'm thinking it's related to the issue described in that PR.

Could also be something happening in the escapeTestPattern function to add the extra \ in. Might be worth making a new issue for this to be looked into. I would offer but I don't have a Windows machine to test this out on.

imfaber commented 5 months ago

@conermurphy yes I'm on Windows and vim.fs.normalize introduced in #91 made paths work nicely. Here the prob that I have is with this change where escapeTestPattern seems to break them. I think back slashes are not the problem if they are properly escaped

conermurphy commented 5 months ago

@imfaber, I just opened #113 to contain the conversation for this issue as while it's related to the changes in this PR, the new issue is unrelated to the bug described in this PR.

Happy to continue the conversation over there 😄