Testing vue-cli javascript components with jest and yarn: nearest does not work
Nobody has claimed this yet.
- Dominant language
- Vim Script
- Stars
- 3.2k
- Forks
- 411
- Avg merge
- 1h 30m
- Merged PRs (30d)
- 5
Description
To run jest in vue-cli apps, one cannot use jest directly (see explanation):
Note that directly running jest will fail because the Babel preset requires hints to make your code work in Node.js, so you must run your tests with vue-cli-service test:unit.
To make this a little bit more complicated, I use yarn for my dependency management. This means to run tests I have to do:
yarn test:unit [jest options]
I configured vim-test to do this:
let test#javascript#jest#executable = 'yarn test:unit'
But the problem is that the jest script passes -- explicitly as a command line arg. For example the resulting command run is:
yarn test:unit --no-coverage -t '^ApplicationForm\.vue test descriptions$' -- tests/unit/components/ApplicationForm.spec.js
This unfortunately tests the whole file tests/unit/components/ApplicationForm.spec.js, not only the example I wanted to run. The reason is:
yarn outputs this warning:
Warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
It seems to ignore everything before the two dashes --, so in fact it runs:
yarn test:unit tests/unit/components/ApplicationForm.spec.js
When I remove the two dashes -- manually, it works like expected (and yarn does not output a warning):
yarn test:unit --no-coverage -t '^ApplicationForm\.vue test descriptions$' tests/unit/components/ApplicationForm.spec.js
The general questions are:
- Do you want to detect a
vue-cliapp andyarnautomatically in this case and do everything right automatically without configuration? A starting point could be to search for@vue/cli-plugin-unit-jestinpackage.jsonto detect the use ofjestin combination withvue-cliand ayarn.lockforyarn - If not, is adding a config option to the
jesttest runner to not add those two dashes--an option? (this would simply solve my problem at least) - How can this scenario be handled in a neat way?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the JavaScript Jest runner and its command construction, then compare the configured yarn test:unit command with the package.json and yarn.lock detection described in the issue. Check how the explicit -- is added and determine the intended configuration or automatic handling; done means Jest options and the test path are forwarded correctly for this Vue CLI and Yarn scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, vim
- Domain
- testing-qa, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100