1- jest . setTimeout ( 10000 )
1+ jest . setTimeout ( 12000 )
22jest . mock ( 'inquirer' )
33
44const invoke = require ( '../lib/invoke' )
@@ -22,13 +22,15 @@ async function assertUpdates (project) {
2222 const updatedPkg = JSON . parse ( await project . read ( 'package.json' ) )
2323 expect ( updatedPkg . scripts . lint ) . toBe ( 'vue-cli-service lint' )
2424 expect ( updatedPkg . devDependencies ) . toHaveProperty ( 'lint-staged' )
25- expect ( updatedPkg . eslintConfig ) . toEqual ( {
26- extends : [ 'plugin:vue/essential' , '@vue/airbnb' ]
27- } )
2825 expect ( updatedPkg . gitHooks ) . toEqual ( {
2926 'pre-commit' : 'lint-staged'
3027 } )
3128
29+ const eslintrc = JSON . parse ( await project . read ( '.eslintrc' ) )
30+ expect ( eslintrc ) . toEqual ( {
31+ extends : [ 'plugin:vue/essential' , '@vue/airbnb' ]
32+ } )
33+
3234 const lintedMain = await project . read ( 'src/main.js' )
3335 expect ( lintedMain ) . toMatch ( ';' ) // should've been linted in post-generate hook
3436}
@@ -58,3 +60,66 @@ test('invoke with prompts', async () => {
5860 await invoke ( `eslint` , { } , project . dir )
5961 await assertUpdates ( project )
6062} )
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