Skip to content

Commit 78048db

Browse files
committed
test(vue-cli-plugin-eslint): Add missing tests
1 parent 5a646be commit 78048db

File tree

2 files changed

+164
-1
lines changed

2 files changed

+164
-1
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[` 1`] = `
4+
Array [
5+
Object {
6+
"choices": Array [
7+
Object {
8+
"name": "org.vue.eslint.config.eslint.setting.off",
9+
"value": "\\"off\\"",
10+
},
11+
Object {
12+
"name": "org.vue.eslint.config.eslint.setting.error",
13+
"value": "\\"error\\"",
14+
},
15+
Object {
16+
"name": "org.vue.eslint.config.eslint.setting.warning",
17+
"value": "\\"warning\\"",
18+
},
19+
],
20+
"default": "\\"error\\"",
21+
"description": "Dolor description",
22+
"group": "org.vue.eslint.config.eslint.groups.base",
23+
"link": "http://test.com/dolor",
24+
"message": "vue/dolor",
25+
"name": "vue/dolor",
26+
"type": "list",
27+
"value": undefined,
28+
},
29+
Object {
30+
"choices": Array [
31+
Object {
32+
"name": "org.vue.eslint.config.eslint.setting.off",
33+
"value": "\\"off\\"",
34+
},
35+
Object {
36+
"name": "org.vue.eslint.config.eslint.setting.error",
37+
"value": "\\"error\\"",
38+
},
39+
Object {
40+
"name": "org.vue.eslint.config.eslint.setting.warning",
41+
"value": "\\"warning\\"",
42+
},
43+
],
44+
"default": "\\"error\\"",
45+
"description": "Ipsum description",
46+
"group": "org.vue.eslint.config.eslint.groups.recommended",
47+
"link": "http://test.com/ipsum",
48+
"message": "vue/ipsum",
49+
"name": "vue/ipsum",
50+
"type": "list",
51+
"value": "\\"warning\\"",
52+
},
53+
Object {
54+
"choices": Array [
55+
Object {
56+
"name": "org.vue.eslint.config.eslint.setting.off",
57+
"value": "\\"off\\"",
58+
},
59+
Object {
60+
"name": "org.vue.eslint.config.eslint.setting.error",
61+
"value": "\\"error\\"",
62+
},
63+
Object {
64+
"name": "org.vue.eslint.config.eslint.setting.warning",
65+
"value": "\\"warning\\"",
66+
},
67+
Object {
68+
"name": "org.vue.eslint.config.eslint.setting.custom",
69+
"value": "[\\"error\\",[\\"asd\\"]]",
70+
},
71+
],
72+
"default": "\\"off\\"",
73+
"description": "Lorem description",
74+
"group": "org.vue.eslint.config.eslint.groups.uncategorized",
75+
"link": "http://test.com/lorem",
76+
"message": "vue/lorem",
77+
"name": "vue/lorem",
78+
"type": "list",
79+
"value": "[\\"error\\",[\\"asd\\"]]",
80+
},
81+
]
82+
`;

packages/@vue/cli-plugin-eslint/__tests__/ui.spec.js

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const configDescriptor = require('../ui/configDescriptor')
2-
const { getEslintConfigName, getDefaultValue } = configDescriptor
2+
const { getEslintConfigName, getDefaultValue, getEslintPrompts } = configDescriptor
33

44
describe('getEslintConfigName', () => {
55
describe('for "extend" of string type', () => {
@@ -76,3 +76,84 @@ describe('getDefaultValue', () => {
7676
expect(getResult('plugin:vue/recommended', undefined)).toBe('off')
7777
})
7878
})
79+
80+
describe('getEslintPrompts', () => {
81+
// project configuration
82+
const data = {
83+
eslint: {
84+
extends: 'plugin:vue/recommended',
85+
rules: {
86+
'vue/lorem': ['error', ['asd']], // custom setting
87+
'vue/ipsum': 'warning'
88+
}
89+
}
90+
}
91+
92+
// all rules
93+
const rules = {
94+
'lorem': {
95+
meta: {
96+
docs: {
97+
category: undefined,
98+
description: 'Lorem description',
99+
url: 'http://test.com/lorem'
100+
}
101+
}
102+
},
103+
'ipsum': {
104+
meta: {
105+
docs: {
106+
category: 'recommended',
107+
description: 'Ipsum description',
108+
url: 'http://test.com/ipsum'
109+
}
110+
}
111+
},
112+
'dolor': {
113+
meta: {
114+
docs: {
115+
category: 'base',
116+
description: 'Dolor description',
117+
url: 'http://test.com/dolor'
118+
}
119+
}
120+
}
121+
}
122+
123+
const prompts = getEslintPrompts(data, rules)
124+
125+
it('generates an array', () => {
126+
expect(prompts).toMatchSnapshot()
127+
})
128+
129+
it('creates an array with three settings', () => {
130+
expect(prompts).toHaveLength(3)
131+
})
132+
133+
it('creates an array which order matches eslint categories', () => {
134+
expect(prompts[0].name).toBe('vue/dolor')
135+
expect(prompts[1].name).toBe('vue/ipsum')
136+
expect(prompts[2].name).toBe('vue/lorem')
137+
})
138+
139+
it('doesn\'t set value on prompt item, if the rule wasn\'t set in project\'s eslint config', () => {
140+
expect(prompts[0].value).toBe(undefined)
141+
})
142+
143+
it('sets value on prompt item, if the rule was set in project\'s eslint config', () => {
144+
expect(prompts[1].value).toBe('"warning"')
145+
expect(prompts[2].value).toBe('["error",["asd"]]')
146+
})
147+
148+
it('generates an extra choice for rules that have a custom setting', () => {
149+
expect(prompts[0].choices).toHaveLength(3)
150+
expect(prompts[1].choices).toHaveLength(3)
151+
expect(prompts[2].choices).toHaveLength(4)
152+
})
153+
154+
it('sets a default value to "ERROR" for rule that belong to the choosen config', () => {
155+
expect(prompts[0].default).toBe('"error"')
156+
expect(prompts[1].default).toBe('"error"')
157+
expect(prompts[2].default).toBe('"off"')
158+
})
159+
})

0 commit comments

Comments
 (0)