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

yarn lint fails for tests inside __tests__ #4397

Closed
franciscolourenco opened this issue Aug 5, 2019 · 1 comment
Closed

yarn lint fails for tests inside __tests__ #4397

franciscolourenco opened this issue Aug 5, 2019 · 1 comment

Comments

@franciscolourenco
Copy link

franciscolourenco commented Aug 5, 2019

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.

@LinusBorg
Copy link
Member

we could probably extend the base eslint config with something like:

{
  overrides: [
    {
      files: "**/__tests__/*.(js|jsx|ts|tsx)",
      env: {
        jest: true
      }
    }
  ]
}

...and do the same for the mocha plugin.

@LinusBorg LinusBorg self-assigned this Aug 6, 2019
LinusBorg added a commit that referenced this issue Aug 16, 2019
 for **/tests/** subfolders

close #4397
haoqunjiang pushed a commit that referenced this issue Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants