1+ /// <reference path=".d.ts" />
2+ "use strict" ;
3+
4+ import yok = require( '../lib/common/yok' ) ;
5+ import stubs = require( './stubs' ) ;
6+ import ErrorsLib = require( "../lib/common/errors" ) ;
7+ import NpmLib = require( "../lib/node-package-manager" ) ;
8+ import FsLib = require( "../lib/common/file-system" ) ;
9+ import OptionsLib = require( "../lib/options" ) ;
10+ import StaticConfigLib = require( "../lib/config" ) ;
11+ import HostInfoLib = require( "../lib/common/host-info" ) ;
12+ import PlatformsDataLib = require( "../lib/platforms-data" ) ;
13+ import PlatformServiceLib = require( '../lib/services/platform-service' ) ;
14+ import ProjectDataLib = require( "../lib/project-data" ) ;
15+ import ProjectHelperLib = require( "../lib/common/project-helper" ) ;
16+ import ProjectDataServiceLib = require( "../lib/services/project-data-service" ) ;
17+ import CommandsServiceLib = require( "../lib/common/services/commands-service" ) ;
18+ import BroccoliBuilderLib = require( "../lib/tools/broccoli/builder" ) ;
19+ import NodeModulesTreeLib = require( "../lib/tools/broccoli/trees/node-modules-tree" ) ;
20+ import PluginsServiceLib = require( "../lib/services/plugins-service" ) ;
21+ import ChildProcessLib = require( "../lib/common/child-process" ) ;
22+
23+ import path = require( "path" ) ;
24+ import temp = require( "temp" ) ;
25+ temp . track ( ) ;
26+
27+ let assert = require ( "chai" ) . assert ;
28+
29+ function createTestInjector ( ) : IInjector {
30+ let testInjector = new yok . Yok ( ) ;
31+
32+ testInjector . register ( "fs" , FsLib . FileSystem ) ;
33+ testInjector . register ( "options" , OptionsLib . Options ) ;
34+ testInjector . register ( "errors" , ErrorsLib . Errors ) ;
35+ testInjector . register ( "staticConfig" , StaticConfigLib . StaticConfig ) ;
36+ testInjector . register ( "hostInfo" , HostInfoLib . HostInfo ) ;
37+ testInjector . register ( "platformsData" , PlatformsDataLib . PlatformsData ) ;
38+ testInjector . register ( "platformService" , PlatformServiceLib . PlatformService ) ;
39+ testInjector . register ( "logger" , stubs . LoggerStub ) ;
40+ testInjector . register ( "npmInstallationManager" , { } ) ;
41+ testInjector . register ( "lockfile" , { } ) ;
42+ testInjector . register ( "prompter" , { } ) ;
43+ testInjector . register ( "androidProjectService" , { } ) ;
44+ testInjector . register ( "iOSProjectService" , { } ) ;
45+ testInjector . register ( "devicesServices" , { } ) ;
46+ testInjector . register ( "projectData" , ProjectDataLib . ProjectData ) ;
47+ testInjector . register ( "projectHelper" , ProjectHelperLib . ProjectHelper ) ;
48+ testInjector . register ( "projectDataService" , ProjectDataServiceLib . ProjectDataService ) ;
49+ testInjector . register ( "commandsService" , CommandsServiceLib . CommandsService ) ;
50+ testInjector . register ( "hooksService" , stubs . HooksServiceStub ) ;
51+ testInjector . register ( "broccoliBuilder" , BroccoliBuilderLib . Builder ) ;
52+ testInjector . register ( "nodeModulesTree" , NodeModulesTreeLib . NodeModulesTree ) ;
53+ testInjector . register ( "pluginsService" , PluginsServiceLib . PluginsService ) ;
54+ testInjector . register ( "npm" , NpmLib . NodePackageManager ) ;
55+ testInjector . register ( "childProcess" , ChildProcessLib . ChildProcess ) ;
56+ testInjector . register ( "commandsServiceProvider" , {
57+ registerDynamicSubCommands : ( ) => { }
58+ } ) ;
59+
60+ return testInjector ;
61+ }
62+
63+ function createProject ( testInjector : IInjector , dependencies ?: any ) : string {
64+ let tempFolder = temp . mkdirSync ( "npmSupportTests" ) ;
65+ let options = testInjector . resolve ( "options" ) ;
66+ options . path = tempFolder ;
67+
68+ dependencies = dependencies || {
69+ "lodash" : "3.9.3"
70+ } ;
71+
72+ let packageJsonData : any = {
73+ "name" : "testModuleName" ,
74+ "version" : "0.1.0" ,
75+ "nativescript" : {
76+ "id" : "org.nativescript.Test" ,
77+ "tns-android" : {
78+ "version" : "1.0.0"
79+ }
80+ }
81+ } ;
82+ packageJsonData [ "dependencies" ] = dependencies ;
83+
84+ testInjector . resolve ( "fs" ) . writeJson ( path . join ( tempFolder , "package.json" ) , packageJsonData ) . wait ( ) ;
85+ return tempFolder ;
86+ }
87+
88+ describe ( "Npm support tests" , ( ) => {
89+ it ( "Ensures that the installed dependencies are prepared correctly" , ( ) => {
90+ let dependencies = {
91+ "bplist" : "0.0.4" ,
92+ "lodash" : "3.9.3"
93+ } ;
94+
95+ let testInjector = createTestInjector ( ) ;
96+ let projectFolder = createProject ( testInjector , dependencies ) ;
97+
98+ let fs = testInjector . resolve ( "fs" ) ;
99+
100+ // Creates app folder
101+ let appFolderPath = path . join ( projectFolder , "app" ) ;
102+ fs . createDirectory ( appFolderPath ) . wait ( ) ;
103+ let appResourcesFolderPath = path . join ( appFolderPath , "App_Resources" ) ;
104+ fs . createDirectory ( appResourcesFolderPath ) . wait ( ) ;
105+ fs . createDirectory ( path . join ( appResourcesFolderPath , "Android" ) ) . wait ( ) ;
106+ fs . createDirectory ( path . join ( appFolderPath , "tns_modules" ) ) . wait ( ) ;
107+
108+ // Creates platforms/android folder
109+ let androidFolderPath = path . join ( projectFolder , "platforms" , "android" ) ;
110+ fs . ensureDirectoryExists ( androidFolderPath ) . wait ( ) ;
111+
112+
113+ // Mock platform data
114+ let appDestinationFolderPath = path . join ( androidFolderPath , "assets" ) ;
115+ let platformsData = testInjector . resolve ( "platformsData" ) ;
116+ platformsData . getPlatformData = ( platform : string ) => {
117+ return {
118+ appDestinationDirectoryPath : appDestinationFolderPath ,
119+ appResourcesDestinationDirectoryPath : path . join ( appDestinationFolderPath , "app" , "App_Resources" ) ,
120+ frameworkPackageName : "tns-android" ,
121+ normalizedPlatformName : "Android"
122+ }
123+ } ;
124+
125+ let platformService = testInjector . resolve ( "platformService" ) ;
126+ platformService . preparePlatform ( "android" ) . wait ( ) ;
127+
128+ // Assert
129+ let tnsModulesFolderPath = path . join ( appDestinationFolderPath , "app" , "tns_modules" ) ;
130+ let lodashFolderPath = path . join ( tnsModulesFolderPath , "lodash" ) ;
131+ let bplistFolderPath = path . join ( tnsModulesFolderPath , "bplist" ) ;
132+ let bplistCreatorFolderPath = path . join ( tnsModulesFolderPath , "bplist-creator" ) ;
133+ let bplistParserFolderPath = path . join ( tnsModulesFolderPath , "bplist-parser" ) ;
134+
135+ assert . isTrue ( fs . exists ( lodashFolderPath ) . wait ( ) ) ;
136+ assert . isTrue ( fs . exists ( bplistFolderPath ) . wait ( ) ) ;
137+ assert . isTrue ( fs . exists ( bplistCreatorFolderPath ) . wait ( ) ) ;
138+ assert . isTrue ( fs . exists ( bplistParserFolderPath ) . wait ( ) ) ;
139+ } ) ;
140+ } ) ;
0 commit comments