Skip to content

Commit

Permalink
fix applyESLint when eslint plugin is added after unit test plugins (#…
Browse files Browse the repository at this point in the history
…5028)

* fix: fix applyESLint when eslint plugin is added after unit test plugins

closes #5017

* test: update test for mocha generator
  • Loading branch information
sodatea committed Jan 27, 2020
1 parent 103d0f1 commit 51cdebd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
34 changes: 19 additions & 15 deletions packages/@vue/cli-plugin-unit-jest/generator/index.js
Expand Up @@ -18,28 +18,32 @@ module.exports = (api, _, __, invoking) => {
})

if (api.hasPlugin('eslint')) {
api.extendPackage({
eslintConfig: {
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)'
],
env: {
jest: true
}
}
]
}
})
applyESLint(api)
}

if (api.hasPlugin('typescript')) {
applyTS(api, invoking)
}
}

const applyESLint = module.exports.applyESLint = api => {
api.extendPackage({
eslintConfig: {
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)'
],
env: {
jest: true
}
}
]
}
})
}

const applyTS = (module.exports.applyTS = (api, invoking) => {
api.extendPackage({
jest: {
Expand Down
Expand Up @@ -17,7 +17,6 @@ test('base', async () => {

expect(pkg.scripts['test:unit']).toBe('vue-cli-service test:unit')
expect(pkg.devDependencies).toHaveProperty('@vue/test-utils')
expect(files['tests/unit/.eslintrc.js']).toMatch('mocha: true')

const spec = files['tests/unit/example.spec.js']
expect(spec).toMatch(`import { expect } from 'chai'`)
Expand Down
30 changes: 14 additions & 16 deletions packages/@vue/cli-plugin-unit-mocha/generator/index.js
Expand Up @@ -15,18 +15,6 @@ module.exports = (api, _, __, invoking) => {

if (api.hasPlugin('eslint')) {
applyESLint(api)
api.extendPackage({
eslintConfig: {
overrides: [
{
files: ['**/__tests__/*.{j,t}s?(x)'],
env: {
mocha: true
}
}
]
}
})
}

if (api.hasPlugin('typescript')) {
Expand All @@ -35,10 +23,20 @@ module.exports = (api, _, __, invoking) => {
}

const applyESLint = module.exports.applyESLint = api => {
api.render(files => {
files['tests/unit/.eslintrc.js'] = api.genJSConfig({
env: { mocha: true }
})
api.extendPackage({
eslintConfig: {
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)'
],
env: {
mocha: true
}
}
]
}
})
}

Expand Down

0 comments on commit 51cdebd

Please sign in to comment.