From 3a078b34bdacf7e43b8f20c64ecc9d7c49bd3ed5 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 3 Jan 2020 15:31:47 +0800 Subject: [PATCH 1/2] fix: fix applyESLint when eslint plugin is added after unit test plugins closes #5017 --- .../cli-plugin-unit-jest/generator/index.js | 34 +++++++++++-------- .../cli-plugin-unit-mocha/generator/index.js | 30 ++++++++-------- 2 files changed, 33 insertions(+), 31 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/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 + } + } + ] + } }) } From 2228fc0faa6a40dd0740bf2bbb02b8d42dbaf64d Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Fri, 3 Jan 2020 15:55:07 +0800 Subject: [PATCH 2/2] test: update test for mocha generator --- .../@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js | 1 - 1 file changed, 1 deletion(-) 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'`)