David-Kunz / jester

A Neovim plugin to easily run and debug Jest tests
The Unlicense
202 stars 12 forks source link

Can't find tests when the filename has regex symbols in it #7

Closed kahnclusions closed 2 years ago

kahnclusions commented 2 years ago

Hi 👋 As the title says, can't find tests when the filename has regex symbols in it. For example, one of my projects has a filename like [productType].test.tsx which is a perfectly valid filename in a Node/TS project.

I can run this test from command line:

> yarn jest src/pages/some-page/__tests__/\\[productType\\].test.tsx

But when running from Jester, it can't find the test likely because it interpreted [productType] as a regex character class, instead of just a plain string. No escaping is done before passing the filename to Jest.

Debugger listening on ws://127.0.0.1:9229/5ddc50
f6-7908-4b7d-9b34-7fc41391553e
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/kahnclusions/src/myproject
  607 files checked.
  testMatch: **/?(*.)+(spec|test).[tj]s?(x) - 52
 matches
  testPathIgnorePatterns: /node_modules/ - 607 matches
  testRegex:  - 0 matches
Pattern: /Users/kahnclusions/src/myproject/src/pages/some-page/__tests__/[productType].test.tsx|--no-cache - 0 matches
Waiting for the debugger to disconnect...

[Process exited 137]
David-Kunz commented 2 years ago

Hi @kahnclusions ,

Thanks for this issue report, that's an interesting bug. Let me see if I can find some time to fix this.

Best regards, David

David-Kunz commented 2 years ago

Hi @kahnclusions ,

Thanks again for providing this nice error report.

I've fixed the issue, now regular expressions in filenames should work. https://github.com/David-Kunz/jester/commit/3f02fb4c43d4ce898dbfa74482cf73b7320dd262

Would you mind testing it with the newest Jester version?

Thanks a lot and best regards, David