nvim-neotest / neotest-jest

MIT License
121 stars 80 forks source link

Tests cannot be found on windows, due to usage of `\` instead of `/` in the file path. #42

Closed DasOhmoff closed 2 years ago

DasOhmoff commented 2 years ago

Have 👋, thank you for this nice plugin!

I use Windows and Neovim 0.8, and I would love to use this plugin with it.

When I try to run my tests through require('neotest').run.run(), then the test cannot be found. The output is as follows:

> jest {...} C:\{...}\component.spec.ts

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\{...}\frontend
  38 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 8 matches
  testPathIgnorePatterns: \\node_modules\\ - 38 matches
  testRegex:  - 0 matches
Pattern: C:\{...}\component.spec.ts - 0 matches

When I manually run the test in the terminal, then the result is the same. But when I change the \s in the command to /s, then the tests can be found and they succeed:

> jest {...} C:/{...}/component.spec.ts

Determining test suites to run...
ngcc-jest-processor: running ngcc
 PASS  src/component.spec.ts

It would be nice to fix this. How can I make this work?

Thank you for your support :)

DasOhmoff commented 2 years ago

I looked through the source code, and through the following change I was able to make the tests pass:

diff --git a/lua/neotest-jest/init.lua b/lua/neotest-jest/init.lua
index 764f585cec8bf72880712dc4c8203a5748c4db78..7282048b3e9e909864dbd8649a56ff1d7596e54d 100644
--- a/lua/neotest-jest/init.lua
+++ b/lua/neotest-jest/init.lua
@@ -222,7 +222,7 @@ function adapter.build_spec(args)
     "--json",
     "--outputFile=" .. results_path,
     "--testNamePattern=" .. testNamePattern,
-    pos.path,
+    string.gsub(pos.path, '\\', '/'),
   })

   local cwd = getCwd(pos.path)

I think this should now work on all systems, but I am not sure

DasOhmoff commented 2 years ago

I opened up the #44 pull request for this thing.