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

Jest crashes on Windows if regexForTestFiles provided from cli is a number #9526

Closed
yume-chan opened this issue Feb 6, 2020 · 2 comments · Fixed by #9546
Closed

Jest crashes on Windows if regexForTestFiles provided from cli is a number #9526

yume-chan opened this issue Feb 6, 2020 · 2 comments · Fixed by #9546

Comments

@yume-chan
Copy link

🐛 Bug Report

I have test files named by numbers.

When I want to run one of them from command line, jest crashed.

To Reproduce

Steps to reproduce the behavior:

  1. run npx jest 1

Expected behavior

Jest run tests matched by 1.

It worked on macOS, but not Windows.

Actual behavior

Output:

TypeError: pattern.replace is not a function
    at replacePosixSep (C:\Users\Simon\Desktop\leetcode-solutions\node_modules\jest-config\build\normalize.js:591:20)
    at Array.map (<anonymous>)
    at buildTestPathPattern (C:\Users\Simon\Desktop\leetcode-solutions\node_modules\jest-config\build\normalize.js:594:36)
    at normalize (C:\Users\Simon\Desktop\leetcode-solutions\node_modules\jest-config\build\normalize.js:1119:32)
    at readConfig (C:\Users\Simon\Desktop\leetcode-solutions\node_modules\jest-config\build\index.js:220:68)
    at async readConfigs (C:\Users\Simon\Desktop\leetcode-solutions\node_modules\jest-config\build\index.js:401:26)
    at async runCLI (C:\Users\Simon\Desktop\leetcode-solutions\node_modules\@jest\core\build\cli\index.js:203:59)
    at async Object.run (C:\Users\Simon\Desktop\leetcode-solutions\node_modules\jest\node_modules\jest-cli\build\cli\index.js:216:37)

https://github.com/facebook/jest/blob/5dcc48075f22d581864f381f20bc8b257d2a73cd/packages/jest-config/src/normalize.ts#L419-L426

Looks like yargs will parse the 1 as a number, thus Number.prototype.replace is undefined.

Link to repl or repo (highly encouraged)

I believe it can be reproduced in any repo, even if you do not have a test named 1.

envinfo

  System:
    OS: Windows 10 10.0.18363
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  Binaries:
    Node: 13.7.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.13.6 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^25.1.0 => 25.1.0
@SimenB
Copy link
Member

SimenB commented Feb 6, 2020

That's odd! Wanna send a PR fixing it? we do patterns.map(replacePosixSep) there, just a .map before making sure everything is a string makes sense.

https://github.com/facebook/jest/blob/481077b09b05dc659b1fbd9ecf34a6486425208d/packages/jest-config/src/normalize.ts#L431

It does seem like a yargs bug, though - mind opening up an issue in the yargs repo?

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants