1+ /// <reference path=".d.ts" />
2+ "use strict" ;
3+
4+ import Future = require( "fibers/future" ) ;
5+ import * as path from "path" ;
6+ import temp = require( "temp" ) ;
7+
8+ import ChildProcessLib = require( "../lib/common/child-process" ) ;
9+ import ConfigLib = require( "../lib/config" ) ;
10+ import ErrorsLib = require( "../lib/common/errors" ) ;
11+ import FileSystemLib = require( "../lib/common/file-system" ) ;
12+ import HostInfoLib = require( "../lib/common/host-info" ) ;
13+ import iOSProjectServiceLib = require( "../lib/services/ios-project-service" ) ;
14+ import LoggerLib = require( "../lib/common/logger" ) ;
15+ import OptionsLib = require( "../lib/options" ) ;
16+ import ProjectDataLib = require( "../lib/project-data" ) ;
17+
18+ import yok = require( "../lib/common/yok" ) ;
19+
20+ let assert = require ( "chai" ) . assert ;
21+
22+ function createTestInjector ( projectPath : string , projectName : string ) : IInjector {
23+ let testInjector = new yok . Yok ( ) ;
24+ testInjector . register ( "childProcess" , ChildProcessLib . ChildProcess ) ;
25+ testInjector . register ( "config" , ConfigLib . Configuration ) ;
26+ testInjector . register ( "errors" , ErrorsLib . Errors ) ;
27+ testInjector . register ( "fs" , FileSystemLib . FileSystem ) ;
28+ testInjector . register ( "hostInfo" , HostInfoLib . HostInfo ) ;
29+ testInjector . register ( "injector" , testInjector ) ;
30+ testInjector . register ( "iOSEmulatorServices" , { } ) ;
31+ testInjector . register ( "iOSProjectService" , iOSProjectServiceLib . IOSProjectService ) ;
32+ testInjector . register ( "logger" , LoggerLib . Logger ) ;
33+ testInjector . register ( "options" , OptionsLib . Options ) ;
34+ testInjector . register ( "projectData" , {
35+ platformsDir : projectPath ,
36+ projectName : projectName
37+ } ) ;
38+ testInjector . register ( "projectHelper" , { } ) ;
39+ testInjector . register ( "staticConfig" , ConfigLib . StaticConfig ) ;
40+
41+ return testInjector ;
42+ }
43+
44+ describe ( "Cocoapods support" , ( ) => {
45+ it ( "adds plugin with Podfile" , ( ) => {
46+ let projectName = "projectDirectory" ;
47+ let projectPath = temp . mkdirSync ( projectName ) ;
48+
49+ let testInjector = createTestInjector ( projectPath , projectName ) ;
50+ let fs : IFileSystem = testInjector . resolve ( "fs" ) ;
51+
52+ let packageJsonData = {
53+ "name" : "myProject" ,
54+ "version" : "0.1.0" ,
55+ "nativescript" : {
56+ "id" : "org.nativescript.myProject" ,
57+ "tns-android" : {
58+ "version" : "1.0.0"
59+ }
60+ }
61+ } ;
62+ fs . writeJson ( path . join ( projectPath , "package.json" ) , packageJsonData ) . wait ( ) ;
63+
64+ let platformsFolderPath = path . join ( projectPath , "ios" ) ;
65+ fs . createDirectory ( platformsFolderPath ) . wait ( ) ;
66+
67+ let iOSProjectService = testInjector . resolve ( "iOSProjectService" ) ;
68+ iOSProjectService . prepareDynamicFrameworks = ( pluginPlatformsFolderPath : string , pluginData : IPluginData ) : IFuture < void > => {
69+ return Future . fromResult ( ) ;
70+ } ;
71+
72+ let pluginPath = temp . mkdirSync ( "pluginDirectory" ) ;
73+ let pluginPlatformsFolderPath = path . join ( pluginPath , "platforms" , "ios" ) ;
74+ let pluginPodfilePath = path . join ( pluginPlatformsFolderPath , "Podfile" ) ;
75+ let pluginPodfileContent = [ "source 'https://github.com/CocoaPods/Specs.git'" , "platform :ios, '8.1'" , "pod 'GoogleMaps'" ] . join ( "\n" ) ;
76+ fs . writeFile ( pluginPodfilePath , pluginPodfileContent ) . wait ( ) ;
77+
78+ let pluginData = {
79+ pluginPlatformsFolderPath ( platform : string ) : string {
80+ return pluginPlatformsFolderPath ;
81+ }
82+ } ;
83+
84+ iOSProjectService . preparePluginNativeCode ( pluginData ) . wait ( ) ;
85+
86+ let projectPodfilePath = path . join ( platformsFolderPath , "Podfile" ) ;
87+ assert . isTrue ( fs . exists ( projectPodfilePath ) . wait ( ) ) ;
88+
89+ let actualProjectPodfileContent = fs . readText ( projectPodfilePath ) . wait ( ) ;
90+ let expectedProjectPodfileContent = [ `# Begin Podfile - ${ pluginPodfilePath } ` , ` ${ pluginPodfileContent } ` , " # End Podfile \n" ] . join ( "\n" ) ;
91+ assert . equal ( actualProjectPodfileContent , expectedProjectPodfileContent ) ;
92+ } ) ;
93+ it ( "adds and removes plugin with Podfile" , ( ) => {
94+ let projectName = "projectDirectory2" ;
95+ let projectPath = temp . mkdirSync ( projectName ) ;
96+
97+ let testInjector = createTestInjector ( projectPath , projectName ) ;
98+ let fs : IFileSystem = testInjector . resolve ( "fs" ) ;
99+
100+ let packageJsonData = {
101+ "name" : "myProject2" ,
102+ "version" : "0.1.0" ,
103+ "nativescript" : {
104+ "id" : "org.nativescript.myProject2" ,
105+ "tns-android" : {
106+ "version" : "1.0.0"
107+ }
108+ }
109+ } ;
110+ fs . writeJson ( path . join ( projectPath , "package.json" ) , packageJsonData ) . wait ( ) ;
111+
112+ let platformsFolderPath = path . join ( projectPath , "ios" ) ;
113+ fs . createDirectory ( platformsFolderPath ) . wait ( ) ;
114+
115+ let iOSProjectService = testInjector . resolve ( "iOSProjectService" ) ;
116+ iOSProjectService . prepareDynamicFrameworks = ( pluginPlatformsFolderPath : string , pluginData : IPluginData ) : IFuture < void > => {
117+ return Future . fromResult ( ) ;
118+ } ;
119+ iOSProjectService . removeDynamicFrameworks = ( pluginPlatformsFolderPath : string , pluginData : IPluginData ) : IFuture < void > => {
120+ return Future . fromResult ( ) ;
121+ }
122+
123+ let pluginPath = temp . mkdirSync ( "pluginDirectory" ) ;
124+ let pluginPlatformsFolderPath = path . join ( pluginPath , "platforms" , "ios" ) ;
125+ let pluginPodfilePath = path . join ( pluginPlatformsFolderPath , "Podfile" ) ;
126+ let pluginPodfileContent = [ "source 'https://github.com/CocoaPods/Specs.git'" , "platform :ios, '8.1'" , "pod 'GoogleMaps'" ] . join ( "\n" ) ;
127+ fs . writeFile ( pluginPodfilePath , pluginPodfileContent ) . wait ( ) ;
128+
129+ let pluginData = {
130+ pluginPlatformsFolderPath ( platform : string ) : string {
131+ return pluginPlatformsFolderPath ;
132+ }
133+ } ;
134+
135+ iOSProjectService . preparePluginNativeCode ( pluginData ) . wait ( ) ;
136+
137+ let projectPodfilePath = path . join ( platformsFolderPath , "Podfile" ) ;
138+ assert . isTrue ( fs . exists ( projectPodfilePath ) . wait ( ) ) ;
139+
140+ let actualProjectPodfileContent = fs . readText ( projectPodfilePath ) . wait ( ) ;
141+ let expectedProjectPodfileContent = [ `# Begin Podfile - ${ pluginPodfilePath } ` , ` ${ pluginPodfileContent } ` , " # End Podfile \n" ] . join ( "\n" ) ;
142+ assert . equal ( actualProjectPodfileContent , expectedProjectPodfileContent ) ;
143+
144+ iOSProjectService . removePluginNativeCode ( pluginData ) . wait ( ) ;
145+
146+ assert . isFalse ( fs . exists ( projectPodfilePath ) . wait ( ) ) ;
147+ } ) ;
148+ } ) ;
0 commit comments