Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors in moduleNameMapper configuration seemingly ignored #1888

Closed
p-decoraid opened this issue Oct 6, 2016 · 10 comments · Fixed by #3567
Closed

Errors in moduleNameMapper configuration seemingly ignored #1888

p-decoraid opened this issue Oct 6, 2016 · 10 comments · Fixed by #3567

Comments

@p-decoraid
Copy link
Contributor

p-decoraid commented Oct 6, 2016

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

Bug

What is the current behavior?

I was following https://facebook.github.io/jest/docs/tutorial-webpack.html and I had the following in my package.json:

  "jest": {
    "moduleNameMapper": {
       "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/mocks/filemock.js",
            "\\.(css|less)$": "identity-obj-proxy"
    }
  },

However, I have not installed identity-obj-proxy (due to having to upgrade node from 5 to 6 for it to work).

In this configuration, running tests produces:

butler% npm test

> @ test /home/me/apps/frontend
> jest

 FAIL  library/paymentform.test.js
  ● Test suite failed to run

    /home/me/apps/frontend/library/paymentform.css:1
    ({"Object.":function(module,exports,require,__dirname,__filename,global,jest){.form-reactbuttons {
                                                                                             ^
    SyntaxError: Unexpected token .
      
      at transformAndBuildScript (node_modules/jest-runtime/build/transform.js:284:10)
      at Object. (library/paymentform.js:2:46)
      at Object. (library/paymentform.test.js:3:46)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.045s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

I'm not 100% certain whether the "include CSS text verbatim in a JS module" is the behavior when there is no moduleNameMapper configuration at all, or it's something else, but when I installed identity-obj-proxy this error went away and the tests started running.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal repository on GitHub that we can npm install and npm test.

I should be able to create this if necessary.

What is the expected behavior?

I expected to be told that identity-obj-proxy is missing in some fashion.

I also expected the tests to not be attempted to run at all, given that the configuration was bogus.

Run Jest again with --debug and provide the full configuration it prints. Please mention your node and npm version and operating system.

butler% ./node_modules/.bin/jest --debug
jest version = 16.0.1
test framework = jasmine2
config = {
  "moduleNameMapper": [
    [
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$",
      "/home/me/apps/frontend/mocks/filemock.js"
    ],
    [
      "\\.(css|less)$",
      "identity-obj-proxy"
    ]
  ],
  "rootDir": "/home/me/apps/frontend",
  "name": "-home-me-apps-frontend",
  "setupFiles": [],
  "testRunner": "/home/me/apps/frontend/node_modules/jest-jasmine2/build/index.js",
  "scriptPreprocessor": "/home/me/apps/frontend/node_modules/babel-jest/build/index.js",
  "usesBabelJest": true,
  "automock": false,
  "bail": false,
  "browser": false,
  "cacheDirectory": "/tmp/jest",
  "clearMocks": false,
  "coveragePathIgnorePatterns": [
    "/node_modules/"
  ],
  "coverageReporters": [
    "json",
    "text",
    "lcov",
    "clover"
  ],
  "globals": {},
  "haste": {
    "providesModuleNodeModules": []
  },
  "mocksPattern": "__mocks__",
  "moduleDirectories": [
    "node_modules"
  ],
  "moduleFileExtensions": [
    "js",
    "json",
    "jsx",
    "node"
  ],
  "modulePathIgnorePatterns": [],
  "noStackTrace": false,
  "notify": false,
  "preset": null,
  "preprocessorIgnorePatterns": [
    "/node_modules/"
  ],
  "resetModules": false,
  "testEnvironment": "jest-environment-jsdom",
  "testPathDirs": [
    "/home/me/apps/frontend"
  ],
  "testPathIgnorePatterns": [
    "/node_modules/"
  ],
  "testRegex": "(/__tests__/.*|\\.(test|spec))\\.jsx?$",
  "testURL": "about:blank",
  "timers": "real",
  "useStderr": false,
  "verbose": null,
  "watch": false,
  "cache": true,
  "watchman": true,
  "testcheckOptions": {
    "times": 100,
    "maxSize": 200
  }
}
butler% node -v
v6.7.0
butler% uname -a
Linux butler 4.7.0-1-amd64 #1 SMP Debian 4.7.5-1 (2016-09-26) x86_64 GNU/Linux
@ghost
Copy link

ghost commented Oct 15, 2016

bump - same issue here - configuration almost identical to the above

@stefanfisk
Copy link

Same here, this just cost me two hours of debugging ,ó_Ò,

@thymikee
Copy link
Collaborator

thymikee commented Dec 8, 2016

@cpojer we should probably validate if the module passed to moduleNameMapper actually exists

@ollwenjones
Copy link

👍 Just got hung up on this (or something very similar) for a while, because I had a misspelling (styleMocks vs styleMock). It would be nice if there was some meaningful error when a moduleNameMapper pattern's file didn't resolve, rather than that pattern getting skipped.

@lindgr3n
Copy link
Contributor

@thymikee Giving this a shoot.
Im guessing that in jest-resolve/src/index.js in _resolveStubModuleName() that if
this.getModule(moduleName) || Resolver.findNodeModule(moduleName, { basedir: dirname, browser: this._options.browser, extensions, moduleDirectory, paths, });
Is giving null you should provide a console.error message?

@thymikee
Copy link
Collaborator

@lindgr3n awesome!
Yea, I think this is a good place for this. You can throw ValidationError from jest-validate package for nicer formatting of the message. We can discuss the details after you send a PR (ideally with a test) 🙂

@lindgr3n
Copy link
Contributor

Great, working on the PR.

@samsch
Copy link

samsch commented Jun 6, 2017

I hit this issue today. Any progress on the patch?

@lindgr3n
Copy link
Contributor

lindgr3n commented Jun 6, 2017

Have the PR here #3567 with the fix. Waiting for it to be merged.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants