From 51cdebdadfa44bbefa6ed3ddf26e2b667196da35 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Mon, 27 Jan 2020 21:44:36 +0800 Subject: [PATCH] fix applyESLint when eslint plugin is added after unit test plugins (#5028) * fix: fix applyESLint when eslint plugin is added after unit test plugins closes #5017 * test: update test for mocha generator --- .../cli-plugin-unit-jest/generator/index.js | 34 +++++++++++-------- .../__tests__/mochaGenerator.spec.js | 1 - .../cli-plugin-unit-mocha/generator/index.js | 30 ++++++++-------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/packages/@vue/cli-plugin-unit-jest/generator/index.js b/packages/@vue/cli-plugin-unit-jest/generator/index.js index 6894361c37..c2f6bb3b7e 100644 --- a/packages/@vue/cli-plugin-unit-jest/generator/index.js +++ b/packages/@vue/cli-plugin-unit-jest/generator/index.js @@ -18,21 +18,7 @@ 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')) { @@ -40,6 +26,24 @@ module.exports = (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: { diff --git a/packages/@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js b/packages/@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js index 3a78d8ca5d..572de94703 100644 --- a/packages/@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js +++ b/packages/@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js @@ -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'`) diff --git a/packages/@vue/cli-plugin-unit-mocha/generator/index.js b/packages/@vue/cli-plugin-unit-mocha/generator/index.js index c3943d9e2f..f37708842c 100644 --- a/packages/@vue/cli-plugin-unit-mocha/generator/index.js +++ b/packages/@vue/cli-plugin-unit-mocha/generator/index.js @@ -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')) { @@ -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 + } + } + ] + } }) }