jest icon indicating copy to clipboard operation
jest copied to clipboard

Confusing escaping behaviours on Windows

Open rudym87 opened this issue 8 years ago • 15 comments

Do you want to request a feature or report a bug? Bug What is the current behavior? There's a different behaviour in escaping the path separator on Windows when the pattern is specified via CLI parameter vs. when it's inserted via the pattern prompt (pressing "p") If I run on the command prompt something like yarn jest folder\file --watchAll then Jest would fail with

No tests found
[...]
Pattern: folder\file - 0 matches

but then if press p and enter the exact same pattern folder\file, Jest would find the correct file(s) and run correctly. I know that the correct CLI pattern should be folder\\file but seeing the same input give different outputs is confusing.

Run npx envinfo --preset jest in your project directory and paste the results here

System:
    OS: Windows 10
    CPU: x64 Intel(R) Core(TM) i7-3635QM CPU @ 2.40GHz
  Binaries:
    Node: 8.9.4
    Yarn: 1.5.1
    npm: 5.6.0
  npmPackages:
    jest:
      wanted: ^22.4.3
      installed: 22.4.3

rudym87 avatar Apr 05 '18 10:04 rudym87

Hello! Would it be fine if I start working on this?

ghost avatar Apr 28 '18 02:04 ghost

Would be great!

thymikee avatar Apr 28 '18 06:04 thymikee

Hi, is this still relevant or being worked on? I could take it up.

jarvinenio avatar Oct 11 '18 12:10 jarvinenio

@jarvinenio all you!

rickhanlonii avatar Oct 11 '18 15:10 rickhanlonii

Since this issue is still open, can I take it up as my very first PR? Also, could anyone tell me how to keep the consistency of these two behaviors? My idea is to prompt the user to check \ should be \\ or /, when running on the command prompt yarn jest folder\file --watchAll on the Windows. Thanks!

Jinshuo1994 avatar Apr 29 '19 04:04 Jinshuo1994

The whole regex auto escaping thing that the pattern prompt does here seems like too much magic to me - sure, typing \\ is annoying, but Windows users can just use the normal / as well. But I guess all of this will be solved when we eventually start using globs for path-related things. For now, maybe we should apply the same replacePathSepForRegex logic (I thinks that's what does the escaping) to the CLI argument?

jeysal avatar Apr 29 '19 11:04 jeysal

@jeysal Thanks! Can I start working on this issue now?

Jinshuo1994 avatar Apr 29 '19 16:04 Jinshuo1994

Maybe first wait if @thymikee or @simenb have thoughts on what's best here?

jeysal avatar Apr 29 '19 17:04 jeysal

It should definitely behave the same regardless if it's specified from cli or watch mode.

I'd prefer using forward slashes for everything, but it should always be consistent

EDIT: does that answer the question? If not, please ping me.

SimenB avatar Apr 29 '19 17:04 SimenB

@SimenB Can I start to try to fix this issue using jeysal's fixing advice?

Jinshuo1994 avatar Apr 29 '19 21:04 Jinshuo1994

I'd prefer using forward slashes for everything, but it should always be consistent

Yeah maybe just remove the magic escaping from the pattern prompt? If paths require entering two backslashes everywhere (proper regex) most people will probably start using slashes regardless of OS.

jeysal avatar Apr 29 '19 22:04 jeysal

In a similar vain though, when using yarn test .\path\to\test\file.js in Windows it doesn't match up, but if you do yarn test ./path/to/test/file.js it does. The problem though is that when you are typing it from powershell/cmd, and using tab to auto complete the path, it automatically converts it to be single back slash.

davidhouweling avatar May 02 '19 12:05 davidhouweling

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Feb 25 '22 13:02 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar Mar 27 '22 13:03 github-actions[bot]

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

github-actions[bot] avatar Apr 27 '22 00:04 github-actions[bot]