@@ -4,8 +4,12 @@ jest.mock('inquirer')
4
4
const invoke = require ( '../lib/invoke' )
5
5
const { expectPrompts } = require ( 'inquirer' )
6
6
const create = require ( '@vue/cli-test-utils/createTestProject' )
7
- const stringifyJS = require ( 'javascript-stringify' )
8
- const toJS = v => `module.exports = ${ stringifyJS ( v , null , 2 ) } `
7
+
8
+ const parseJS = file => {
9
+ const res = { }
10
+ ; ( new Function ( 'module' , file ) ) ( res )
11
+ return res . exports
12
+ }
9
13
10
14
async function createAndInstall ( name ) {
11
15
const project = await create ( name , {
@@ -28,11 +32,11 @@ async function assertUpdates (project) {
28
32
'pre-commit' : 'lint-staged'
29
33
} )
30
34
31
- const eslintrc = await project . read ( '.eslintrc.js' )
32
- expect ( eslintrc ) . toEqual ( toJS ( {
35
+ const eslintrc = parseJS ( await project . read ( '.eslintrc.js' ) )
36
+ expect ( eslintrc ) . toEqual ( {
33
37
root : true ,
34
38
extends : [ 'plugin:vue/essential' , '@vue/airbnb' ]
35
- } ) )
39
+ } )
36
40
37
41
const lintedMain = await project . read ( 'src/main.js' )
38
42
expect ( lintedMain ) . toMatch ( ';' ) // should've been linted in post-generate hook
@@ -80,11 +84,11 @@ test('invoke with existing files', async () => {
80
84
// mock existing vue.config.js
81
85
await project . write ( 'vue.config.js' , `module.exports = { lintOnSave: true }` )
82
86
83
- const eslintrc = await project . read ( '.eslintrc.js' )
84
- expect ( eslintrc ) . toEqual ( toJS ( {
87
+ const eslintrc = parseJS ( await project . read ( '.eslintrc.js' ) )
88
+ expect ( eslintrc ) . toEqual ( {
85
89
root : true ,
86
90
extends : [ 'plugin:vue/essential' , 'eslint:recommended' ]
87
- } ) )
91
+ } )
88
92
89
93
await project . run ( `${ require . resolve ( '../bin/vue' ) } invoke eslint --config airbnb --lintOn commit` )
90
94
@@ -106,11 +110,11 @@ test('invoke with existing files (yaml)', async () => {
106
110
pkg . devDependencies [ '@vue/cli-plugin-eslint' ] = '*'
107
111
await project . write ( 'package.json' , JSON . stringify ( pkg , null , 2 ) )
108
112
109
- const eslintrc = await project . read ( '.eslintrc.js' )
110
- expect ( eslintrc ) . toEqual ( toJS ( {
113
+ const eslintrc = parseJS ( await project . read ( '.eslintrc.js' ) )
114
+ expect ( eslintrc ) . toEqual ( {
111
115
root : true ,
112
116
extends : [ 'plugin:vue/essential' , 'eslint:recommended' ]
113
- } ) )
117
+ } )
114
118
115
119
await project . rm ( `.eslintrc.js` )
116
120
await project . write ( `.eslintrc.yml` , `
0 commit comments