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

VueCLI forces Jest's testMatch option #1067

Closed
Ldoppea opened this issue Apr 3, 2018 · 8 comments
Closed

VueCLI forces Jest's testMatch option #1067

Ldoppea opened this issue Apr 3, 2018 · 8 comments
Labels

Comments

@Ldoppea
Copy link

Ldoppea commented Apr 3, 2018

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 [email protected]. This commit changed the test detection behavior : 2c61d23#diff-17aae08cfc13cba07661681220ddd985 (I do not use typescript)

@dhensche
Copy link
Contributor

dhensche commented 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

dhensche added a commit to dhensche/vue-cli that referenced this issue Apr 3, 2018
@LinusBorg LinusBorg added the bug label Apr 4, 2018
@laander
Copy link

laander commented Apr 13, 2018

Just want to add that besides package.json, we should also respect options set in jest.config.js 👌

@robcresswell
Copy link

robcresswell commented Apr 16, 2018

What makes this slightly worse is that the forced option isn't even a superset of Jests own default. For example, when testing with other Vue applications I've always just suppled a test.js file in the same directory as the component it's testing (less directory hopping, encourages testing at same time as component design, file name is self explanatory, etc.)

For example, I tend to use something like:

src/components/my-component
├── index.js
├── my-component.vue
└── test.js

With Vue CLI, this doesn't work at all, which I'd consider a regression. Is there any technical reason to force override Jests own default?

@posva
Copy link
Member

posva commented Apr 16, 2018

I think it's easier to just remove that code from the cli runtime and move it to the config generated by the cli

@robcresswell
Copy link

That sounds like a sensible solution to me 😇

@dhensche
Copy link
Contributor

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)

@laander
Copy link

laander commented Apr 16, 2018

Much better solution @dhensche ! 🤘
An added benefit is that other tooling (e.g. the Jest extension for VSCode) works out of the box.

@Ldoppea
Copy link
Author

Ldoppea commented Apr 25, 2018

Thank you @dhensche 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants