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

fix(windows): path reducing for jest pattern #116

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eugeny-dementev
Copy link

@eugeny-dementev eugeny-dementev commented Apr 3, 2024

Fix for #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.ts in nvim running command
    :lua =vim.fn.expand("%") will show
    unix: __tests__/file.test.ts
    windows: C:/project\__tests__/file.test.ts
    • neotest uses 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'}

@conermurphy
Copy link
Contributor

I had the same issues with running the tests locally, raised an issue for it here #114 to try get some help from others.

@JanPeter
Copy link

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.

@BitsAndDroids
Copy link

BitsAndDroids commented Jun 5, 2024

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'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("\\", ""),

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

Successfully merging this pull request may close these issues.

None yet

4 participants