test: fix vue.config.js tests

This commit is contained in:
Evan You
2018-02-28 18:31:25 -05:00
parent bf9a30437a
commit e6585633d4
2 changed files with 5 additions and 7 deletions
@@ -1,5 +1,5 @@
jest.mock('fs')
jest.mock('mock-config', () => ({ lintOnSave: false }), { virtual: true })
jest.mock('/vue.config.js', () => ({ lintOnSave: false }), { virtual: true })
jest.mock('vue-cli-plugin-foo', () => () => {}, { virtual: true })
const fs = require('fs')
@@ -53,16 +53,16 @@ test('load project options from package.json', () => {
})
test('load project options from vue.config.js', () => {
process.env.VUE_CLI_SERVICE_CONFIG_PATH = 'mock-config'
fs.writeFileSync('/vue.config.js', `module.exports = { lintOnSave: false }`)
mockPkg({
vue: {
lintOnSave: true
}
})
const service = createMockService()
fs.unlinkSync('/vue.config.js')
// vue.config.js has higher priority
expect(service.projectOptions.lintOnSave).toBe(false)
delete process.env.VUE_CLI_SERVICE_CONFIG_PATH
})
test('api: setMode', () => {
+2 -4
View File
@@ -159,13 +159,11 @@ module.exports = class Service {
loadProjectOptions (inlineOptions) {
// vue.config.js
let fileConfig, pkgConfig, resolved, resovledFrom
const configPath = (
process.env.VUE_CLI_SERVICE_CONFIG_PATH ||
path.resolve(this.context, 'vue.config.js')
)
const configPath = path.resolve(this.context, 'vue.config.js')
if (fs.existsSync(configPath)) {
try {
fileConfig = require(configPath)
console.log(fileConfig)
if (!fileConfig || typeof fileConfig !== 'object') {
error(
`Error loading ${chalk.bold('vue.config.js')}: should export an object.`