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-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:

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:open
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Apr 7, 2020

or what do you suggest for us regarding to the usage with string config ?

Yeah, feel free to ignore it if you want - it’s just there as a convenience

0reactions
ahnpnlcommented, Jul 8, 2020

I discovered that toMatchInlineSnapshot and toMatchSnapshot can handle serializing RegExp object correctly. Maybe the codes behind those 2 functions for serializing can be applied to this situation ?

Updated I’ve tested serialize from jest-snapshot. serialize produces a nice string, but then JSON.parse doesn’t work with that string.

Read more comments on GitHub >

github_iconTop 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 >

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