mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-16 04:10:20 -06:00
test: fix tests for preserving ruleNames
This commit is contained in:
@@ -233,6 +233,28 @@ test('api: configureWebpack returning object', () => {
|
||||
expect(config.output.path).toBe('test-dist-3')
|
||||
})
|
||||
|
||||
test('api: configureWebpack preserve ruleNames', () => {
|
||||
const service = createMockService([
|
||||
{
|
||||
id: 'babel',
|
||||
apply: require('@vue/cli-plugin-babel')
|
||||
},
|
||||
{
|
||||
id: 'test',
|
||||
apply: api => {
|
||||
api.configureWebpack({
|
||||
module: {
|
||||
rules: []
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
const config = service.resolveWebpackConfig()
|
||||
expect(config.module.rules[0].__ruleNames).toEqual(['js'])
|
||||
})
|
||||
|
||||
test('api: configureDevServer', () => {
|
||||
const cb = () => {}
|
||||
const service = createMockService([{
|
||||
|
||||
@@ -234,8 +234,8 @@ module.exports = class Service {
|
||||
// vue inspect works properly.
|
||||
if (config !== original) {
|
||||
cloneRuleNames(
|
||||
config.module.rules,
|
||||
original.module.rules
|
||||
config.module && config.module.rules,
|
||||
original.module && original.module.rules
|
||||
)
|
||||
}
|
||||
|
||||
@@ -352,14 +352,15 @@ function removeSlash (config, key) {
|
||||
}
|
||||
|
||||
function cloneRuleNames (to, from) {
|
||||
if (!to || !from) {
|
||||
return
|
||||
}
|
||||
from.forEach((r, i) => {
|
||||
if (to[i]) {
|
||||
Object.defineProperty(to[i], '__ruleNames', {
|
||||
value: r.__ruleNames
|
||||
})
|
||||
if (to[i].oneOf && r.oneOf) {
|
||||
cloneRuleNames(to[i].oneOf, r.oneOf)
|
||||
}
|
||||
cloneRuleNames(to[i].oneOf, r.oneOf)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user