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.

moduleNameMapper of Jest config links to files that do not exist

See original GitHub issue

When creating a new project with the Jest test harness (alone or with other harnesses) I run into errors when trying to run the tests.

To Reproduce Steps to reproduce the behavior:

  1. Create a new project: quasar create my_project --branch next
    • Sass with SCSS syntax
    • ESLint (Prettier)
    • Vuex
    • Axios
    • Vue-i18n
    • use Yarn
  2. cd my_project
  3. Install test harnesses: quasar ext add @quasar/testing
    • Jest
    • Cypress
    • Quality
    • Security
    • Overwrite babel.config.js and use additional .babelrc
    • Extra "scripts" in your package.json
    • SFC webpack <test> loader
    • Cypress: extra "scripts" in your package.json
    • Lighthouse: extra "scripts" in your package.json
    • install the OWASP ZAP Heads Up Display
    • configure with Chrome
  4. Run quasar test --unit jest
  5. See error:
 FAIL  test/jest/__tests__/App.spec.js
  ● Test suite failed to run

    Configuration error:
    
    Could not locate module vue mapped as:
    vue/dist/vue.common.js.
    
    Please check your configuration for these entries:
    {
      "moduleNameMapper": {
        "/^vue$/": "vue/dist/vue.common.js"
      },
      "resolver": undefined
    }

      at createNoMappedModuleFoundError (node_modules/jest-resolve/build/index.js:551:17)
      at Object.<anonymous> (node_modules/@vue/test-utils/dist/vue-test-utils.js:5:11)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.004 s
Ran all test suites.

The files that appear in node_modules/vue/dist/ are:

vue.cjs.js
vue.cjs.prod.js
vue.d.ts
vue.esm-browser.js
vue.esm-browser.prod.js
vue.esm-bundler.js
vue.global.js
vue.global.prod.js
vue.runtime.esm-browser.js
vue.runtime.esm-browser.prod.js
vue.runtime.esm-bundler.js
vue.runtime.global.js
vue.runtime.global.prod.js

If I map to another file instead, I get the following error:

Cannot find module 'vue-template-compiler' from 'node_modules/@vue/test-utils/dist/vue-test-utils.js'

    Require stack:
      node_modules/@vue/test-utils/dist/vue-test-utils.js
      test/jest/__tests__/App.spec.js

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11)
      at Object.<anonymous> (node_modules/@vue/test-utils/dist/vue-test-utils.js:6:27)

In that directory, vue-template-compiler is not present either.

Expected behavior The test suite should run the tests without configuration errors.

Platform Quasar Version: 3.0.0-beta.6 @quasar/app Version: 2.0.8 OS: macOS 10.15.7 Node: 12.20.0 NPM: 7.5.0 Yarn: 1.22.10

Additional context I have reproduced this several times from fresh projects.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

0reactions
cbleekcommented, Jul 28, 2021

same issue here.

maybe the issue should be reopened

Read more comments on GitHub >

github_iconTop Results From Across the Web

moduleNameMapper of Jest config links to files that do not ...
When creating a new project with the Jest test harness (alone or with other harnesses) I run into errors when trying to run...
Read more >
Jest moduleNameMapper to find files: "resolver": undefined
Based on the log I guess your configuration is /^components\/(.*)$/: "<rootDir>/src/components$1" which is different from your given code is ...
Read more >
Configuring Jest
Thresholds for globs are applied to all files matching the glob. If the file specified by path is not found, an error is...
Read more >
Unit Testing
However, there are a few features of the Gatsby build process that mean the standard Jest setup doesn't quite work. This guide shows...
Read more >
Configuring package.json · Jest
Jest's configuration can be defined in the package.json file of your ... When using the --config option, the JSON file must not contain...
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