Skip to content

Commit f94ad9b

Browse files
committed
tests(adddTarget): Added unit tests for new addTarget feature.
1 parent 0f6c8ac commit f94ad9b

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
@@ -0,0 +1,89 @@
1+
var fullProject = require('./fixtures/full-project')
2+
fullProjectStr = JSON.stringify(fullProject),
3+
pbx = require('../lib/pbxProject'),
4+
proj = new pbx('.');
5+
6+
function cleanHash() {
7+
return JSON.parse(fullProjectStr);
8+
}
9+
10+
var TARGET_NAME = 'TestExtension',
11+
TARGET_TYPE = 'app_extension',
12+
TARGET_SUBFOLDER_NAME = 'TestExtensionFiles';
13+
14+
exports.setUp = function (callback) {
15+
proj.hash = cleanHash();
16+
callback();
17+
}
18+
19+
exports.addTarget = {
20+
'should throw when target name is missing': function (test) {
21+
test.throws(function() {
22+
proj.addTarget(null, TARGET_TYPE);
23+
});
24+
25+
test.done();
26+
},
27+
'should throw when target type missing': function (test) {
28+
test.throws(function() {
29+
proj.addTarget(TARGET_NAME, null);
30+
});
31+
32+
test.done();
33+
},
34+
'should create a new target': function (test) {
35+
var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME);
36+
37+
test.ok(typeof target == 'object');
38+
test.ok(target.uuid);
39+
test.ok(target.pbxNativeTarget);
40+
test.ok(target.pbxNativeTarget.isa);
41+
test.ok(target.pbxNativeTarget.name);
42+
test.ok(target.pbxNativeTarget.productName);
43+
test.ok(target.pbxNativeTarget.productReference);
44+
test.ok(target.pbxNativeTarget.productType);
45+
test.ok(target.pbxNativeTarget.buildConfigurationList);
46+
test.ok(target.pbxNativeTarget.buildPhases);
47+
test.ok(target.pbxNativeTarget.buildRules);
48+
test.ok(target.pbxNativeTarget.dependencies);
49+
50+
test.done();
51+
},
52+
'should create a new target and add source, framework, resource and header files and the corresponding build phases': function (test) {
53+
var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME),
54+
options = { 'target' : target.uuid };
55+
56+
var sourceFile = proj.addSourceFile('Plugins/file.m', options),
57+
sourcePhase = proj.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid),
58+
resourceFile = proj.addResourceFile('assets.bundle', options),
59+
resourcePhase = proj.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid),
60+
frameworkFile = proj.addFramework('libsqlite3.dylib', options);
61+
frameworkPhase = proj.addBuildPhase([], 'PBXFrameworkBuildPhase', 'Frameworks', target.uuid),
62+
headerFile = proj.addHeaderFile('file.h', options);
63+
64+
test.ok(sourcePhase);
65+
test.ok(resourcePhase);
66+
test.ok(frameworkPhase);
67+
68+
test.equal(sourceFile.constructor, pbxFile);
69+
test.equal(resourceFile.constructor, pbxFile);
70+
test.equal(frameworkFile.constructor, pbxFile);
71+
test.equal(headerFile.constructor, pbxFile);
72+
73+
test.ok(typeof target == 'object');
74+
test.ok(target.uuid);
75+
test.ok(target.pbxNativeTarget);
76+
test.ok(target.pbxNativeTarget.isa);
77+
test.ok(target.pbxNativeTarget.name);
78+
test.ok(target.pbxNativeTarget.productName);
79+
test.ok(target.pbxNativeTarget.productReference);
80+
test.ok(target.pbxNativeTarget.productType);
81+
test.ok(target.pbxNativeTarget.buildConfigurationList);
82+
test.ok(target.pbxNativeTarget.buildPhases);
83+
test.ok(target.pbxNativeTarget.buildRules);
84+
test.ok(target.pbxNativeTarget.dependencies);
85+
86+
test.done();
87+
88+
}
89+
}

0 commit comments

Comments
 (0)