vim-test / vim-test/vim-test

Testing vue-cli javascript components with jest and yarn: nearest does not work

Open
#324 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement feature
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-cli app and yarn automatically in this case and do everything right automatically without configuration? A starting point could be to search for @vue/cli-plugin-unit-jest in package.json to detect the use of jest in combination with vue-cli and a yarn.lock for yarn
  • If not, is adding a config option to the jest test 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.