mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-04-21 11:58:36 -05:00
test: fix vue.config.js tests
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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.`
|
||||
|
||||
Reference in New Issue
Block a user