forked from vuejs/vue-cli
/
ServiceESM.spec.js
52 lines (43 loc) · 1.31 KB
/
ServiceESM.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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)
})