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

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.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 19 (6 by maintainers)

Commits related to this issue

Most upvoted comments

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…

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.