Skip to content

Commit 6010eb2

Browse files
committed
test: fix tests for preserving ruleNames
1 parent 82ded1f commit 6010eb2

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

packages/@vue/cli-service/__tests__/Service.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,28 @@ test('api: configureWebpack returning object', () => {
233233
expect(config.output.path).toBe('test-dist-3')
234234
})
235235

236+
test('api: configureWebpack preserve ruleNames', () => {
237+
const service = createMockService([
238+
{
239+
id: 'babel',
240+
apply: require('@vue/cli-plugin-babel')
241+
},
242+
{
243+
id: 'test',
244+
apply: api => {
245+
api.configureWebpack({
246+
module: {
247+
rules: []
248+
}
249+
})
250+
}
251+
}
252+
])
253+
254+
const config = service.resolveWebpackConfig()
255+
expect(config.module.rules[0].__ruleNames).toEqual(['js'])
256+
})
257+
236258
test('api: configureDevServer', () => {
237259
const cb = () => {}
238260
const service = createMockService([{

packages/@vue/cli-service/lib/Service.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ module.exports = class Service {
234234
// vue inspect works properly.
235235
if (config !== original) {
236236
cloneRuleNames(
237-
config.module.rules,
238-
original.module.rules
237+
config.module && config.module.rules,
238+
original.module && original.module.rules
239239
)
240240
}
241241

@@ -352,14 +352,15 @@ function removeSlash (config, key) {
352352
}
353353

354354
function cloneRuleNames (to, from) {
355+
if (!to || !from) {
356+
return
357+
}
355358
from.forEach((r, i) => {
356359
if (to[i]) {
357360
Object.defineProperty(to[i], '__ruleNames', {
358361
value: r.__ruleNames
359362
})
360-
if (to[i].oneOf && r.oneOf) {
361-
cloneRuleNames(to[i].oneOf, r.oneOf)
362-
}
363+
cloneRuleNames(to[i].oneOf, r.oneOf)
363364
}
364365
})
365366
}

0 commit comments

Comments
 (0)