Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DasOhmoff opened this issue Oct 25, 2022 · 2 comments · Fixed by #91 · May be fixed by #44
Closed

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

DasOhmoff opened this issue Oct 25, 2022 · 2 comments · Fixed by #91 · May be fixed by #44

Comments

@DasOhmoff
Copy link

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
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant