jest-transform: testRegex value shows empty object instead of RegExp object
See original GitHub issue🐛 Bug Report
Custom transformer receives jest config string via getCacheKey. In ts-jest recently we rely on testRegex to do some logic. However, the value of testRegex which is passed to transformer is unusable. Instead of receiving the real value of the regex, transformer receives it as [{}]
Related to https://github.com/kulshekhar/ts-jest/issues/1509
To Reproduce
Steps to reproduce the behavior:
- Clone the repo and switch to branch test-regex-transformer .
- Install dependencies with
yarn, runyarn testand see the exception - Trace the exception back to
getCacheKeyand inspectjestConfigStr, observe the value in the picture below (red circle)
- Trace back to
ScriptTransformer.jsconstructor, observe the input value ofconfigis
- The value after this line https://github.com/facebook/jest/blob/2edd5c4724cfadb944a6a233a7ad8fb5a3e05996/packages/jest-transform/src/ScriptTransformer.ts#L72 becomes
[{}]and it is unusable.
Expected behavior
testRegex value which is passed to transformer should be usable and retain its original value.
Link to repl or repo (highly encouraged)
https://github.com/ahnpnl/ts-jest-babel-example/tree/test-regex-transformer
envinfo
System:
OS: macOS 10.15.4
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
Node: 12.16.1 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
npmPackages:
jest: ^25.2.7 => 25.2.7
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Regex value is converted into an empty object after sending it ...
The problem with your current approach is that you are passing /^Test$/i , which is a JavaScript regex literal.
Read more >Configuring Jest
Any docblock pragmas in test files will be passed to the environment constructor and can be used for per-test configuration. If the pragma...
Read more >RegExp - JavaScript - MDN Web Docs - Mozilla
Chrome Edge
RegExp Full support. Chrome1. Toggle history Full support. Edge12. Toggle history
@@match Full support. Chrome50. Toggle history Full support. Edge13. Toggle history
@@matchAll Full...
Read more >@jest/transform | Yarn - Package Manager
... cjs modules as objects so they can be mocked (#13513); [jest-worker] Throw an error instead of hanging when jest workers terminate unexpectedly...
Read more >JavaScript RegExp test() Method - W3Schools
Definition and Usage. The test() method tests for a match in a string. If it finds a match, it returns true, otherwise it...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yeah, feel free to ignore it if you want - it’s just there as a convenience
I discovered that
toMatchInlineSnapshotandtoMatchSnapshotcan handle serializingRegExpobject correctly. Maybe the codes behind those 2 functions for serializing can be applied to this situation ?Updated I’ve tested
serializefromjest-snapshot.serializeproduces a nice string, but thenJSON.parsedoesn’t work with that string.