@@ -4,8 +4,12 @@ jest.mock('inquirer')
44const invoke = require ( '../lib/invoke' )
55const { expectPrompts } = require ( 'inquirer' )
66const 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+ }
913
1014async function createAndInstall ( name ) {
1115 const project = await create ( name , {
@@ -28,11 +32,11 @@ async function assertUpdates (project) {
2832 'pre-commit' : 'lint-staged'
2933 } )
3034
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 ( {
3337 root : true ,
3438 extends : [ 'plugin:vue/essential' , '@vue/airbnb' ]
35- } ) )
39+ } )
3640
3741 const lintedMain = await project . read ( 'src/main.js' )
3842 expect ( lintedMain ) . toMatch ( ';' ) // should've been linted in post-generate hook
@@ -80,11 +84,11 @@ test('invoke with existing files', async () => {
8084 // mock existing vue.config.js
8185 await project . write ( 'vue.config.js' , `module.exports = { lintOnSave: true }` )
8286
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 ( {
8589 root : true ,
8690 extends : [ 'plugin:vue/essential' , 'eslint:recommended' ]
87- } ) )
91+ } )
8892
8993 await project . run ( `${ require . resolve ( '../bin/vue' ) } invoke eslint --config airbnb --lintOn commit` )
9094
@@ -106,11 +110,11 @@ test('invoke with existing files (yaml)', async () => {
106110 pkg . devDependencies [ '@vue/cli-plugin-eslint' ] = '*'
107111 await project . write ( 'package.json' , JSON . stringify ( pkg , null , 2 ) )
108112
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 ( {
111115 root : true ,
112116 extends : [ 'plugin:vue/essential' , 'eslint:recommended' ]
113- } ) )
117+ } )
114118
115119 await project . rm ( `.eslintrc.js` )
116120 await project . write ( `.eslintrc.yml` , `
0 commit comments