neotest-jest
neotest-jest copied to clipboard
fix(windows): path reducing for jest pattern
Fix for https://github.com/nvim-neotest/neotest-jest/issues/113
There are few issues with it on windows:
- First issue is there a huge difference how
vim.fn.expand("%")works on windows and unix: for file__tests__/file.test.tsin nvim running command:lua =vim.fn.expand("%")will show unix:__tests__/file.test.tswindows:C:/project\__tests__/file.test.tsneotestuses that internal function to get current file and pass result to adapters
- Second is jest not exactly expecting pattern to be full path to the file. I'm not sure but I assume jest always run pattern search on current directory and providing full path just makes so there is no files matching that pattern ever
- Also jest seem to expect pattern to be unix style always, no matter the OS it's running on
Solution in the PR is to reduce windows version of path to the same pattern it is for unix:
C:/project\__tests__/file.test.ts => __tests__/file.test.ts.
Fix is universal, on unix vim.fn.substitute (string replace) just doesn't do anything since path already lacking cwd part
I've tested it on both windows and ubuntu and it seem to work as intended on both platforms
Help needed with writing tests because ./scripts/test throws an error for me so I have no idea if I broke something
Error detected while processing command line:
E492: Not an editor command: PlenaryBustedDirectory tests/ {minimal_init = 'tests/init.vim'}
I had the same issues with running the tests locally, raised an issue for it here #114 to try get some help from others.
I'm using Neovim in Windows 11 with PowerShell 7.4.1 and it only works for me after I apply your code and remove the escapeTestPattern call.
I'm using Neovim in Windows 11 with PowerShell 7.4.1 and it only works for me after I apply your code and remove the
escapeTestPatterncall.
I've encountered the same issue. To fix this I've had to gsub out the backslash characters for it to work. It seems to normalize the path to C:\/....\/.... which windows does not like.
escapeTestPattern(reducePattern(cwd, pos.path)):gsub("\\", ""),