mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-25 08:38:57 -06:00
reverts #5305 this makes the tests a little more tedious, need to find a better way to test these functionalities fixes #5442
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
const Service = require('../lib/Service')
|
|
|
|
const path = require('path')
|
|
const configPath = path.resolve('/', 'vue.config.cjs')
|
|
|
|
jest.mock('fs')
|
|
const fs = require('fs')
|
|
|
|
beforeEach(() => {
|
|
fs.writeFileSync(path.resolve('/', 'package.json'), JSON.stringify({
|
|
type: 'module',
|
|
vue: {
|
|
lintOnSave: 'default'
|
|
}
|
|
}, null, 2))
|
|
})
|
|
|
|
afterEach(() => {
|
|
if (fs.existsSync(configPath)) {
|
|
fs.unlinkSync(configPath)
|
|
}
|
|
})
|
|
|
|
const createService = () => {
|
|
const service = new Service('/', {
|
|
plugins: [],
|
|
useBuiltIn: false
|
|
})
|
|
service.init()
|
|
return service
|
|
}
|
|
|
|
// vue.config.cjs has higher priority
|
|
|
|
test('load project options from package.json', async () => {
|
|
const service = createService()
|
|
expect(service.projectOptions.lintOnSave).toBe('default')
|
|
})
|
|
|
|
test('load project options from vue.config.cjs', async () => {
|
|
fs.writeFileSync(configPath, '')
|
|
jest.mock(configPath, () => ({ lintOnSave: true }), { virtual: true })
|
|
const service = createService()
|
|
expect(service.projectOptions.lintOnSave).toBe(true)
|
|
})
|
|
|
|
test('load project options from vue.config.cjs as a function', async () => {
|
|
fs.writeFileSync(configPath, '')
|
|
jest.mock(configPath, () => function () { return { lintOnSave: true } }, { virtual: true })
|
|
const service = createService()
|
|
expect(service.projectOptions.lintOnSave).toBe(true)
|
|
})
|