Skip to content

Commit 81efc48

Browse files
haoqunjiangmactanxin
authored andcommitted
fix applyESLint when eslint plugin is added after unit test plugins (vuejs#5028)
* fix: fix applyESLint when eslint plugin is added after unit test plugins closes vuejs#5017 * test: update test for mocha generator
1 parent 413b14d commit 81efc48

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

packages/@vue/cli-plugin-unit-jest/generator/index.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,32 @@ module.exports = (api, _, __, invoking) => {
1818
})
1919

2020
if (api.hasPlugin('eslint')) {
21-
api.extendPackage({
22-
eslintConfig: {
23-
overrides: [
24-
{
25-
files: [
26-
'**/__tests__/*.{j,t}s?(x)',
27-
'**/tests/unit/**/*.spec.{j,t}s?(x)'
28-
],
29-
env: {
30-
jest: true
31-
}
32-
}
33-
]
34-
}
35-
})
21+
applyESLint(api)
3622
}
3723

3824
if (api.hasPlugin('typescript')) {
3925
applyTS(api, invoking)
4026
}
4127
}
4228

29+
const applyESLint = module.exports.applyESLint = api => {
30+
api.extendPackage({
31+
eslintConfig: {
32+
overrides: [
33+
{
34+
files: [
35+
'**/__tests__/*.{j,t}s?(x)',
36+
'**/tests/unit/**/*.spec.{j,t}s?(x)'
37+
],
38+
env: {
39+
jest: true
40+
}
41+
}
42+
]
43+
}
44+
})
45+
}
46+
4347
const applyTS = (module.exports.applyTS = (api, invoking) => {
4448
api.extendPackage({
4549
jest: {

packages/@vue/cli-plugin-unit-mocha/__tests__/mochaGenerator.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ test('base', async () => {
1717

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

2221
const spec = files['tests/unit/example.spec.js']
2322
expect(spec).toMatch(`import { expect } from 'chai'`)

packages/@vue/cli-plugin-unit-mocha/generator/index.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@ module.exports = (api, _, __, invoking) => {
1515

1616
if (api.hasPlugin('eslint')) {
1717
applyESLint(api)
18-
api.extendPackage({
19-
eslintConfig: {
20-
overrides: [
21-
{
22-
files: ['**/__tests__/*.{j,t}s?(x)'],
23-
env: {
24-
mocha: true
25-
}
26-
}
27-
]
28-
}
29-
})
3018
}
3119

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

3725
const applyESLint = module.exports.applyESLint = api => {
38-
api.render(files => {
39-
files['tests/unit/.eslintrc.js'] = api.genJSConfig({
40-
env: { mocha: true }
41-
})
26+
api.extendPackage({
27+
eslintConfig: {
28+
overrides: [
29+
{
30+
files: [
31+
'**/__tests__/*.{j,t}s?(x)',
32+
'**/tests/unit/**/*.spec.{j,t}s?(x)'
33+
],
34+
env: {
35+
mocha: true
36+
}
37+
}
38+
]
39+
}
4240
})
4341
}
4442

0 commit comments

Comments
 (0)