Jest: Potential issue with Jest with moduleNameMapper

Created on 22 Sep 2017  路  8Comments  路  Source: facebook/jest


Do you want to request a feature or report a bug?

bug

What is the current behavior?

  • Configure moduleNameMapper to map a certain character as an alias (in my case I used @)
  • Run jest with --watch flag,
  • Accidentally import the wrong file by forgetting the / in @/myModule, i.e. @myModule
  • Jest in client will hang at Determining test suites to run... until you kill the process.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

What is the expected behavior?

  • Expected a Cannot find module error message

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

  • All configs and versions are in repo above.
  • Running on Mac OSx version 10.11.6
Bug

Most helpful comment

I can confirm this is happening to me as well, but from what I can tell, my moduleNameMapper isn't pointing to a non-existent file. I don't get any errors when I run Jest watchAll.

All 8 comments

Obviously, this is user error, but the accidental omission of '/' caused a serious headache. If this isn't a bug, at least this issue could be referred to help anyone else in similar situation.

I got this issue too in version 21. But in version 20, the error was displayed as expected.

Not sure if related, but I get Determining test suites to run..., and the the whole thing stalls. If I try --watchAll, everything works with no errors, but then hitting o and going to normal watch mode gives the same message again and hangs. Only happens in version 21. Downgrading to 20.0.4 fixes the problem.

I also just ran into this error after upgrading to Jest 21. It was similarly an issue where one of my moduleNameMappers pointed to a non-existant file.

I can confirm this is happening to me as well, but from what I can tell, my moduleNameMapper isn't pointing to a non-existent file. I don't get any errors when I run Jest watchAll.

I have the same problem but it's a bit more than an inconvenience...
I do have an angular project and use the path typescript feature to define paths as @shared or @books instead of the path.
So all my paths are @something and not @/something... will have to change all of them, I think...

same issue here, my setup:

 "moduleNameMapper": {
      "@app/(.*)": "<rootDir>/src/$1"
    }

This works fine when I run jest or jest --watchAll but hangs on Determining test suites to run... forever when I run jest --watch.

I'm seeing the same behavior as @Mohamed3on mentioned. I am using Jest 23.1.0.

What's odd is that if you kill and rerun the command it'll eventually start working immediately.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SimenB picture SimenB  路  69Comments

snapwich picture snapwich  路  77Comments

vitalibozhko picture vitalibozhko  路  138Comments

seibelj picture seibelj  路  116Comments

udbhav picture udbhav  路  236Comments