Skip to content

yarn lint fails for tests inside __tests__ #4397

Closed
@franciscolourenco

Description

@franciscolourenco

Version

3.10.0

Reproduction link

https://github.com/reproducing/reproduce-eslint-tests

Environment info

  System:
    OS: macOS 10.14.5
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 12.6.0 - /usr/local/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 75.0.3770.142
    Firefox: 67.0.4
    Safari: 12.1.1
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0
    @vue/babel-plugin-transform-vue-jsx:  1.0.0
    @vue/babel-preset-app:  3.10.0
    @vue/babel-preset-jsx:  1.1.0
    @vue/babel-sugar-functional-vue:  1.0.0
    @vue/babel-sugar-inject-h:  1.0.0
    @vue/babel-sugar-v-model:  1.0.0
    @vue/babel-sugar-v-on:  1.1.0
    @vue/cli-overlay:  3.10.0
    @vue/cli-plugin-babel: ^3.10.0 => 3.10.0
    @vue/cli-plugin-eslint: ^3.10.0 => 3.10.0
    @vue/cli-plugin-unit-jest: ^3.10.0 => 3.10.0
    @vue/cli-service: ^3.10.0 => 3.10.0
    @vue/cli-shared-utils:  3.10.0
    @vue/component-compiler-utils:  2.6.0 (3.0.0)
    @vue/preload-webpack-plugin:  1.1.1
    @vue/test-utils: 1.0.0-beta.29 => 1.0.0-beta.29
    @vue/web-component-wrapper:  1.2.0
    eslint-plugin-vue: ^5.0.0 => 5.2.3 (4.7.1)
    jest-serializer-vue:  2.0.2
    vue: ^2.6.10 => 2.6.10
    vue-eslint-parser:  5.0.0 (2.0.3)
    vue-hot-reload-api:  2.3.3
    vue-jest:  3.0.4
    vue-loader:  15.7.1
    vue-style-loader:  4.1.2
    vue-template-compiler: ^2.6.10 => 2.6.10
    vue-template-es2015-compiler:  1.9.1
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

  1. vue create with jest unit tests
  2. Create a unit test in src/**/__test__/*.js as in the docs: https://vue-test-utils.vuejs.org/guides/#testing-single-file-components-with-jest ; https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-unit-jest ;
  3. Run yarn lint

What is expected?

yarn lint passes

What is actually happening?

yarn run v1.17.3
$ vue-cli-service lint
error: 'describe' is not defined (no-undef) at src/components/__tests__/HelloWorld.spec.js:4:1:
  2 | import HelloWorld from '@/components/HelloWorld.vue'
  3 |
> 4 | describe('HelloWorld.vue', () => {
    | ^
  5 |   it('renders props.msg when passed', () => {
  6 |     const msg = 'new message'
  7 |     const wrapper = shallowMount(HelloWorld, {


error: 'it' is not defined (no-undef) at src/components/__tests__/HelloWorld.spec.js:5:3:
  3 |
  4 | describe('HelloWorld.vue', () => {
> 5 |   it('renders props.msg when passed', () => {
    |   ^
  6 |     const msg = 'new message'
  7 |     const wrapper = shallowMount(HelloWorld, {
  8 |       propsData: { msg }


error: 'expect' is not defined (no-undef) at src/components/__tests__/HelloWorld.spec.js:10:5:
   8 |       propsData: { msg }
   9 |     })
> 10 |     expect(wrapper.text()).toMatch(msg)
     |     ^
  11 |   })
  12 | })
  13 |

The /tests/unit/.eslintrc configures eslint for jest tests, but it only applies to tests in that subdirectory. It ignores tests in /src/**/__tests__/.

I chose to report this in vue-cli instead of vue-test-utils because I guess this needs to be fixed in the vue-cli-plugin-unit-jest generator.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions