mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-03-14 13:11:10 -05:00
test: options
This commit is contained in:
@@ -1,5 +1,66 @@
|
||||
jest.mock('fs')
|
||||
|
||||
it('should pass', () => {
|
||||
const fs = require('fs')
|
||||
const {
|
||||
rcPath,
|
||||
saveOptions,
|
||||
loadSavedOptions,
|
||||
savePartialOptions
|
||||
} = require('../options')
|
||||
|
||||
it('save options', () => {
|
||||
saveOptions({
|
||||
packageManager: 'npm',
|
||||
plugins: {},
|
||||
foo: 'bar'
|
||||
})
|
||||
const options = JSON.parse(fs.readFileSync(rcPath, 'utf-8'))
|
||||
expect(options).toEqual({
|
||||
packageManager: 'npm',
|
||||
plugins: {}
|
||||
})
|
||||
})
|
||||
|
||||
it('load options', () => {
|
||||
expect(loadSavedOptions()).toEqual({
|
||||
packageManager: 'npm',
|
||||
plugins: {}
|
||||
})
|
||||
fs.unlinkSync(rcPath)
|
||||
expect(loadSavedOptions()).toEqual({})
|
||||
})
|
||||
|
||||
it('save partial options', () => {
|
||||
savePartialOptions({
|
||||
packageManager: 'yarn'
|
||||
})
|
||||
expect(loadSavedOptions()).toEqual({
|
||||
packageManager: 'yarn'
|
||||
})
|
||||
|
||||
savePartialOptions({
|
||||
plugins: {
|
||||
foo: { a: 1, b: 2 }
|
||||
}
|
||||
})
|
||||
expect(loadSavedOptions()).toEqual({
|
||||
packageManager: 'yarn',
|
||||
plugins: {
|
||||
foo: { a: 1, b: 2 }
|
||||
}
|
||||
})
|
||||
|
||||
savePartialOptions({
|
||||
plugins: {
|
||||
foo: { a: 2, c: 3 },
|
||||
bar: { d: 4 }
|
||||
}
|
||||
})
|
||||
expect(loadSavedOptions()).toEqual({
|
||||
packageManager: 'yarn',
|
||||
plugins: {
|
||||
foo: { a: 2, b: 2, c: 3 },
|
||||
bar: { d: 4 }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -64,7 +64,7 @@ const isObject = val => val && typeof val === 'object'
|
||||
function deepMerge (to, from) {
|
||||
for (const key in from) {
|
||||
if (isObject(to[key]) && isObject(from[key])) {
|
||||
to[key] = deepMerge(to[key], from[key])
|
||||
deepMerge(to[key], from[key])
|
||||
} else {
|
||||
to[key] = from[key]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user