Skip to content

Commit e2a7eee

Browse files
author
Kristian D. Dimitrov
committed
fix: unit tests
1 parent 18fb390 commit e2a7eee

23 files changed

+67
-50
lines changed

lib/pbxProject.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ pbxProject.prototype.findMainPbxGroup = function () {
510510
}
511511

512512
pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceTree, opt) {
513-
513+
opt = opt || {};
514514
var oldGroup = this.pbxGroupByName(name);
515515
if (oldGroup) {
516516
this.removePbxGroup(name, path);
@@ -523,6 +523,7 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
523523
isa: 'PBXGroup',
524524
children: [],
525525
name: name,
526+
path: path,
526527
sourceTree: sourceTree ? sourceTree : '"<group>"'
527528
},//path is mandatory only for the main group
528529
fileReferenceSection = this.pbxFileReferenceSection(),
@@ -551,23 +552,29 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
551552

552553
var srcRootPath = $path.dirname($path.dirname(this.filepath));
553554
var file = new pbxFile($path.relative(srcRootPath, filePath));
554-
if (fs.lstatSync(filePath).isDirectory()) {
555+
if (fs.existsSync(filePath) && fs.lstatSync(filePath).isDirectory()) {
555556
file.uuid = this.generateUuid();
556557
file.fileRef = file.uuid;
557558
this.addToPbxFileReferenceSection(file); // PBXFileReference
558559
this.addToPbxBuildFileSection(file);
559560
pbxGroup.children.push(pbxGroupChild(file));
560561
var files = fs.readdirSync(filePath).map(p => $path.join(filePath, p));
561562
this.addPbxGroup(files, $path.basename(filePath), filePath, null, {uuid: file.uuid});
562-
}else if (isSourceOrHeaderFileType(file.lastType)) {
563+
} else if (isSourceOrHeaderFileType(file.lastKnownFileType)) {
563564
file.uuid = this.generateUuid();
564565
file.fileRef = this.generateUuid();
565566
this.addToPbxFileReferenceSection(file); // PBXFileReference
566567
this.addToPbxBuildFileSection(file); // PBXBuildFile
567-
if (!isHeaderFileType(file.lastType)) {
568+
if (!isHeaderFileType(file.lastKnownFileType)) {
568569
this.addToPbxSourcesBuildPhase(file);
569570
}
570571
pbxGroup.children.push(pbxGroupChild(file));
572+
} else {
573+
file.uuid = this.generateUuid();
574+
file.fileRef = this.generateUuid();
575+
this.addToPbxFileReferenceSection(file); // PBXFileReference
576+
this.addToPbxBuildFileSection(file);
577+
pbxGroup.children.push(pbxGroupChild(file));
571578
}
572579

573580
}
@@ -594,6 +601,8 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
594601
if (!group) {
595602
return;
596603
}
604+
605+
path = path || $path.dirname(this.filepath);
597606

598607
var children = group.children;
599608

@@ -607,10 +616,13 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
607616
this.removeFromPbxSourcesBuildPhase(file);
608617
}
609618

610-
var mainGroupChildren = this.findMainPbxGroup().children, i;
611-
for(i in mainGroupChildren) {
612-
if (mainGroupChildren[i].comment == name) {
613-
mainGroupChildren.splice(i, 1);
619+
var mainGroup = this.findMainPbxGroup();
620+
if(mainGroup) {
621+
var mainGroupChildren = this.findMainPbxGroup().children, i;
622+
for(i in mainGroupChildren) {
623+
if (mainGroupChildren[i].comment == name) {
624+
mainGroupChildren.splice(i, 1);
625+
}
614626
}
615627
}
616628

@@ -1592,12 +1604,12 @@ function pbxFileReferenceObj(file) {
15921604
includeInIndex: file.includeInIndex
15931605
};
15941606

1595-
if(fileObject.name.indexOf("\"") !== -1) {
1607+
if(fileObject.name && fileObject.name.indexOf("\"") !== -1) {
15961608
fileObject.name = fileObject.name.replace(/\"/g, "\\\"");
15971609
fileObject.path = fileObject.path.replace(/\"/g, "\\\"");
15981610
}
15991611

1600-
if(!file.basename.match(NO_SPECIAL_SYMBOLS)) {
1612+
if(file.basename && !file.basename.match(NO_SPECIAL_SYMBOLS)) {
16011613
fileObject.name = "\"" + fileObject.name + "\"";
16021614
}
16031615

test/BuildSettings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {

test/FrameworkSearchPaths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
var pbxFile = {

test/HeaderSearchPaths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {

test/LibrarySearchPaths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {

test/OtherLinkerFlags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {

test/addFramework.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {
@@ -98,7 +98,7 @@ exports.addFramework = {
9898

9999
test.equal(fileRefEntry.isa, 'PBXFileReference');
100100
test.equal(fileRefEntry.lastKnownFileType, 'compiled.mach-o.dylib');
101-
test.equal(fileRefEntry.name, '"libsqlite3.dylib"');
101+
test.equal(fileRefEntry.name, 'libsqlite3.dylib');
102102
test.equal(fileRefEntry.path, '"usr/lib/libsqlite3.dylib"');
103103
test.equal(fileRefEntry.sourceTree, 'SDKROOT');
104104

test/addHeaderFile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {
@@ -70,8 +70,8 @@ exports.addHeaderFile = {
7070
test.equal(fileRefEntry.isa, 'PBXFileReference');
7171
test.equal(fileRefEntry.fileEncoding, 4);
7272
test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.h');
73-
test.equal(fileRefEntry.name, '"file.h"');
74-
test.equal(fileRefEntry.path, '"file.h"');
73+
test.equal(fileRefEntry.name, 'file.h');
74+
test.equal(fileRefEntry.path, 'file.h');
7575
test.equal(fileRefEntry.sourceTree, '"<group>"');
7676

7777
test.done();

test/addRemovePbxGroup.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ exports.addRemovePbxGroup = {
169169
proj.removePbxGroup(groupName);
170170

171171
var pbxGroupInPbx = proj.pbxGroupByName(groupName);
172-
console.log(pbxGroupInPbx);
173172

174173
test.ok(!pbxGroupInPbx);
175174
test.done()

test/addResourceFile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {
@@ -108,7 +108,7 @@ exports.addResourceFile = {
108108
test.equal(fileRefEntry.isa, 'PBXFileReference');
109109
test.equal(fileRefEntry.fileEncoding, undefined);
110110
test.equal(fileRefEntry.lastKnownFileType, 'wrapper.plug-in');
111-
test.equal(fileRefEntry.name, '"assets.bundle"');
111+
test.equal(fileRefEntry.name, 'assets.bundle');
112112
test.equal(fileRefEntry.path, '"Resources/assets.bundle"');
113113
test.equal(fileRefEntry.sourceTree, '"<group>"');
114114

@@ -169,7 +169,7 @@ exports.addResourceFile = {
169169
test.equal(fileRefEntry.isa, 'PBXFileReference');
170170
test.equal(fileRefEntry.fileEncoding, undefined);
171171
test.equal(fileRefEntry.lastKnownFileType, 'wrapper.plug-in');
172-
test.equal(fileRefEntry.name, '"assets.bundle"');
172+
test.equal(fileRefEntry.name, 'assets.bundle');
173173
test.equal(fileRefEntry.path, '"Plugins/assets.bundle"');
174174
test.equal(fileRefEntry.sourceTree, '"<group>"');
175175
test.done();

0 commit comments

Comments
 (0)