Skip to content

Commit

Permalink
Fixed GHI #103 [You cannot sign and use web inspector anymore] + unit…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
James Keshavarzi authored and nukulb committed May 28, 2012
1 parent b5146f9 commit 1c1f0b2
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 20 deletions.
19 changes: 10 additions & 9 deletions lib/native-packager.js
Expand Up @@ -99,10 +99,12 @@ function generateTabletXMLFile(session, config) {

function generateOptionsFile(session, target, config) {
var srcFiles = wrench.readdirSyncRecursive(session.sourceDir),
isSigning = session.keystore && session.storepass && config.buildId,
optionsStr = "-package" + NL,
debugToken;

if (session.debug) {

//if -d was provided and we are not signing [-g], set debugToken
if (session.debug && !isSigning) {
if (path.extname(conf.DEBUG_TOKEN) === ".bar") {
if (path.existsSync(conf.DEBUG_TOKEN)) {
debugToken = "-debugToken" + NL;
Expand All @@ -116,25 +118,24 @@ function generateOptionsFile(session, target, config) {
}
}

//TODO add logic to use proper buildId (i.e. -buildId or 4rth octet in version)
//getBuildId();

//Signing params
if (target === "device" && session.keystore && session.storepass && config.buildId) {
if (target === "device" && isSigning) {
//Signing params
optionsStr += "-sign" + NL;
optionsStr += "-keystore" + NL;
optionsStr += session.keystore + NL;
optionsStr += "-storepass" + NL;
optionsStr += session.storepass + NL;
optionsStr += "-buildId" + NL;
optionsStr += config.buildId + NL;
} else if (session.debug) {
//DebugToken params
optionsStr += "-devMode" + NL;
optionsStr += (debugToken ? debugToken : "");
}

optionsStr += path.resolve(util.format(session.barPath, target)) + NL;
optionsStr += "-C" + NL;
optionsStr += session.sourceDir + NL;
optionsStr += (session.debug ? ("-devMode" + NL) : "");
optionsStr += (debugToken ? debugToken : "");
optionsStr += "blackberry-tablet.xml" + NL;

srcFiles.forEach(function (file) {
Expand Down
40 changes: 40 additions & 0 deletions test/unit/lib/native-packager.js
Expand Up @@ -6,6 +6,7 @@ var path = require("path"),
srcPath = __dirname + "/../../../lib/",
nativePkgr = require(srcPath + "/native-packager"),
pkgrUtils = require(srcPath + "/packager-utils"),
testUtils = require("./test-utilities"),
testData = require("./test-data"),
logger = require(srcPath + "logger"),
localize = require(srcPath + "/localize"),
Expand Down Expand Up @@ -125,4 +126,43 @@ describe("Native packager", function () {
expect(childProcess.spawn).toHaveBeenCalledWith(cmd, ["@options"], {"cwd": session.sourceDir, "env": process.env});
expect(callback).toHaveBeenCalledWith(0);
});

it("omits -devMode when signing and specifying -d", function () {
testUtils.mockResolve(path);

var session = testUtils.cloneObj(testData.session),
config = testUtils.cloneObj(testData.config),
target = "device",
NL = pkgrUtils.isWindows() ? "\r\n" : "\n",
optionsFile = "-package" + NL +
"-sign" + NL +
"-keystore" + NL +
path.normalize("c:/author.p12") + NL +
"-storepass" + NL +
"password" + NL +
"-buildId" + NL +
"100" + NL +
path.normalize("c:/device/Demo.bar") + NL +
"-C" + NL +
path.normalize("c:/src/") + NL +
"blackberry-tablet.xml" + NL +
path.normalize("c:/src/abc") + NL +
path.normalize("c:/src/xyz") + NL;

//Set signing params [-g --buildId]
session.keystore = path.normalize("c:/author.p12");
session.storepass = "password";
config.buildId = "100";

session.barPath = path.normalize("c:/%s/" + "Demo.bar");
session.sourceDir = path.normalize("c:/src/");

//Set -d param
session.debug = "";

nativePkgr.exec(session, target, config, callback);

//options file should NOT contain -devMode
expect(fs.writeFileSync).toHaveBeenCalledWith(jasmine.any(String), optionsFile);
});
});
15 changes: 4 additions & 11 deletions test/unit/lib/session.js
@@ -1,15 +1,8 @@
var session = require(__dirname + "/../../../lib/session"),
testUtils = require("./test-utilities"),
path = require("path"),
wrench = require("wrench"),
zipLocation = __dirname + "/../../config.xml";

function mockResolve() {
//Mocking resolve because of a weird issue where resolve would return an
//invalid path on Mac if it cannot find the directory (c:/ doesnt exist on mac)
spyOn(path, "resolve").andCallFake(function (myPath) {
return path.normalize(myPath);
});
}

describe("Session", function () {
beforeEach(function () {
Expand All @@ -18,7 +11,7 @@ describe("Session", function () {
});

it("sets the source directory correctly when specified [-s C:/sampleApp/mySource]", function () {
mockResolve();
testUtils.mockResolve(path);

var data = {
args: [ 'C:/sampleApp/sample.zip' ],
Expand All @@ -31,7 +24,7 @@ describe("Session", function () {
});

it("sets the source directory correctly when unspecified [-s] and output path set [-o]", function () {
mockResolve();
testUtils.mockResolve(path);

var data = {
args: [ 'C:/sampleApp/sample.zip' ],
Expand All @@ -45,7 +38,7 @@ describe("Session", function () {
});

it("sets the source directory correctly when unspecified [-s] and no output path is set", function () {
mockResolve();
testUtils.mockResolve(path);

var data = {
args: [ zipLocation ],
Expand Down
13 changes: 13 additions & 0 deletions test/unit/lib/test-utilities.js
Expand Up @@ -15,6 +15,19 @@ module.exports = {
return getObjectByProperty(featureArray, "id", featureID);
},

mockResolve: function (path) {
//Mock resolve because of a weird issue where resolve would return an
//invalid path on Mac if it cannot find the directory (c:/ doesnt exist on mac)
spyOn(path, "resolve").andCallFake(function (to) {
if (arguments.length === 2) {
//Handle optional from attribute
return path.normalize(path.join(arguments[0], arguments[1]));
} else {
return path.normalize(to);
}
});
},

cloneObj: function (obj) {
var newObj = (obj instanceof Array) ? [] : {}, i;

Expand Down

0 comments on commit 1c1f0b2

Please sign in to comment.