[CB-3741] Switching from childProcess to shellJS to avoid output related
issues on Windows.


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/397af324
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/397af324
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/397af324

Branch: refs/heads/master
Commit: 397af324ab143c6061bc265ecd11192e8eb1205a
Parents: db75de5
Author: Jeffrey Heifetz <[email protected]>
Authored: Thu Jun 20 11:35:12 2013 -0400
Committer: Jeffrey Heifetz <[email protected]>
Committed: Fri Jun 21 17:43:07 2013 -0400

----------------------------------------------------------------------
 blackberry10/.gitignore                         |   1 +
 .../bin/test/cordova/integration/create.js      | 126 ++++-------
 .../bin/test/cordova/integration/target.js      | 213 +++++--------------
 .../test/cordova/unit/spec/lib/i18n-manager.js  |  49 +++--
 .../bin/test/cordova/unit/spec/lib/session.js   |   2 +-
 5 files changed, 130 insertions(+), 261 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/397af324/blackberry10/.gitignore
----------------------------------------------------------------------
diff --git a/blackberry10/.gitignore b/blackberry10/.gitignore
index 5fc9030..88eb1b3 100644
--- a/blackberry10/.gitignore
+++ b/blackberry10/.gitignore
@@ -21,3 +21,4 @@ bin/templates/project/lib
 example/
 node_modules/
 bin/templates/project/cordova/lib/utils.js
+.tmp

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/397af324/blackberry10/bin/test/cordova/integration/create.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/test/cordova/integration/create.js 
b/blackberry10/bin/test/cordova/integration/create.js
index b27ac4e..d9ef6e6 100644
--- a/blackberry10/bin/test/cordova/integration/create.js
+++ b/blackberry10/bin/test/cordova/integration/create.js
@@ -22,47 +22,42 @@ var childProcess = require('child_process'),
     appFolder = tempFolder + 'tempCordovaApp/',
     projectFile = 'project.json',
     wrench = require('wrench'),
+    utils = require('../../../lib/utils'),
+    path = require('path'),
     fs = require('fs'),
-    flag = false,
-    timeout = 10000,
-    _stdout = "",
-    _stderr = "";
+    shell = require("shelljs"),
+    _output = "",
+    CREATE_COMMAND = path.normalize(__dirname + "/../../../create") + 
(utils.isWindows() ? ".bat" : "");
 
-function executeScript(shellCommand, shouldError) {
-    childProcess.exec(shellCommand, function (error, stdout, stderr) {
-        if (error && !shouldError) {
-            console.log("Error executing command: " + error);
-        }
-        _stdout = stdout.toString().trim();
-        _stderr = stderr.toString().trim();
-        flag = true;
-    });
+function executeScript(shellCommand, args, shouldError) {
+    var strCommand = "\"" + shellCommand + "\" " + args.join(" "),
+        result;
+
+    //console.log("CREATE About to execute ", strCommand, (new Date()), 
"\n\n\n");
+    result = shell.exec(strCommand, {silent: true, async: false});
+    //console.log(result.output, "\n\n\n");
+    //console.log("Finished executing  with code ", result.code, " at ", (new 
Date()), "\n\n\n");
+    _output = result.output;
 }
 
 describe("create tests", function () {
     it("creates project", function () {
         var project,
             appIdRegExp = /id="default\.app\.id"/g;
-        executeScript("bin/create " + appFolder);
-        waitsFor(function () {
-            return flag;
-        },timeout);
-        runs(function () {
-            flag = false;
-            project = JSON.parse(fs.readFileSync(appFolder + projectFile, 
"utf-8"));
-            expect(appIdRegExp.test(fs.readFileSync(appFolder + 
"www/config.xml", "utf-8"))).toEqual(true);
-            expect(fs.existsSync(appFolder)).toEqual(true);
-            expect(fs.existsSync(appFolder + "/plugins")).toEqual(true);
-            expect(fs.existsSync(appFolder + "/cordova")).toEqual(true);
-            expect(fs.existsSync(appFolder + 
"/cordova/node_modules")).toEqual(true);
-            expect(fs.existsSync(appFolder + "/cordova/lib")).toEqual(true);
-            expect(fs.existsSync(appFolder + 
"/cordova/third_party")).toEqual(true);
-            expect(fs.existsSync(appFolder + "/www")).toEqual(true);
-            expect(project.barName).toEqual("cordova-BB10-app");
-            expect(project.defaultTarget).toEqual("");
-            expect(project.targets).toEqual({});
-            expect(fs.existsSync("./build")).toEqual(false);
-        });
+        executeScript(CREATE_COMMAND, [appFolder]);
+        project = JSON.parse(fs.readFileSync(appFolder + projectFile, 
"utf-8"));
+        expect(appIdRegExp.test(fs.readFileSync(appFolder + "www/config.xml", 
"utf-8"))).toEqual(true);
+        expect(fs.existsSync(appFolder)).toEqual(true);
+        expect(fs.existsSync(appFolder + "/plugins")).toEqual(true);
+        expect(fs.existsSync(appFolder + "/cordova")).toEqual(true);
+        expect(fs.existsSync(appFolder + 
"/cordova/node_modules")).toEqual(true);
+        expect(fs.existsSync(appFolder + "/cordova/lib")).toEqual(true);
+        expect(fs.existsSync(appFolder + 
"/cordova/third_party")).toEqual(true);
+        expect(fs.existsSync(appFolder + "/www")).toEqual(true);
+        expect(project.barName).toEqual("cordova-BB10-app");
+        expect(project.defaultTarget).toEqual("");
+        expect(project.targets).toEqual({});
+        expect(fs.existsSync("./build")).toEqual(false);
         this.after(function () {
             wrench.rmdirSyncRecursive(tempFolder);
         });
@@ -71,14 +66,9 @@ describe("create tests", function () {
     it("sets appId", function () {
         var configEt,
             appIdRegExp = /id="com\.example\.bb10app"/g;
-        executeScript("bin/create " + appFolder + " com.example.bb10app");
-        waitsFor(function () {
-            return flag;
-        },timeout);
-        runs(function () {
-            flag = false;
-            expect(appIdRegExp.test(fs.readFileSync(appFolder + 
"www/config.xml", "utf-8"))).toEqual(true);
-        });
+
+        executeScript(CREATE_COMMAND, [appFolder, "com.example.bb10app"]);
+        expect(appIdRegExp.test(fs.readFileSync(appFolder + "www/config.xml", 
"utf-8"))).toEqual(true); 
         this.after(function () {
             wrench.rmdirSyncRecursive(tempFolder);
         });
@@ -87,62 +77,32 @@ describe("create tests", function () {
     it("sets appId and barName", function () {
         var project,
             appIdRegExp = /id="com\.example\.bb10app"/g;
-        executeScript("bin/create " + appFolder + " com.example.bb10app 
bb10appV1");
-        waitsFor(function () {
-            return flag;
-        },timeout);
-        runs(function () {
-            flag = false;
-            project = JSON.parse(fs.readFileSync(appFolder + projectFile, 
"utf-8"));
-            expect(appIdRegExp.test(fs.readFileSync(appFolder + 
"www/config.xml", "utf-8"))).toEqual(true);
-            expect(project.barName).toEqual("bb10appV1");
-        });
+        executeScript(CREATE_COMMAND, [appFolder, "com.example.bb10app", 
"bb10appV1"]);
+        project = JSON.parse(fs.readFileSync(appFolder + projectFile, 
"utf-8"));
+        expect(appIdRegExp.test(fs.readFileSync(appFolder + "www/config.xml", 
"utf-8"))).toEqual(true);
+        expect(project.barName).toEqual("bb10appV1");
         this.after(function () {
             wrench.rmdirSyncRecursive(tempFolder);
         });
     });
 
     it("No args", function () {
-        executeScript("bin/create", true);
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            expect(_stdout).toContain("You must give a project PATH");
-        });
+        executeScript(CREATE_COMMAND, [], true);
+        expect(_output).toContain("You must give a project PATH");  
     });
 
     it("Empty dir error", function () {
-        executeScript("bin/create ./", true);
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            expect(_stdout).toContain("The project path must be an empty 
directory");
-        });
+        executeScript(CREATE_COMMAND, ["./"], true);
+        expect(_output).toContain("The project path must be an empty 
directory");   
     });
 
     it("Invalid appId error", function () {
-        executeScript("bin/create " + appFolder + " 23.21#$", true);
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            expect(_stdout).toContain("App ID must be sequence of 
alpha-numeric (optionally seperated by '.') characters, no longer than 50 
characters");
-        });
+        executeScript(CREATE_COMMAND, [appFolder, "23.21#$"], true);
+        expect(_output).toContain("App ID must be sequence of alpha-numeric 
(optionally seperated by '.') characters, no longer than 50 characters");
     });
 
     it("Invalid barName error", function () {
-        executeScript("bin/create " + appFolder + " com.example.app 
%bad@bar^name", true);
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            expect(_stdout).toContain("BAR filename can only contain 
alpha-numeric, '.', '-' and '_' characters");
-        });
+        executeScript(CREATE_COMMAND, [appFolder, "com.example.app", 
"%bad@bar^name"], true);
+        expect(_output).toContain("BAR filename can only contain 
alpha-numeric, '.', '-' and '_' characters");
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/397af324/blackberry10/bin/test/cordova/integration/target.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/test/cordova/integration/target.js 
b/blackberry10/bin/test/cordova/integration/target.js
index 4ff2ed9..b7f283c 100644
--- a/blackberry10/bin/test/cordova/integration/target.js
+++ b/blackberry10/bin/test/cordova/integration/target.js
@@ -25,21 +25,22 @@ var childProcess = require('child_process'),
     utils = require('../../../lib/utils'),
     fs = require('fs'),
     path = require('path'),
+    shell = require("shelljs"),
     configPath = utils.getPropertiesFilePath(),
-    flag = false,
     testAppCreated = false,
-    _stdout = "",
-    _stderr = "";
-
-function executeScript(shellCommand) {
-    childProcess.exec(shellCommand, function (error, stdout, stderr) {
-        if (error) {
-            //console.log("Error executing command: " + error);
-        }
-        _stdout = stdout.toString().trim();
-        _stderr = stderr.toString().trim();
-        flag = true;
-    });
+    _output = "",
+    CREATE_COMMAND = path.normalize(__dirname + "/../../../create") + 
(utils.isWindows() ? ".bat" : ""),
+    TARGET_COMMAND = path.normalize(appFolder + "cordova/target") + 
(utils.isWindows() ? ".bat" : "");
+
+function executeScript(shellCommand, args, shouldFail) {
+    var strCommand = "\"" + shellCommand + "\" " + args.join(" "),
+        result;
+
+    //console.log("CREATE About to execute ", strCommand, (new Date()), 
"\n\n\n");
+    result = shell.exec(strCommand, {silent: true, async: false});
+    //console.log(result.output, "\n\n\n");
+    //console.log("Finished executing  with code ", result.code, " at ", (new 
Date()), "\n\n\n");
+    _output = result.output;
 }
 
 describe("cordova/target tests", function () {
@@ -47,14 +48,8 @@ describe("cordova/target tests", function () {
         utils.copyFile(configPath, path.join(utils.getCordovaDir(), 
"bb10bak"));
         fs.unlinkSync(configPath);
         if (!testAppCreated) {
-            executeScript("bin/create " + appFolder);
-            waitsFor(function () {
-                return flag;
-            },9000);
-            runs(function () {
-                testAppCreated = true;
-                flag = false;
-            });
+            executeScript(CREATE_COMMAND , [appFolder]);
+            testAppCreated = true;
         }
     });
 
@@ -66,159 +61,70 @@ describe("cordova/target tests", function () {
     it("should add a target", function () {
         var project,
             target;
-        executeScript(appFolder + "cordova/target add z10 169.254.0.1 -t 
device -p pass --pin DEADBEEF");
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            project = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
-            expect(project.defaultTarget).toEqual("z10");
-            expect(Object.keys(project.targets).length).toEqual(1);
-            target = project.targets.z10;
-            expect(target.ip).toEqual("169.254.0.1");
-            expect(target.type).toEqual("device");
-            expect(target.password).toEqual("pass");
-            expect(target.pin).toEqual("DEADBEEF");
-            expect(_stdout).toEqual("");
-            expect(_stderr).toEqual("");
-        });
+
+        executeScript(TARGET_COMMAND, ["add", "z10", "169.254.0.1", "-t", 
"device", "-p", "pass", "--pin", "DEADBEEF"]);
+        project = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
+        expect(project.defaultTarget).toEqual("z10");
+        expect(Object.keys(project.targets).length).toEqual(1);
+        target = project.targets.z10;
+        expect(target.ip).toEqual("169.254.0.1");
+        expect(target.type).toEqual("device");
+        expect(target.password).toEqual("pass");
+        expect(target.pin).toEqual("DEADBEEF");
+        expect(_output).toEqual("");
     });
 
     it("should remove a target", function () {
         var project;
-        executeScript(appFolder + "cordova/target add z10 169.254.0.1 -t 
device -p pass --pin DEADBEEF");
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            executeScript(appFolder + "cordova/target remove z10");
-            waitsFor(function () {
-                return flag;
-            });
-            runs(function () {
-                flag = false;
-                project = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
-                expect(project.defaultTarget).toEqual("");
-                expect(Object.keys(project.targets).length).toEqual(0);
-                expect(_stdout).toEqual("Deleting default target, please set a 
new default target");
-                expect(_stderr).toEqual("");
-            });
-        });
+
+        executeScript(TARGET_COMMAND, ["add", "z10", "169.254.0.1", "-t", 
"device", "-p", "pass", "--pin", "DEADBEEF"]);
+        executeScript(TARGET_COMMAND , ["remove", "z10"]);
+        project = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
+        expect(project.defaultTarget).toEqual("");
+        expect(Object.keys(project.targets).length).toEqual(0);
+        expect(_output).toContain("Deleting default target, please set a new 
default target");
     });
 
     it("should set default target", function () {
         var project;
-        executeScript(appFolder + "cordova/target add z10 169.254.0.1 -t 
device -p pass --pin DEADBEEF");
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            executeScript(appFolder + "cordova/target add q10 169.254.0.2 -t 
device -p p455w02D --pin FACEFACE");
-            waitsFor(function () {
-                return flag;
-            });
-            runs(function () {
-                flag = false;
-                executeScript(appFolder + "cordova/target default q10");
-                waitsFor(function () {
-                    return flag;
-                });
-                runs(function () {
-                    flag = false;
-                    project = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
-                    expect(project.defaultTarget).toEqual("q10");
-                });
-            });
-        });
+
+        executeScript(TARGET_COMMAND, ["add", "z10", "169.254.0.1", "-t", 
"device", "-p", "pass", "--pin", "DEADBEEF"]);
+        executeScript(TARGET_COMMAND, ["add", "q10", "169.254.0.2", "-t", 
"device", "-p", "p455w02D", "--pin", "FACEFACE"]);
+        executeScript(TARGET_COMMAND, ["default", "q10"]);
+        project = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
+        expect(project.defaultTarget).toEqual("q10");
     });
 
     it("should list targets", function () {
-        executeScript(appFolder + "cordova/target add z10 169.254.0.1 -t 
device -p pass --pin DEADBEEF");
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            executeScript(appFolder + "cordova/target add q10 169.254.0.2 -t 
device -p p455w02D --pin FACEFACE");
-            waitsFor(function () {
-                return flag;
-            });
-            runs(function () {
-                flag = false;
-                executeScript(appFolder + "cordova/target");
-                waitsFor(function () {
-                    return flag;
-                });
-                runs(function () {
-                    flag = false;
-                    expect(_stdout).toEqual("* z10\n  q10");
-                    expect(_stderr).toEqual("");
-                });
-            });
-        });
+        executeScript(TARGET_COMMAND, ["add", "z10", "169.254.0.1", "-t", 
"device", "-p", "pass", "--pin", "DEADBEEF"]);
+        executeScript(TARGET_COMMAND, ["add", "q10", "169.254.0.2", "-t", 
"device", "-p", "p455w02D", "--pin", "FACEFACE"]);
+        executeScript(TARGET_COMMAND, []);
+        expect(_output).toContain("* z10\n  q10");
     });
 
     it("should require name for add/remove", function () {
-        executeScript(appFolder + "cordova/target add");
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            expect(_stdout).toContain("Target details not specified");
-            expect(_stderr).toEqual("");
-        });
+        executeScript(TARGET_COMMAND, ["add"], true);
+        expect(_output).toContain("Target details not specified");
     });
 
     it("should require ip for add", function () {
-        executeScript(appFolder + "cordova/target add z10");
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            expect(_stdout).toContain("IP is required");
-            expect(_stderr).toEqual("");
-        });
+        executeScript(TARGET_COMMAND, ["add", "z10"], true);
+        expect(_output).toContain("IP is required");
     });
 
     it("should warn unregonized command", function () {
-        executeScript(appFolder + "cordova/target bleh");
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            expect(_stdout).toContain("Unrecognized command");
-            expect(_stderr).toEqual("");
-        });
+        executeScript(TARGET_COMMAND, ["bleh"], true);
+        expect(_output).toContain("Unrecognized command");
     });
 
     it("should warn invalid ip", function () {
-        executeScript(appFolder + "cordova/target add z10 256.254.0.1");
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            expect(_stdout).toContain("Invalid IP: 256.254.0.1");
-            expect(_stderr).toEqual("");
-        });
+        executeScript(TARGET_COMMAND, ["add", "z10", "256.254.0.1"], true);
+        expect(_output).toContain("Invalid IP: 256.254.0.1");
     });
 
     it("should warn invalid type", function () {
-        executeScript(appFolder + "cordova/target add z10 169.254.0.1 -t 
bleh");
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            expect(_stdout).toContain("Invalid target type: bleh");
-            expect(_stderr).toEqual("");
-        });
+        executeScript(TARGET_COMMAND, ["add", "z10", "169.254.0.1", "-t", 
"bleh"], true);
+        expect(_output).toContain("Invalid target type: bleh");
     });
 
     it("should warn invalid pin", function () {
@@ -228,14 +134,7 @@ describe("cordova/target tests", function () {
             wrench.rmdirSyncRecursive(tempFolder);
         });
 
-        executeScript(appFolder + "cordova/target add z10 169.254.0.1 -t 
device --pin NOTAPIN!");
-        waitsFor(function () {
-            return flag;
-        });
-        runs(function () {
-            flag = false;
-            expect(_stdout).toContain("Invalid PIN: NOTAPIN!");
-            expect(_stderr).toEqual("");
-        });
+        executeScript(TARGET_COMMAND, ["add", "z10", "169.254.0.1", "-t", 
"device", "--pin", "NOTAPIN!"], true);
+        expect(_output).toContain("Invalid PIN: NOTAPIN!");
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/397af324/blackberry10/bin/test/cordova/unit/spec/lib/i18n-manager.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/test/cordova/unit/spec/lib/i18n-manager.js 
b/blackberry10/bin/test/cordova/unit/spec/lib/i18n-manager.js
index 50d7225..91df758 100644
--- a/blackberry10/bin/test/cordova/unit/spec/lib/i18n-manager.js
+++ b/blackberry10/bin/test/cordova/unit/spec/lib/i18n-manager.js
@@ -134,26 +134,35 @@ describe("i18n manager", function () {
     });
 
     it("generate correct metadata for icon when image is in subfolder and OS 
is windows", function () {
-        var config = {
-                icon: ["assets\\images\\logo.png"]
-            },
-            xmlObject = {};
-
-        spyOn(pkgrUtils, 'isWindows').andReturn(true);
-        spyOn(fs, "existsSync").andReturn(true);
-        spyOn(wrench, "readdirSyncRecursive").andReturn(mockOSReturnFiles([
-            'fr',
-            'fr\\assets\\images\\logo.png'
-        ]));
-
-        i18nMgr.generateLocalizedMetadata(session, config, xmlObject, "icon");
-
-        expect(xmlObject.icon).toBeDefined();
-        expect(xmlObject.icon.image).toBeDefined();
-        expect(xmlObject.icon.image.length).toBe(1);
-        expect(xmlObject.icon.image).toContain({
-            _value: "assets/images/logo.png"
-        });
+        if (pkgrUtils.isWindows()) {
+            var config = {
+                    icon: ["assets\\images\\logo.png"]
+                },
+                xmlObject = {};
+
+            spyOn(fs, "existsSync").andReturn(true);
+            spyOn(wrench, "readdirSyncRecursive").andReturn(mockOSReturnFiles([
+                'fr',
+                'fr\\assets\\images\\logo.png'
+            ]));
+
+            i18nMgr.generateLocalizedMetadata(session, config, xmlObject, 
"icon");
+
+            expect(xmlObject.icon).toBeDefined();
+            expect(xmlObject.icon.image).toBeDefined();
+            expect(xmlObject.icon.image.length).toBe(2);
+            expect(xmlObject.icon.image).toContain({
+                _value: "assets/images/logo.png"
+            });
+            expect(xmlObject.icon.image).toContain({
+                text: {
+                    _attr: {
+                        "xml:lang": "fr"
+                    },
+                    _value: "locales/fr/assets/images/logo.png"
+                }
+            });
+        }
     });
 
     it("generate correct metadata for splash and OS is *nx", function () {

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/397af324/blackberry10/bin/test/cordova/unit/spec/lib/session.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/test/cordova/unit/spec/lib/session.js 
b/blackberry10/bin/test/cordova/unit/spec/lib/session.js
index bbf6eb3..3cf3f98 100644
--- a/blackberry10/bin/test/cordova/unit/spec/lib/session.js
+++ b/blackberry10/bin/test/cordova/unit/spec/lib/session.js
@@ -134,7 +134,7 @@ describe("Session", function () {
                 },
                 result;
 
-            spyOn(path, 
"resolve").andReturn("bin/test/cordova/unit/params.json");
+            spyOn(path, "resolve").andReturn(path.normalize(__dirname + 
"../../../params.json"));
             spyOn(fs, "existsSync").andReturn(true);
 
             result = session.initialize(data);

Reply via email to