@@ -342,4 +342,99 @@ describe("projectService", () => {
342342 assert . isFalse ( projectService . isValidNativeScriptProject ( "some-dir" ) ) ;
343343 } ) ;
344344 } ) ;
345+
346+ describe ( "ensureAppResourcesExist" , ( ) => {
347+ const projectDir = path . resolve ( "app-resources-project" ) ;
348+ const appResources = path . join ( projectDir , "App_Resources" ) ;
349+ const templateDir = path . resolve ( "default-template" ) ;
350+ const templateAppResources = path . join ( templateDir , "App_Resources" ) ;
351+
352+ const setup = ( existing : string [ ] ) => {
353+ const exists = new Set ( existing . map ( ( p ) => path . resolve ( p ) ) ) ;
354+ const copies : { from : string ; to : string } [ ] = [ ] ;
355+ let extracted = 0 ;
356+ const testInjector = new yok . Yok ( ) ;
357+ testInjector . register ( "fs" , {
358+ exists : ( p : string ) => exists . has ( path . resolve ( p ) ) ,
359+ createDirectory : ( p : string ) => exists . add ( path . resolve ( p ) ) ,
360+ copyFile : ( from : string , to : string ) => copies . push ( { from, to } ) ,
361+ } ) ;
362+ testInjector . register ( "logger" , LoggerStub ) ;
363+ testInjector . register ( "projectDataService" , {
364+ getProjectData : ( dir : string ) : IProjectData =>
365+ < any > {
366+ getAppResourcesDirectoryPath : ( d : string ) =>
367+ path . join ( d === templateDir ? templateDir : dir , "App_Resources" ) ,
368+ } ,
369+ } ) ;
370+ testInjector . register ( "pacoteService" , {
371+ extractPackage : async ( ) => {
372+ extracted ++ ;
373+ } ,
374+ } ) ;
375+ testInjector . register ( "tempService" , {
376+ mkdirSync : async ( ) => templateDir ,
377+ } ) ;
378+ for ( const name of [
379+ "options" ,
380+ "hooksService" ,
381+ "packageManager" ,
382+ "errors" ,
383+ "projectConfigService" ,
384+ "projectHelper" ,
385+ "projectNameService" ,
386+ "projectTemplatesService" ,
387+ "staticConfig" ,
388+ "childProcess" ,
389+ ] ) {
390+ testInjector . register ( name , { } ) ;
391+ }
392+ const projectService : IProjectService = testInjector . resolve (
393+ ProjectServiceLib . ProjectService
394+ ) ;
395+ return { projectService, copies, extracted : ( ) => extracted } ;
396+ } ;
397+
398+ it ( "copies the whole App_Resources when it is missing" , async ( ) => {
399+ const { projectService, copies } = setup ( [ ] ) ;
400+ await projectService . ensureAppResourcesExist ( projectDir , "Windows" ) ;
401+ assert . deepEqual ( copies , [
402+ { from : path . join ( templateAppResources , "*" ) , to : appResources } ,
403+ ] ) ;
404+ } ) ;
405+
406+ it ( "adds a missing platform folder from the default template" , async ( ) => {
407+ const { projectService, copies } = setup ( [
408+ appResources ,
409+ path . join ( templateAppResources , "Windows" ) ,
410+ ] ) ;
411+ await projectService . ensureAppResourcesExist ( projectDir , "Windows" ) ;
412+ assert . deepEqual ( copies , [
413+ { from : path . join ( templateAppResources , "Windows" ) , to : appResources } ,
414+ ] ) ;
415+ } ) ;
416+
417+ it ( "leaves an existing platform folder alone" , async ( ) => {
418+ const { projectService, copies, extracted } = setup ( [
419+ appResources ,
420+ path . join ( appResources , "Windows" ) ,
421+ ] ) ;
422+ await projectService . ensureAppResourcesExist ( projectDir , "Windows" ) ;
423+ assert . deepEqual ( copies , [ ] ) ;
424+ assert . equal ( extracted ( ) , 0 ) ;
425+ } ) ;
426+
427+ it ( "copies nothing when the template has no folder for the platform" , async ( ) => {
428+ const { projectService, copies } = setup ( [ appResources ] ) ;
429+ await projectService . ensureAppResourcesExist ( projectDir , "Windows" ) ;
430+ assert . deepEqual ( copies , [ ] ) ;
431+ } ) ;
432+
433+ it ( "does not look at platform folders without a platform" , async ( ) => {
434+ const { projectService, copies, extracted } = setup ( [ appResources ] ) ;
435+ await projectService . ensureAppResourcesExist ( projectDir ) ;
436+ assert . deepEqual ( copies , [ ] ) ;
437+ assert . equal ( extracted ( ) , 0 ) ;
438+ } ) ;
439+ } ) ;
345440} ) ;
0 commit comments