Skip to content

Commit 8307518

Browse files
l3enderChris Brody
authored andcommitted
Add target test coverage (#82)
* addTarget coverage - target name * addTarget coverage - validate target type * addTarget coverage - build configuration validation * addTarget coverage - target name * addTarget coverage - target type/name error validation * addTarget coverage - strict match for build config comment * addTarget coverage - debug/release build config
1 parent 0d13735 commit 8307518

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

test/addTarget.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,35 @@ exports.addTarget = {
4242

4343
test.done();
4444
},
45+
'should throw when provided blank or empty target name': function (test) {
46+
test.throws(function() {
47+
proj.addTarget('', TARGET_TYPE);
48+
}, function (error) {
49+
return (error instanceof Error) && /Target name missing/i.test(error);
50+
});
51+
52+
test.throws(function() {
53+
proj.addTarget(' ', TARGET_TYPE);
54+
}, function (error) {
55+
return (error instanceof Error) && /Target name missing/i.test(error);
56+
});
57+
58+
test.done();
59+
},
4560
'should throw when target type missing': function (test) {
4661
test.throws(function() {
4762
proj.addTarget(TARGET_NAME, null);
63+
}, function (error) {
64+
return (error instanceof Error) && /Target type missing/i.test(error);
65+
});
66+
67+
test.done();
68+
},
69+
'should throw when invalid target type': function (test) {
70+
test.throws(function() {
71+
proj.addTarget(TARGET_NAME, 'invalid_target_type');
72+
}, function (error) {
73+
return (error instanceof Error) && /Target type invalid/i.test(error);
4874
});
4975

5076
test.done();
@@ -67,6 +93,60 @@ exports.addTarget = {
6793

6894
test.done();
6995
},
96+
'should add debug and release configurations to build configuration list': function (test) {
97+
var pbxXCBuildConfigurationSection = proj.pbxXCBuildConfigurationSection(),
98+
pbxXCConfigurationList = proj.pbxXCConfigurationList(),
99+
target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME);
100+
101+
test.ok(target.pbxNativeTarget.buildConfigurationList);
102+
test.ok(pbxXCConfigurationList[target.pbxNativeTarget.buildConfigurationList]);
103+
var buildConfigurations = pbxXCConfigurationList[target.pbxNativeTarget.buildConfigurationList].buildConfigurations;
104+
test.ok(buildConfigurations);
105+
test.equal(buildConfigurations.length, 2);
106+
107+
buildConfigurations.forEach((config, index) => {
108+
var configUuid = config.value;
109+
test.ok(configUuid);
110+
var pbxConfig = pbxXCBuildConfigurationSection[configUuid];
111+
test.ok(pbxConfig);
112+
test.equal(pbxConfig.name, index === 0 ? 'Debug' : 'Release');
113+
test.equal(pbxConfig.isa, 'XCBuildConfiguration');
114+
test.ok(pbxConfig.buildSettings);
115+
if (index === 0) {
116+
var debugConfig = pbxConfig.buildSettings['GCC_PREPROCESSOR_DEFINITIONS'];
117+
test.ok(debugConfig);
118+
test.equal(debugConfig.length, 2);
119+
test.equal(debugConfig[0], '"DEBUG=1"');
120+
test.equal(debugConfig[1], '"$(inherited)"');
121+
}
122+
test.equal(pbxConfig.buildSettings['INFOPLIST_FILE'], '"' + TARGET_SUBFOLDER_NAME + '/' + TARGET_SUBFOLDER_NAME + '-Info.plist"');
123+
test.equal(pbxConfig.buildSettings['LD_RUNPATH_SEARCH_PATHS'], '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"');
124+
test.equal(pbxConfig.buildSettings['PRODUCT_NAME'], '"' + TARGET_NAME + '"');
125+
test.equal(pbxConfig.buildSettings['SKIP_INSTALL'], 'YES');
126+
});
127+
128+
test.done();
129+
},
130+
'should add to build configuration list with default configuration name': function (test) {
131+
var pbxXCConfigurationList = proj.pbxXCConfigurationList(),
132+
target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME);
133+
134+
test.ok(target.pbxNativeTarget.buildConfigurationList);
135+
test.ok(pbxXCConfigurationList[target.pbxNativeTarget.buildConfigurationList]);
136+
test.equal(pbxXCConfigurationList[target.pbxNativeTarget.buildConfigurationList].defaultConfigurationName, 'Release');
137+
138+
test.done();
139+
},
140+
'should add to build configuration list with comment': function (test) {
141+
var pbxXCConfigurationList = proj.pbxXCConfigurationList(),
142+
target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME);
143+
144+
var buildCommentKey = target.pbxNativeTarget.buildConfigurationList + '_comment';
145+
test.ok(pbxXCConfigurationList[buildCommentKey]);
146+
test.equals(pbxXCConfigurationList[buildCommentKey], 'Build configuration list for PBXNativeTarget "' + TARGET_NAME + '"');
147+
148+
test.done();
149+
},
70150
'should create a new target and add source, framework, resource and header files and the corresponding build phases': function (test) {
71151
var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME),
72152
options = { 'target' : target.uuid };
@@ -103,6 +183,15 @@ exports.addTarget = {
103183

104184
test.done();
105185
},
186+
'should create target with correct pbxNativeTarget name': function (test) {
187+
var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME);
188+
189+
var quotedTargetName = '"' + TARGET_NAME + '"';
190+
test.equals(target.pbxNativeTarget.name, quotedTargetName);
191+
test.equals(target.pbxNativeTarget.productName, quotedTargetName);
192+
193+
test.done();
194+
},
106195
'should add build phase for extension target': function (test) {
107196
var target = proj.addTarget(TARGET_NAME, TARGET_TYPE);
108197
test.ok(target.uuid);

0 commit comments

Comments
 (0)