@@ -2,26 +2,49 @@ import { Yok } from "../../../lib/common/yok";
2
2
import { ExportOptionsPlistService } from "../../../lib/services/ios/export-options-plist-service" ;
3
3
import { assert } from "chai" ;
4
4
import * as _ from "lodash" ;
5
- import { TempServiceStub } from "../../stubs" ;
5
+ import { TempServiceStub , ProjectDataStub } from "../../stubs" ;
6
6
7
7
let actualPlistTemplate : string = null ;
8
8
const projectName = "myProjectName" ;
9
9
const projectRoot = "/my/test/project/platforms/ios" ;
10
10
const archivePath = "/my/test/archive/path" ;
11
11
12
+ let provisioningJSON : Record < string , any > | undefined ;
13
+
12
14
function createTestInjector ( ) {
13
15
const injector = new Yok ( ) ;
16
+ provisioningJSON = undefined ;
14
17
injector . register ( "fs" , {
18
+ exists ( path : string ) {
19
+ return path . endsWith ( "provisioning.json" ) ;
20
+ } ,
15
21
writeFile : ( exportPath : string , plistTemplate : string ) => {
16
22
actualPlistTemplate = plistTemplate ;
17
23
} ,
24
+ readJson ( ) {
25
+ return provisioningJSON ?? { } ;
26
+ } ,
18
27
} ) ;
19
28
injector . register ( "exportOptionsPlistService" , ExportOptionsPlistService ) ;
20
29
injector . register ( "tempService" , TempServiceStub ) ;
30
+ const projectData = new ProjectDataStub ( ) ;
31
+ projectData . initializeProjectData ( projectRoot ) ;
32
+ projectData . projectName = projectName ;
33
+
34
+ injector . register ( "projectData" , projectData ) ;
21
35
22
36
return injector ;
23
37
}
24
38
39
+ function expectPlistTemplateToContain ( template : string , expected : string ) {
40
+ const trimmedTemplate = template . replace ( / \s / g, "" ) ;
41
+ const trimmedExpected = expected . replace ( / \s / g, "" ) ;
42
+ assert . isTrue (
43
+ trimmedTemplate . indexOf ( trimmedExpected ) !== - 1 ,
44
+ `Expected plist template to contain:\n\n${ expected } \n\nbut it was:\n\n${ template } `
45
+ ) ;
46
+ }
47
+
25
48
describe ( "ExportOptionsPlistService" , ( ) => {
26
49
describe ( "createDevelopmentExportOptionsPlist" , ( ) => {
27
50
const testCases = [
@@ -33,21 +56,29 @@ describe("ExportOptionsPlistService", () => {
33
56
name : "should create export options plist with provision" ,
34
57
buildConfig : { provision : "myTestProvision" } ,
35
58
expectedPlist :
36
- "<key>provisioningProfiles</key> <dict> <key>org.nativescript.myTestApp</key> <string>myTestProvision</string> </dict>" ,
59
+ "<key>provisioningProfiles</key><dict><key>org.nativescript.myTestApp</key><string>myTestProvision</string></dict>" ,
37
60
} ,
38
61
{
39
- name :
40
- "should create export options plist with mobileProvisionIdentifier" ,
62
+ name : "should create export options plist with mobileProvisionIdentifier" ,
41
63
buildConfig : { mobileProvisionIdentifier : "myTestProvision" } ,
42
64
expectedPlist :
43
- "<key>provisioningProfiles</key> <dict> <key>org.nativescript.myTestApp</key> <string>myTestProvision</string> </dict>" ,
65
+ "<key>provisioningProfiles</key><dict><key>org.nativescript.myTestApp</key><string>myTestProvision</string></dict>" ,
44
66
} ,
45
67
{
46
- name :
47
- "should create export options plist with Production iCloudContainerEnvironment" ,
68
+ name : "should create export options plist with Production iCloudContainerEnvironment" ,
48
69
buildConfig : { iCloudContainerEnvironment : "Production" } ,
49
70
expectedPlist :
50
- "<key>iCloudContainerEnvironment</key> <string>Production</string>" ,
71
+ "<key>iCloudContainerEnvironment</key><string>Production</string>" ,
72
+ } ,
73
+ {
74
+ name : "should add extension provisioning profiles if there are any" ,
75
+ buildConfig : { provision : "myTestProvision" } ,
76
+ provisioningJSON : {
77
+ "org.nativescript.myTestApp.SampleExtension" :
78
+ "mySampleExtensionTestProvision" ,
79
+ } ,
80
+ expectedPlist :
81
+ "<key>provisioningProfiles</key><dict><key>org.nativescript.myTestApp</key><string>myTestProvision</string><key>org.nativescript.myTestApp.SampleExtension</key><string>mySampleExtensionTestProvision</string></dict>" ,
51
82
} ,
52
83
] ;
53
84
@@ -57,6 +88,9 @@ describe("ExportOptionsPlistService", () => {
57
88
( provisionType ) => {
58
89
it ( testCase . name , async ( ) => {
59
90
const injector = createTestInjector ( ) ;
91
+ if ( testCase . provisioningJSON ) {
92
+ provisioningJSON = testCase . provisioningJSON ;
93
+ }
60
94
const exportOptionsPlistService = injector . resolve (
61
95
"exportOptionsPlistService"
62
96
) ;
@@ -73,20 +107,23 @@ describe("ExportOptionsPlistService", () => {
73
107
testCase . buildConfig
74
108
) ;
75
109
76
- const template = actualPlistTemplate . split ( "\n" ) . join ( " " ) ;
77
- assert . isTrue (
78
- template . indexOf (
79
- `<key>method</key> <string>${ provisionType } </string>`
80
- ) > 0
110
+ expectPlistTemplateToContain (
111
+ actualPlistTemplate ,
112
+ `<key>method</key><string>${ provisionType } </string>`
81
113
) ;
82
- assert . isTrue (
83
- template . indexOf ( "<key>uploadBitcode</key> <false/>" ) > 0
114
+ expectPlistTemplateToContain (
115
+ actualPlistTemplate ,
116
+ `<key>uploadBitcode</key><false/>`
84
117
) ;
85
- assert . isTrue (
86
- template . indexOf ( "<key>compileBitcode</key> <false/>" ) > 0
118
+ expectPlistTemplateToContain (
119
+ actualPlistTemplate ,
120
+ `<key>compileBitcode</key><false/>`
87
121
) ;
88
122
if ( testCase . expectedPlist ) {
89
- assert . isTrue ( template . indexOf ( testCase . expectedPlist ) > 0 ) ;
123
+ expectPlistTemplateToContain (
124
+ actualPlistTemplate ,
125
+ testCase . expectedPlist
126
+ ) ;
90
127
}
91
128
} ) ;
92
129
}
@@ -103,25 +140,37 @@ describe("ExportOptionsPlistService", () => {
103
140
name : "should create export options plist with provision" ,
104
141
buildConfig : { provision : "myTestProvision" } ,
105
142
expectedPlist :
106
- "<key>provisioningProfiles</key> <dict> <key>org.nativescript.myTestApp</key> <string>myTestProvision</string> </dict>" ,
143
+ "<key>provisioningProfiles</key><dict><key>org.nativescript.myTestApp</key><string>myTestProvision</string></dict>" ,
107
144
} ,
108
145
{
109
- name :
110
- "should create export options plist with mobileProvisionIdentifier" ,
146
+ name : "should create export options plist with mobileProvisionIdentifier" ,
111
147
buildConfig : { mobileProvisionIdentifier : "myTestProvision" } ,
112
148
expectedPlist :
113
- "<key>provisioningProfiles</key> <dict> <key>org.nativescript.myTestApp</key> <string>myTestProvision</string> </dict>" ,
149
+ "<key>provisioningProfiles</key><dict><key>org.nativescript.myTestApp</key><string>myTestProvision</string></dict>" ,
114
150
} ,
115
151
{
116
152
name : "should create export options plist with teamID" ,
117
153
buildConfig : { teamId : "myTeamId" } ,
118
- expectedPlist : "<key>teamID</key> <string>myTeamId</string>" ,
154
+ expectedPlist : "<key>teamID</key><string>myTeamId</string>" ,
155
+ } ,
156
+ {
157
+ name : "should add extension provisioning profiles if there are any" ,
158
+ buildConfig : { provision : "myTestProvision" } ,
159
+ provisioningJSON : {
160
+ "org.nativescript.myTestApp.SampleExtension" :
161
+ "mySampleExtensionTestProvision" ,
162
+ } ,
163
+ expectedPlist :
164
+ "<key>provisioningProfiles</key><dict><key>org.nativescript.myTestApp</key><string>myTestProvision</string><key>org.nativescript.myTestApp.SampleExtension</key><string>mySampleExtensionTestProvision</string></dict>" ,
119
165
} ,
120
166
] ;
121
167
122
168
_ . each ( testCases , ( testCase ) => {
123
169
it ( testCase . name , async ( ) => {
124
170
const injector = createTestInjector ( ) ;
171
+ if ( testCase . provisioningJSON ) {
172
+ provisioningJSON = testCase . provisioningJSON ;
173
+ }
125
174
const exportOptionsPlistService = injector . resolve (
126
175
"exportOptionsPlistService"
127
176
) ;
@@ -137,22 +186,28 @@ describe("ExportOptionsPlistService", () => {
137
186
testCase . buildConfig
138
187
) ;
139
188
140
- const template = actualPlistTemplate . split ( "\n" ) . join ( " " ) ;
141
- assert . isTrue (
142
- template . indexOf ( "<key>method</key> <string>app-store</string>" ) >
143
- 0
189
+ expectPlistTemplateToContain (
190
+ actualPlistTemplate ,
191
+ `<key>method</key><string>app-store</string>`
144
192
) ;
145
- assert . isTrue (
146
- template . indexOf ( "<key>uploadBitcode</key> <false/>" ) > 0
193
+ expectPlistTemplateToContain (
194
+ actualPlistTemplate ,
195
+ `<key>uploadBitcode</key><false/>`
147
196
) ;
148
- assert . isTrue (
149
- template . indexOf ( "<key>compileBitcode</key> <false/>" ) > 0
197
+ expectPlistTemplateToContain (
198
+ actualPlistTemplate ,
199
+ `<key>compileBitcode</key><false/>`
150
200
) ;
151
- assert . isTrue (
152
- template . indexOf ( "<key>uploadSymbols</key> <false/>" ) > 0
201
+ expectPlistTemplateToContain (
202
+ actualPlistTemplate ,
203
+ `<key>uploadSymbols</key><false/>`
153
204
) ;
205
+
154
206
if ( testCase . expectedPlist ) {
155
- assert . isTrue ( template . indexOf ( testCase . expectedPlist ) > 0 ) ;
207
+ expectPlistTemplateToContain (
208
+ actualPlistTemplate ,
209
+ testCase . expectedPlist
210
+ ) ;
156
211
}
157
212
} ) ;
158
213
} ) ;
0 commit comments