-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
Copy pathServiceESM.spec.js
75 lines (66 loc) · 2.74 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
jest.setTimeout(200000)
const path = require('path')
const fs = require('fs-extra')
const { defaultPreset } = require('@vue/cli/lib/options')
const create = require('@vue/cli-test-utils/createTestProject')
const { loadModule } = require('@vue/cli-shared-utils')
let project
beforeAll(async () => {
project = await create('service-esm-test', defaultPreset)
const pkg = JSON.parse(await project.read('package.json'))
pkg.type = 'module'
pkg.vue = { lintOnSave: 'default' }
await project.write('package.json', JSON.stringify(pkg, null, 2))
fs.renameSync(path.resolve(project.dir, 'babel.config.js'), path.resolve(project.dir, 'babel.config.cjs'))
})
const createService = async () => {
const Service = loadModule('@vue/cli-service/lib/Service', project.dir)
const service = new Service(project.dir, {
plugins: [],
useBuiltIn: false
})
await service.init()
return service
}
test('load project options from package.json', async () => {
const service = await createService()
expect(service.projectOptions.lintOnSave).toBe('default')
})
test('load project options from vue.config.cjs', async () => {
const configPath = path.resolve(project.dir, './vue.config.cjs')
fs.writeFileSync(configPath, 'module.exports = { lintOnSave: true }')
const service = await createService()
expect(service.projectOptions.lintOnSave).toBe(true)
await fs.unlinkSync(configPath)
})
test('load project options from vue.config.cjs as a function', async () => {
const configPath = path.resolve(project.dir, './vue.config.cjs')
fs.writeFileSync(configPath, 'module.exports = function () { return { lintOnSave: true } }')
const service = await createService()
expect(service.projectOptions.lintOnSave).toBe(true)
await fs.unlinkSync(configPath)
})
test('load project options from vue.config.js', async () => {
const configPath = path.resolve(project.dir, './vue.config.js')
fs.writeFileSync(configPath, 'export default { lintOnSave: true }')
const service = await createService()
expect(service.projectOptions.lintOnSave).toBe(true)
await fs.unlinkSync(configPath)
})
test('load project options from vue.config.mjs', async () => {
const configPath = path.resolve(project.dir, './vue.config.mjs')
fs.writeFileSync(configPath, 'export default { lintOnSave: true }')
const service = await createService()
expect(service.projectOptions.lintOnSave).toBe(true)
await fs.unlinkSync(configPath)
})
test('load project options from vue.config.ts', async () => {
const configPath = path.resolve(project.dir, './vue.config.ts')
fs.writeFileSync(configPath, `
const lintOnSave:boolean = true
export default { lintOnSave }
`)
const service = await createService()
expect(service.projectOptions.lintOnSave).toBe(true)
await fs.unlinkSync(configPath)
})