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.

transform does not happen on matched moduleNameMapper file.

See original GitHub issue

🐛 Bug Report

transform isn’t ran on matched modules of moduleNameMapper.

To Reproduce

Read the repository’s readMe.md (npm install && npm test)

Expected behavior

core.ls gets compiled using jest.ls.transformer and there is no error.

Link to repl or repo

https://github.com/ATheCoder/jest-bug

envinfo

  System:
    OS: macOS 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  Binaries:
    Node: 10.16.1 - /usr/local/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
SimenBcommented, Aug 26, 2019

The issue is that your core regex matches an internal ./core module in Babel: https://github.com/babel/babel/blob/a2bf68981fbe26a5574607c526818868562fb1f4/packages/babel-types/src/definitions/index.js#L3. This confuses the resolver, which returns your core.ls rather than core.js within Babel. This diff makes your tests pass on my machine:

diff --git i/package.json w/package.json
index f9e730b..7c4c284 100644
--- i/package.json
+++ w/package.json
@@ -16,7 +16,7 @@
     "moduleFileExtensions": ["ls","js", "json", "jsx", "ts", "tsx", "node"],
     "transformIgnorePatterns" : ["<rootDir>/node_modules/"],
     "moduleNameMapper" : {
-      "core": "<rootDir>/dank/core"
+      "^core$": "<rootDir>/dank/core"
     },
     "transform": {
       "^.+\\.ls$": "<rootDir>/jest.ls.transformer"

We should probably ignore moduleNameMapper during an internal require…

https://github.com/facebook/jest/blob/8c169d20add61c8831162d8347d2710c07b6b0ef/packages/jest-runtime/src/index.ts#L290-L294 ^ options.isInternalModule is true in this case, but the resolver cares about the user supplied config

@thymikee @jeysal thoughts on that?

0reactions
github-actions[bot]commented, May 3, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jest unexpected token when importing css - Stack Overflow
The problem is that Jest is hitting these CSS imports and trying to parse them as if they were JavaScript. The "Unexpected token...
Read more >
Configuring Jest
While code transformation is applied to the linked setup-file, Jest will not transform any code in node_modules . This is due to the...
Read more >
Configuring package.json · Jest
An array of regexp pattern strings that are matched against all source file paths before transformation. If the test path matches any of...
Read more >
Configuring Jest compiled - w3resource
When you are using the --config option, the JSON file should not contain a ... setup-file, Jest does not transform any code in...
Read more >
jest-preset-angular - npm
By default Jest doesn't transform node_modules , because they should be valid JavaScript files. However, it happens that library authors assume ...
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