@@ -7,11 +7,9 @@ import {
7
7
writeFiles ,
8
8
} from '../jest/helpers' ;
9
9
import slash from 'slash' ;
10
- import prompts from 'prompts' ;
11
-
12
- jest . mock ( 'prompts' , ( ) => jest . fn ( ) ) ;
13
10
14
11
const DIR = getTempDirectory ( 'command-init' ) ;
12
+ const PROJECT_NAME = 'TestInit' ;
15
13
16
14
function createCustomTemplateFiles ( ) {
17
15
writeFiles ( DIR , {
@@ -51,31 +49,18 @@ if (process.platform === 'win32') {
51
49
}
52
50
53
51
test ( 'init fails if the directory already exists' , ( ) => {
54
- fs . mkdirSync ( path . join ( DIR , 'TestInit' ) ) ;
52
+ fs . mkdirSync ( path . join ( DIR , PROJECT_NAME ) ) ;
55
53
56
- const { stderr} = runCLI ( DIR , [ 'init' , 'TestInit' ] , { expectedFailure : true } ) ;
54
+ const { stderr} = runCLI ( DIR , [ 'init' , PROJECT_NAME ] , { expectedFailure : true } ) ;
57
55
expect ( stderr ) . toContain (
58
- ' error Cannot initialize new project because directory "TestInit " already exists.' ,
56
+ ` error Cannot initialize new project because directory "${ PROJECT_NAME } " already exists.` ,
59
57
) ;
60
58
} ) ;
61
59
62
60
test ( 'init should prompt for the project name' , ( ) => {
63
- createCustomTemplateFiles ( ) ;
64
- const { stdout} = runCLI ( DIR , [
65
- 'init' ,
66
- 'test' ,
67
- '--template' ,
68
- templatePath ,
69
- '--install-pods' ,
70
- 'false' ,
71
- ] ) ;
61
+ const { stdout} = runCLI ( DIR , [ 'init' ] ) ;
72
62
73
- ( prompts as jest . MockedFunction < typeof prompts > ) . mockReturnValue (
74
- Promise . resolve ( {
75
- name : 'TestInit' ,
76
- } ) ,
77
- ) ;
78
- expect ( stdout ) . toContain ( 'Run instructions' ) ;
63
+ expect ( stdout ) . toContain ( 'How would you like to name the app?' ) ;
79
64
} ) ;
80
65
81
66
test ( 'init --template filepath' , ( ) => {
@@ -85,7 +70,7 @@ test('init --template filepath', () => {
85
70
'init' ,
86
71
'--template' ,
87
72
templatePath ,
88
- 'TestInit' ,
73
+ PROJECT_NAME ,
89
74
'--install-pods' ,
90
75
'false' ,
91
76
] ) ;
@@ -95,21 +80,20 @@ test('init --template filepath', () => {
95
80
// make sure we don't leave garbage
96
81
expect ( fs . readdirSync ( DIR ) ) . toContain ( 'custom' ) ;
97
82
98
- let dirFiles = fs . readdirSync ( path . join ( DIR , 'TestInit' ) ) ;
83
+ let dirFiles = fs . readdirSync ( path . join ( DIR , PROJECT_NAME ) ) ;
99
84
100
85
expect ( dirFiles ) . toEqual ( customTemplateCopiedFiles ) ;
101
86
} ) ;
102
87
103
88
test ( 'init --template file with custom directory' , ( ) => {
104
89
createCustomTemplateFiles ( ) ;
105
- const projectName = 'TestInit' ;
106
90
const customPath = 'custom-path' ;
107
91
108
92
const { stdout} = runCLI ( DIR , [
109
93
'init' ,
110
94
'--template' ,
111
95
templatePath ,
112
- projectName ,
96
+ PROJECT_NAME ,
113
97
'--directory' ,
114
98
'custom-path' ,
115
99
'--install-pods' ,
@@ -133,7 +117,7 @@ test('init skips installation of dependencies with --skip-install', () => {
133
117
'init' ,
134
118
'--template' ,
135
119
templatePath ,
136
- 'TestInit' ,
120
+ PROJECT_NAME ,
137
121
'--skip-install' ,
138
122
] ) ;
139
123
@@ -142,7 +126,7 @@ test('init skips installation of dependencies with --skip-install', () => {
142
126
// make sure we don't leave garbage
143
127
expect ( fs . readdirSync ( DIR ) ) . toContain ( 'custom' ) ;
144
128
145
- let dirFiles = fs . readdirSync ( path . join ( DIR , 'TestInit' ) ) ;
129
+ let dirFiles = fs . readdirSync ( path . join ( DIR , PROJECT_NAME ) ) ;
146
130
147
131
expect ( dirFiles ) . toEqual (
148
132
customTemplateCopiedFiles . filter (
@@ -158,7 +142,7 @@ test('init uses npm as the package manager with --npm', () => {
158
142
'init' ,
159
143
'--template' ,
160
144
templatePath ,
161
- 'TestInit' ,
145
+ PROJECT_NAME ,
162
146
'--npm' ,
163
147
'--install-pods' ,
164
148
'false' ,
@@ -169,7 +153,7 @@ test('init uses npm as the package manager with --npm', () => {
169
153
// make sure we don't leave garbage
170
154
expect ( fs . readdirSync ( DIR ) ) . toContain ( 'custom' ) ;
171
155
172
- const initDirPath = path . join ( DIR , 'TestInit' ) ;
156
+ const initDirPath = path . join ( DIR , PROJECT_NAME ) ;
173
157
174
158
// Remove yarn.lock and node_modules
175
159
const filteredFiles = customTemplateCopiedFiles . filter (
0 commit comments