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.

VueCLI forces Jest's testMatch option

See original GitHub issue

Version

3.0.0-beta.6

Reproduction link

https://github.com/Ldoppea/vue-cli-jest-testmatch

Steps to reproduce

Init project with following options :

Vue CLI v3.0.0-beta.6
? Please pick a preset: Manually select features
? Check the features needed for your project: Unit
? Pick a unit testing solution: Jest
? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? In package.json
? Save this as a preset for future projects? (Y/n) n

Move /tests/unit/HelloWorld.spec.js in /src/components/

Add testMatch in package.json Jest category :

    "testMatch": [
      "test/**/*.spec.js", 
      "src/**/*.spec.js"
    ]

Run npm run test

What is expected?

HelloWorld.spec.js should be tested

What is actually happening?

No test is found by Jest. Get the following error :

No tests found
In D:\Work\test\vue\testJest
  6 files checked.
  testMatch: D:\Work\test\vue\testJest\(tests\unit\**\*.spec.(ts|tsx|js)|**\__tests__\*.(ts|tsx|js)) - 0 matches
  testPathIgnorePatterns: \\node_modules\\ - 6 matches
Pattern:  - 0 matches
 ERROR  jest exited with code 1.

testMatch still has the value forced by vueCLI


I was able to run my tests from src folder and without using testMatch on vueCLI@3.0.0-beta.4. This commit changed the test detection behavior : https://github.com/vuejs/vue-cli/commit/2c61d236d77dfcb22b4560afe4c957ddf45b4337#diff-17aae08cfc13cba07661681220ddd985 (I do not use typescript)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
dhenschecommented, Apr 3, 2018

It appears that the plugin always sets the testMatch to [`--testMatch`, `<rootDir>/(tests/unit/**/*.spec.(ts|tsx|js)|**/__tests__/*.(ts|tsx|js))`] if none is specified via a command line argument, instead of respecting anything set in package.json. If we would like to respect those configurations, it appears to be an easy enough tweak I would gladly contribute

5reactions
dhenschecommented, Apr 16, 2018

With my current PR (#1069) that is what I ended up doing. I moved the testMatch pattern over to the generator so that it goes into the package.json or jest.config.js (depending on how the user wants their config files laid out)

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue/cli-plugin-unit-jest
Run unit tests with Jest. Default testMatch is <rootDir>/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)) which matches ...
Read more >
Jest CLI Options
Jest CLI Options. The jest command line runner has a number of useful options. You can run jest --help to view all available...
Read more >
@vue/cli-plugin-unit-jest | Yarn - Package Manager
Run unit tests with Jest. Default testMatch is <rootDir>/(tests/unit/**/*.spec.(js|jsx|ts|tsx) ...
Read more >
vue-cli default unit tests "Unexpected token {" error
I just asked a similar question, here ( there is an answer in that one towards the bottom ). I see in your...
Read more >
Configuring Jest compiled - w3resource
Always remember that the resulting configuration must be JSON-serializable. When you are using the --config option, the JSON file should not ...
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