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