@@ -9,6 +9,7 @@ import { getProjectPath } from '../../../../../utils/getProjectPath';
9
9
import {
10
10
getInstallCommand ,
11
11
importPackageJson ,
12
+ installModules ,
12
13
} from '../../../../../utils/upgrade/other/importPackageJson' ;
13
14
import { mockFs } from '../../../../mocks/mockFs' ;
14
15
import { mockPrompter } from '../../../../mocks/mockPrompter' ;
@@ -47,22 +48,6 @@ describe('importPackageJson', () => {
47
48
expect ( importGetter ) . toBeTruthy ( ) ;
48
49
expect ( importGetter . value ) . toEqual ( '[email protected] ' ) ;
49
50
50
- mockSpawn . mockImplementationOnce ( ( ) => ( {
51
- on : ( _event : string , cb : ( exitCode : number ) => void ) => {
52
- cb ( 0 ) ;
53
- } ,
54
- stdout : {
55
- on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
56
- cb ( 'stdout' ) ;
57
- } ,
58
- } ,
59
- stderr : {
60
- on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
61
- cb ( 'stderr' ) ;
62
- } ,
63
- } ,
64
- } ) ) ;
65
-
66
51
await importGetter . apply ( ) ;
67
52
68
53
expect (
@@ -71,44 +56,6 @@ describe('importPackageJson', () => {
71
56
)
72
57
) . toContain ( 'non-integrated-mock-package' ) ;
73
58
} ) ;
74
- it ( 'should get package.json and handle failed module installation' , async ( ) => {
75
- mockFs . writeFileSync (
76
- '/oldProject/' + Constants . PACKAGE_JSON_FILE_NAME ,
77
- JSON . stringify (
78
- {
79
- name : 'test' ,
80
- dependencies : {
81
- 'react-native' : '1.0.0' ,
82
- 'some-package' : '1.0.0' ,
83
- } ,
84
- } as PackageJsonType ,
85
- null ,
86
- 2
87
- )
88
- ) ;
89
-
90
- const importGetter = importPackageJson ( '/oldProject' ) as ImportGetter ;
91
-
92
- mockSpawn . mockImplementationOnce ( ( ) => ( {
93
- on : ( _event : string , cb : ( exitCode : number ) => void ) => {
94
- cb ( 1 ) ;
95
- } ,
96
- stdout : {
97
- on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
98
- cb ( 'stdout' ) ;
99
- } ,
100
- } ,
101
- stderr : {
102
- on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
103
- cb ( 'stderr' ) ;
104
- } ,
105
- } ,
106
- } ) ) ;
107
- mockPrompter . multiselect . mockClear ( ) ;
108
-
109
- await importGetter . apply ( ) ;
110
- expect ( mockPrompter . multiselect ) . toHaveBeenCalled ( ) ;
111
- } ) ;
112
59
it ( 'should get package.json on windows' , async ( ) => {
113
60
mockFs . writeFileSync (
114
61
'/oldProject/' + Constants . PACKAGE_JSON_FILE_NAME ,
@@ -131,24 +78,7 @@ describe('importPackageJson', () => {
131
78
132
79
const importGetter = importPackageJson ( '/oldProject' ) as ImportGetter ;
133
80
134
- mockSpawn . mockImplementationOnce ( ( ) => ( {
135
- on : ( _event : string , cb : ( exitCode : number ) => void ) => {
136
- cb ( 0 ) ;
137
- } ,
138
- stdout : {
139
- on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
140
- cb ( 'stdout' ) ;
141
- } ,
142
- } ,
143
- stderr : {
144
- on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
145
- cb ( 'stderr' ) ;
146
- } ,
147
- } ,
148
- } ) ) ;
149
-
150
81
await importGetter . apply ( ) ;
151
- expect ( mockSpawn ) . toHaveBeenCalledWith ( 'npm' , [ 'install' ] , { shell : true } ) ;
152
82
153
83
Object . defineProperty ( process , 'platform' , {
154
84
value : originalPlatform ,
@@ -202,22 +132,6 @@ describe('importPackageJson', () => {
202
132
203
133
const importGetter = importPackageJson ( '/oldProject' ) as ImportGetter ;
204
134
205
- mockSpawn . mockImplementationOnce ( ( ) => ( {
206
- on : ( _event : string , cb : ( exitCode : number ) => void ) => {
207
- cb ( 0 ) ;
208
- } ,
209
- stdout : {
210
- on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
211
- cb ( 'stdout' ) ;
212
- } ,
213
- } ,
214
- stderr : {
215
- on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
216
- cb ( 'stderr' ) ;
217
- } ,
218
- } ,
219
- } ) ) ;
220
-
221
135
await importGetter . apply ( ) ;
222
136
223
137
expect (
@@ -232,6 +146,90 @@ describe('importPackageJson', () => {
232
146
) . not . toContain ( 'dev-package' ) ;
233
147
} ) ;
234
148
149
+ describe ( 'installModules' , ( ) => {
150
+ it ( 'should install modules' , async ( ) => {
151
+ mockFs . writeFileSync (
152
+ '/oldProject/' + Constants . PACKAGE_JSON_FILE_NAME ,
153
+ JSON . stringify (
154
+ {
155
+ name : 'test' ,
156
+ dependencies : {
157
+ 'react-native' : '1.0.0' ,
158
+ 'some-package' : '1.0.0' ,
159
+ } ,
160
+ } as PackageJsonType ,
161
+ null ,
162
+ 2
163
+ )
164
+ ) ;
165
+
166
+ mockSpawn . mockImplementationOnce ( ( ) => ( {
167
+ on : ( _event : string , cb : ( exitCode : number ) => void ) => {
168
+ cb ( 0 ) ;
169
+ } ,
170
+ stdout : {
171
+ on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
172
+ cb ( 'stdout' ) ;
173
+ } ,
174
+ } ,
175
+ stderr : {
176
+ on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
177
+ cb ( 'stderr' ) ;
178
+ } ,
179
+ } ,
180
+ } ) ) ;
181
+ const originalPlatform = process . platform ;
182
+ Object . defineProperty ( process , 'platform' , {
183
+ value : 'win32' ,
184
+ } ) ;
185
+
186
+ await installModules ( '/oldProject' ) ;
187
+ expect ( mockSpawn ) . toHaveBeenCalledWith ( 'npm' , [ 'install' ] , {
188
+ shell : true ,
189
+ cwd : getProjectPath ( ) ,
190
+ } ) ;
191
+ Object . defineProperty ( process , 'platform' , {
192
+ value : originalPlatform ,
193
+ } ) ;
194
+ } ) ;
195
+ it ( 'should handle failed module installation' , async ( ) => {
196
+ mockFs . writeFileSync (
197
+ '/oldProject/' + Constants . PACKAGE_JSON_FILE_NAME ,
198
+ JSON . stringify (
199
+ {
200
+ name : 'test' ,
201
+ dependencies : {
202
+ 'react-native' : '1.0.0' ,
203
+ 'some-package' : '1.0.0' ,
204
+ } ,
205
+ } as PackageJsonType ,
206
+ null ,
207
+ 2
208
+ )
209
+ ) ;
210
+
211
+ mockSpawn . mockImplementationOnce ( ( ) => ( {
212
+ on : ( _event : string , cb : ( exitCode : number ) => void ) => {
213
+ cb ( 1 ) ;
214
+ } ,
215
+ stdout : {
216
+ on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
217
+ cb ( 'stdout' ) ;
218
+ } ,
219
+ } ,
220
+ stderr : {
221
+ on : ( _event : string , cb : ( ...args : any [ ] ) => void ) => {
222
+ cb ( 'stderr' ) ;
223
+ } ,
224
+ } ,
225
+ } ) ) ;
226
+ mockPrompter . multiselect . mockClear ( ) ;
227
+
228
+ await installModules ( '/oldProject' ) ;
229
+ expect ( mockPrompter . multiselect ) . toHaveBeenCalled ( ) ;
230
+ } ) ;
231
+ } ) ;
232
+
235
233
describe ( 'getInstallCommand' , ( ) => {
236
234
it ( 'should ask user when multiple lock exists' , async ( ) => {
237
235
mockFs . writeFileSync ( '/oldProject/package-lock.json' , '' ) ;
0 commit comments