-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
Copy pathCreator.spec.js
118 lines (111 loc) · 2.57 KB
/
Creator.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
jest.mock('fs')
jest.mock('inquirer')
const { defaults } = require('../lib/options')
const assertPromptModule = require('@vue/cli-test-utils/assertPromptModule')
test('default', async () => {
const expectedPrompts = [
{
message: 'pick a preset',
choices: [
// both names are `Default`, the vue version is indicated in the feature prompts, so later we'll test the result preset for the vue version
'Default',
'Default',
'Manually select'
],
choose: 0
},
{
message: 'package manager',
choices: ['Yarn', 'PNPM', 'NPM'],
choose: 0
}
]
await assertPromptModule([], expectedPrompts, defaults.presets['Default (Vue 3)'])
})
test('manual + PromptModuleAPI', async () => {
const mockModule = api => {
api.injectFeature({
name: 'Foo',
value: 'foo'
})
api.injectFeature({
name: 'Bar',
value: 'bar'
})
api.injectPrompt({
name: 'customFoo',
message: 'customFoo',
when: answers => answers.features.includes('foo'),
type: 'confirm'
})
api.injectPrompt({
name: 'customBar',
message: 'customBar',
when: answers => answers.features.includes('bar'),
type: 'list',
choices: []
})
api.injectOptionForPrompt('customBar', {
name: 'barChoice',
value: 'barChoice'
})
api.onPromptComplete((answers, options) => {
if (answers.features.includes('bar')) {
options.plugins.bar = {}
}
if (answers.customBar === 'barChoice') {
options.plugins.barChoice = {}
}
})
}
const expectedPrompts = [
{
message: 'Please pick a preset',
choose: 2 // manual
},
{
message: 'Check the features',
choices: ['Foo', 'Bar'],
check: [1]
},
{
message: 'customBar',
choices: ['barChoice'],
choose: 0
},
{
message: 'Where do you prefer placing config',
choices: ['dedicated', 'package.json'],
choose: 0
},
{
message: 'Save this as a preset',
confirm: true
},
{
message: 'Save preset as',
input: 'test'
}
]
const expectedOptions = {
useConfigFiles: true,
plugins: {
bar: {},
barChoice: {}
}
}
await assertPromptModule(mockModule, expectedPrompts, expectedOptions)
// should be saved now
const expectedPromptsForSaved = [
{
choices: [
'test',
'Default',
'Default',
'Manually'
],
choose: 0
}
]
await assertPromptModule([], expectedPromptsForSaved, expectedOptions)
})