question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest 23 --config breaks create-react-app on Windows

See original GitHub issue

I am trying to use Jest 23 in create-react-app@next https://github.com/facebook/create-react-app/pull/4555 In particular I’ve found windows config to break after the upgrade. The specific part of config being generated is https://github.com/facebook/create-react-app/blob/next/packages/react-scripts/scripts/utils/createJestConfig.js#L47 In Jest 22.4.3 the regex is [\\\\\\\\\\\\]node_modules[\\\\\\\\\\\\].+\.(js|jsx|mjs)$|^.+\.module\.(css|sass|scss)$/ (12 slashes) in jest-runtime In Jest 23 the error is Invalid regular expression: /[\\\\\]node_modules[\\\\\].+\.(js|jsx|mjs)$|^.+\.module\.(css|sass|scss)$/

Does not repo on other platforms.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:19 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
tshinniccommented, Jun 6, 2018

Speculating…

jest-config/build/index.js::readConfig() calls normalize() on incoming option values and defaults, including transformIgnorePatterns.

When normalize() sees options.transformIgnorePatterns: "[/\\]node_modules[/\\].+\.(js|jsx|mjs)$" it converts that to value: "[\\\\\]node_modules[\\\\\].+\.(js|jsx|mjs)$"

Note that really is 5 back slashes, 2 each from each incoming back slash and 1 from the forward slash. An odd number of back slashes produces much unhappiness for a later new RegExp().

normalize() uses normalizeUnmockedModulePathPatterns() which uses ‘jest-regex-util’. Checking the results returned by that module’s code finds:

> "/\\\\".replace(/(\/|\\(?![[\]{}()*+?.^$|]))/g, '\\\\').split('')
          [ '\\', '\\', '\\', '\\', '\\', '\\' ]
> "[/\\\\]".replace(/(\/|\\(?![[\]{}()*+?.^$|]))/g, '\\\\').split('')
          [ '[', '\\', '\\', '\\', '\\', '\\', ']' ]

so path separators are okay unless they happen to have char class delimiters around them. Perhaps the wrong routine is being used? Or rather, that one routine is being called for incompatible uses.

Oh, the rules wrt to ‘[’ and ‘]’ got changed by edd95fc4df8d6c539bfe21881e922fa75f9c5b69 and #5941

You probably do want separate routines…

1reaction
ThakurKarthikcommented, Jun 17, 2018

I have downgraded jest and jest-cli from v 23.1.0 to v 22.4.4.Now it’s working fine.This error is only on windows platform.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest from create-react-app not running on Windows
create -react-app is CLI that generates react-scripts pre-configured setup that includes Webpack and Jest configuration, among other things.
Read more >
Troubleshooting - Jest
If you are using Facebook's create-react-app , you can debug your Jest tests with the following configuration: { "version": "0.2.0",
Read more >
First class support for Create React App - Jest Preview
Currently, there is no way to customize CRA's jest.config.js file easily. So, Jest Preview bundles a few CLIs to make integrating Jest Preview ......
Read more >
Electron and React integration done right - Patrick Passarella
First, create a folder, outside of the src folder, named electron , and a main.js file inside it. Change the main property in...
Read more >
Introducing the New JSX Transform – React Blog
Together with the React 17 release, we've wanted to make a few improvements to the JSX transform, but we didn't want to break...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found