@@ -24,8 +24,16 @@ describe("projectService", () => {
2424 /* tslint:disable:no-empty */
2525 const getTestInjector = ( opts : { projectName : string } ) : IInjector => {
2626 const testInjector = new yok . Yok ( ) ;
27+ let lastInstallConfig : any = null ;
2728 testInjector . register ( "packageManager" , {
28- install : async ( ) => { } ,
29+ install : async (
30+ _packageName : string ,
31+ _pathToSave : string ,
32+ config : any ,
33+ ) => {
34+ lastInstallConfig = config ;
35+ } ,
36+ _getLastInstallConfig : ( ) => lastInstallConfig ,
2937 } ) ;
3038 testInjector . register ( "errors" , ErrorsStub ) ;
3139 testInjector . register ( "fs" , {
@@ -79,7 +87,7 @@ describe("projectService", () => {
7987 testInjector . register ( "hooksService" , {
8088 executeAfterHooks : async (
8189 commandName : string ,
82- hookArguments ?: IDictionary < any >
90+ hookArguments ?: IDictionary < any > ,
8391 ) : Promise < void > => undefined ,
8492 } ) ;
8593 testInjector . register ( "pacoteService" , {
@@ -104,7 +112,7 @@ describe("projectService", () => {
104112 const projectName = invalidProjectName ;
105113 const testInjector = getTestInjector ( { projectName } ) ;
106114 const projectService = testInjector . resolve < IProjectService > (
107- ProjectServiceLib . ProjectService
115+ ProjectServiceLib . ProjectService ,
108116 ) ;
109117 const projectDir = path . join ( dirToCreateProject , projectName ) ;
110118 const projectCreationData = await projectService . createProject ( {
@@ -114,6 +122,31 @@ describe("projectService", () => {
114122 template : constants . RESERVED_TEMPLATE_NAMES [ "default" ] ,
115123 } ) ;
116124
125+ it ( "passes legacyPeerDeps to package manager install" , async ( ) => {
126+ const projectName = invalidProjectName ;
127+ const testInjector = getTestInjector ( { projectName } ) ;
128+ const projectService = testInjector . resolve < IProjectService > (
129+ ProjectServiceLib . ProjectService ,
130+ ) ;
131+
132+ await projectService . createProject ( {
133+ projectName : projectName ,
134+ pathToProject : dirToCreateProject ,
135+ force : true ,
136+ template : constants . RESERVED_TEMPLATE_NAMES [ "default" ] ,
137+ legacyPeerDeps : true ,
138+ } ) ;
139+
140+ const installConfig = testInjector
141+ . resolve ( "packageManager" )
142+ . _getLastInstallConfig ( ) ;
143+ assert . isOk (
144+ installConfig ,
145+ "Expected package manager install to be called" ,
146+ ) ;
147+ assert . isTrue ( installConfig . legacyPeers ) ;
148+ } ) ;
149+
117150 assert . deepStrictEqual ( projectCreationData , {
118151 projectName,
119152 projectDir,
@@ -125,7 +158,7 @@ describe("projectService", () => {
125158 const testInjector = getTestInjector ( { projectName } ) ;
126159 const options = testInjector . resolve < IOptions > ( "options" ) ;
127160 const projectService = testInjector . resolve < IProjectService > (
128- ProjectServiceLib . ProjectService
161+ ProjectServiceLib . ProjectService ,
129162 ) ;
130163 const projectDir = path . join ( dirToCreateProject , projectName ) ;
131164
@@ -145,7 +178,7 @@ describe("projectService", () => {
145178 `git init ${ projectDir } ` ,
146179 `git -C ${ projectDir } add --all` ,
147180 `git -C ${ projectDir } commit --no-verify -m "init"` ,
148- ]
181+ ] ,
149182 ) ;
150183 } ) ;
151184
@@ -154,7 +187,7 @@ describe("projectService", () => {
154187 const testInjector = getTestInjector ( { projectName } ) ;
155188 const options = testInjector . resolve < IOptions > ( "options" ) ;
156189 const projectService = testInjector . resolve < IProjectService > (
157- ProjectServiceLib . ProjectService
190+ ProjectServiceLib . ProjectService ,
158191 ) ;
159192
160193 // simulate --no-git
@@ -169,30 +202,29 @@ describe("projectService", () => {
169202
170203 assert . deepEqual (
171204 testInjector . resolve ( "childProcess" ) . _getExecutedCommands ( ) ,
172- [ ]
205+ [ ] ,
173206 ) ;
174207 } ) ;
175208
176209 it ( "fails when invalid name is passed when projectNameService fails" , async ( ) => {
177210 const projectName = invalidProjectName ;
178211 const testInjector = getTestInjector ( { projectName } ) ;
179- const projectNameService = testInjector . resolve < IProjectNameService > (
180- "projectNameService"
181- ) ;
212+ const projectNameService =
213+ testInjector . resolve < IProjectNameService > ( "projectNameService" ) ;
182214 const err = new Error ( "Invalid name" ) ;
183215 projectNameService . ensureValidName = ( name : string ) => {
184216 throw err ;
185217 } ;
186218 const projectService = testInjector . resolve < IProjectService > (
187- ProjectServiceLib . ProjectService
219+ ProjectServiceLib . ProjectService ,
188220 ) ;
189221 await assert . isRejected (
190222 projectService . createProject ( {
191223 projectName : projectName ,
192224 pathToProject : dirToCreateProject ,
193225 template : constants . RESERVED_TEMPLATE_NAMES [ "default" ] ,
194226 } ) ,
195- err . message
227+ err . message ,
196228 ) ;
197229 } ) ;
198230
@@ -202,7 +234,7 @@ describe("projectService", () => {
202234 const fs = testInjector . resolve < IFileSystem > ( "fs" ) ;
203235 fs . isEmptyDir = ( name : string ) => false ;
204236 const projectService = testInjector . resolve < IProjectService > (
205- ProjectServiceLib . ProjectService
237+ ProjectServiceLib . ProjectService ,
206238 ) ;
207239 await assert . isRejected (
208240 projectService . createProject ( {
@@ -212,8 +244,8 @@ describe("projectService", () => {
212244 } ) ,
213245 `Path already exists and is not empty ${ path . join (
214246 dirToCreateProject ,
215- projectName
216- ) } `
247+ projectName ,
248+ ) } `,
217249 ) ;
218250 } ) ;
219251 } ) ;
@@ -243,7 +275,7 @@ describe("projectService", () => {
243275 testInjector . register ( "hooksService" , {
244276 executeAfterHooks : async (
245277 commandName : string ,
246- hookArguments ?: IDictionary < any >
278+ hookArguments ?: IDictionary < any > ,
247279 ) : Promise < void > => undefined ,
248280 } ) ;
249281 testInjector . register ( "pacoteService" , {
@@ -264,16 +296,15 @@ describe("projectService", () => {
264296 } ) ;
265297
266298 const projectService : IProjectService = testInjector . resolve (
267- ProjectServiceLib . ProjectService
299+ ProjectServiceLib . ProjectService ,
268300 ) ;
269301 assert . isTrue ( projectService . isValidNativeScriptProject ( "some-dir" ) ) ;
270302 } ) ;
271303
272304 it ( "returns correct data when multiple calls are executed" , ( ) => {
273305 const testInjector = getTestInjector ( ) ;
274- const projectDataService = testInjector . resolve < IProjectDataService > (
275- "projectDataService"
276- ) ;
306+ const projectDataService =
307+ testInjector . resolve < IProjectDataService > ( "projectDataService" ) ;
277308 const projectData : any = {
278309 projectDir : "projectDir" ,
279310 projectId : "projectId" ,
@@ -282,23 +313,23 @@ describe("projectService", () => {
282313
283314 let returnedProjectData : any = null ;
284315 projectDataService . getProjectData = (
285- projectDir ?: string
316+ projectDir ?: string ,
286317 ) : IProjectData => {
287318 projectData . projectDir = projectDir ;
288319 returnedProjectData = projectData ;
289320 return returnedProjectData ;
290321 } ;
291322
292323 const projectService : IProjectService = testInjector . resolve (
293- ProjectServiceLib . ProjectService
324+ ProjectServiceLib . ProjectService ,
294325 ) ;
295326 assert . isTrue ( projectService . isValidNativeScriptProject ( "some-dir" ) ) ;
296327 assert . equal ( returnedProjectData . projectDir , "some-dir" ) ;
297328 assert . isTrue ( projectService . isValidNativeScriptProject ( "some-dir-2" ) ) ;
298329 assert . equal ( returnedProjectData . projectDir , "some-dir-2" ) ;
299330
300331 projectDataService . getProjectData = (
301- projectDir ?: string
332+ projectDir ?: string ,
302333 ) : IProjectData => {
303334 throw new Error ( "Err" ) ;
304335 } ;
@@ -315,7 +346,7 @@ describe("projectService", () => {
315346 } ) ;
316347
317348 const projectService : IProjectService = testInjector . resolve (
318- ProjectServiceLib . ProjectService
349+ ProjectServiceLib . ProjectService ,
319350 ) ;
320351 assert . isFalse ( projectService . isValidNativeScriptProject ( "some-dir" ) ) ;
321352 } ) ;
@@ -326,7 +357,7 @@ describe("projectService", () => {
326357 } ) ;
327358
328359 const projectService : IProjectService = testInjector . resolve (
329- ProjectServiceLib . ProjectService
360+ ProjectServiceLib . ProjectService ,
330361 ) ;
331362 assert . isFalse ( projectService . isValidNativeScriptProject ( "some-dir" ) ) ;
332363 } ) ;
@@ -337,7 +368,7 @@ describe("projectService", () => {
337368 } ) ;
338369
339370 const projectService : IProjectService = testInjector . resolve (
340- ProjectServiceLib . ProjectService
371+ ProjectServiceLib . ProjectService ,
341372 ) ;
342373 assert . isFalse ( projectService . isValidNativeScriptProject ( "some-dir" ) ) ;
343374 } ) ;
0 commit comments