1
- jest . setTimeout ( 10000 )
1
+ jest . setTimeout ( 12000 )
2
2
jest . mock ( 'inquirer' )
3
3
4
4
const invoke = require ( '../lib/invoke' )
@@ -22,13 +22,15 @@ async function assertUpdates (project) {
22
22
const updatedPkg = JSON . parse ( await project . read ( 'package.json' ) )
23
23
expect ( updatedPkg . scripts . lint ) . toBe ( 'vue-cli-service lint' )
24
24
expect ( updatedPkg . devDependencies ) . toHaveProperty ( 'lint-staged' )
25
- expect ( updatedPkg . eslintConfig ) . toEqual ( {
26
- extends : [ 'plugin:vue/essential' , '@vue/airbnb' ]
27
- } )
28
25
expect ( updatedPkg . gitHooks ) . toEqual ( {
29
26
'pre-commit' : 'lint-staged'
30
27
} )
31
28
29
+ const eslintrc = JSON . parse ( await project . read ( '.eslintrc' ) )
30
+ expect ( eslintrc ) . toEqual ( {
31
+ extends : [ 'plugin:vue/essential' , '@vue/airbnb' ]
32
+ } )
33
+
32
34
const lintedMain = await project . read ( 'src/main.js' )
33
35
expect ( lintedMain ) . toMatch ( ';' ) // should've been linted in post-generate hook
34
36
}
@@ -58,3 +60,66 @@ test('invoke with prompts', async () => {
58
60
await invoke ( `eslint` , { } , project . dir )
59
61
await assertUpdates ( project )
60
62
} )
63
+
64
+ test ( 'invoke with existing files' , async ( ) => {
65
+ const project = await create ( `invoke-existing` , {
66
+ useConfigFiles : true ,
67
+ plugins : {
68
+ '@vue/cli-plugin-babel' : { } ,
69
+ '@vue/cli-plugin-eslint' : { config : 'base' }
70
+ }
71
+ } )
72
+ // mock install
73
+ const pkg = JSON . parse ( await project . read ( 'package.json' ) )
74
+ pkg . devDependencies [ '@vue/cli-plugin-eslint' ] = '*'
75
+ await project . write ( 'package.json' , JSON . stringify ( pkg , null , 2 ) )
76
+
77
+ // mock existing vue.config.js
78
+ await project . write ( 'vue.config.js' , `module.exports = { lintOnSave: false }` )
79
+
80
+ const eslintrc = JSON . parse ( await project . read ( '.eslintrc' ) )
81
+ expect ( eslintrc ) . toEqual ( {
82
+ extends : [ 'plugin:vue/essential' , 'eslint:recommended' ]
83
+ } )
84
+
85
+ await project . run ( `${ require . resolve ( '../bin/vue' ) } invoke eslint --config airbnb --lintOn save,commit` )
86
+
87
+ await assertUpdates ( project )
88
+ const updatedVueConfig = await project . read ( 'vue.config.js' )
89
+ expect ( updatedVueConfig ) . toMatch ( `module.exports = { lintOnSave: true }` )
90
+ } )
91
+
92
+ test ( 'invoke with existing files (yaml)' , async ( ) => {
93
+ const project = await create ( `invoke-existing` , {
94
+ useConfigFiles : true ,
95
+ plugins : {
96
+ '@vue/cli-plugin-babel' : { } ,
97
+ '@vue/cli-plugin-eslint' : { config : 'base' }
98
+ }
99
+ } )
100
+ // mock install
101
+ const pkg = JSON . parse ( await project . read ( 'package.json' ) )
102
+ pkg . devDependencies [ '@vue/cli-plugin-eslint' ] = '*'
103
+ await project . write ( 'package.json' , JSON . stringify ( pkg , null , 2 ) )
104
+
105
+ const eslintrc = JSON . parse ( await project . read ( '.eslintrc' ) )
106
+ expect ( eslintrc ) . toEqual ( {
107
+ extends : [ 'plugin:vue/essential' , 'eslint:recommended' ]
108
+ } )
109
+
110
+ await project . rm ( `.eslintrc` )
111
+ await project . write ( `.eslintrc.yml` , `
112
+ extends:
113
+ - 'plugin:vue/essential'
114
+ - 'eslint:recommended'
115
+ ` . trim ( ) )
116
+
117
+ await project . run ( `${ require . resolve ( '../bin/vue' ) } invoke eslint --config airbnb` )
118
+
119
+ const updated = await project . read ( '.eslintrc.yml' )
120
+ expect ( updated ) . toMatch ( `
121
+ extends:
122
+ - 'plugin:vue/essential'
123
+ - '@vue/airbnb'
124
+ ` . trim ( ) )
125
+ } )
0 commit comments