You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2013/12/12 04:33:25 UTC

[1/3] js commit: moved templates to tasks/templates and logic to tasks/lib

Updated Branches:
  refs/heads/master 67c9259e4 -> c608726a8


moved templates to tasks/templates and logic to tasks/lib


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

Branch: refs/heads/master
Commit: ced04a4ec71f144dd2cd6c2e9392e3b1fc725ec1
Parents: 67c9259
Author: brianleroux <b...@brian.io>
Authored: Thu Dec 12 14:19:37 2013 +1100
Committer: brianleroux <b...@brian.io>
Committed: Thu Dec 12 14:19:37 2013 +1100

----------------------------------------------------------------------
 tasks/lib/LICENSE-for-js-file.txt       |  16 ---
 tasks/lib/bundle.js                     |   2 +-
 tasks/lib/reporter.js                   | 205 +++++++++++++++++++++++++++
 tasks/lib/test-browser.js               |  86 +++++++++++
 tasks/lib/test-jsdom.js                 |  80 +++++++++++
 tasks/templates/LICENSE-for-js-file.txt |  16 +++
 tasks/templates/suite.html              |  74 ++++++++++
 tasks/test.js                           |   4 +-
 test/reporter.js                        | 205 ---------------------------
 test/runner.js                          |  52 -------
 test/suite.html                         |  74 ----------
 11 files changed, 464 insertions(+), 350 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ced04a4e/tasks/lib/LICENSE-for-js-file.txt
----------------------------------------------------------------------
diff --git a/tasks/lib/LICENSE-for-js-file.txt b/tasks/lib/LICENSE-for-js-file.txt
deleted file mode 100644
index 20f533b..0000000
--- a/tasks/lib/LICENSE-for-js-file.txt
+++ /dev/null
@@ -1,16 +0,0 @@
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements.  See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership.  The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License.  You may obtain a copy of the License at
- 
-     http://www.apache.org/licenses/LICENSE-2.0
- 
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied.  See the License for the
- specific language governing permissions and limitations
- under the License.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ced04a4e/tasks/lib/bundle.js
----------------------------------------------------------------------
diff --git a/tasks/lib/bundle.js b/tasks/lib/bundle.js
index c3995a1..cf3c455 100644
--- a/tasks/lib/bundle.js
+++ b/tasks/lib/bundle.js
@@ -22,6 +22,7 @@ var collectFiles = require('./collect-files');
 var copyProps    = require('./copy-props');
 var writeModule  = require('./write-module');
 var writeScript  = require('./write-script');
+var licensePath = path.join(__dirname, '..', 'templates', 'LICENSE-for-js-file.txt');
 
 
 module.exports = function bundle(platform, debug, commitId) {
@@ -43,7 +44,6 @@ module.exports = function bundle(platform, debug, commitId) {
     output.push("// "  + commitId);
 
     // write header
-    var licensePath = path.join(__dirname, 'LICENSE-for-js-file.txt');
     output.push('/*', fs.readFileSync(licensePath, 'utf8'), '*/');
     output.push(';(function() {');
     output.push("var CORDOVA_JS_BUILD_LABEL = '"  + commitId + "';");

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ced04a4e/tasks/lib/reporter.js
----------------------------------------------------------------------
diff --git a/tasks/lib/reporter.js b/tasks/lib/reporter.js
new file mode 100644
index 0000000..59d0a5e
--- /dev/null
+++ b/tasks/lib/reporter.js
@@ -0,0 +1,205 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+/*
+
+From the jasmine-node project: https://github.com/mhevery/jasmine-node
+
+The MIT License
+
+Copyright (c) 2010 Adam Abrons and Misko Hevery http://getangular.com
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+*/
+
+//
+// Imports
+//
+var util;
+try {
+  util = require('util')
+} catch(e) {
+  util = require('sys')
+}
+
+
+//
+// Helpers
+//
+function noop() {}
+
+printRunnerResults = function(runner){
+  var results = runner.results();
+  var specs = runner.specs();
+  var msg = '';
+  msg += specs.length + ' test' + ((specs.length === 1) ? '' : 's') + ', ';
+  msg += results.totalCount + ' assertion' + ((results.totalCount === 1) ? '' : 's') + ', ';
+  msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n';
+  return msg;
+};
+
+ANSIColors = {
+  pass:    function() { return '\033[32m'; }, // Green
+  fail:    function() { return '\033[31m'; }, // Red
+  neutral: function() { return '\033[0m';  }  // Normal
+};
+
+NoColors = {
+  pass:    function() { return ''; },
+  fail:    function() { return ''; },
+  neutral: function() { return ''; }
+};
+
+//
+// Reporter implementation
+//
+TerminalReporter = function(config) {
+  this.print_      = config.print      || util.print;
+  this.isVerbose_  = config.verbose    || false;
+  this.onComplete_ = config.onComplete || noop;
+  this.color_      = config.color? ANSIColors: NoColors;
+  this.stackFilter = config.stackFilter || function(t) { return t; }
+
+  this.columnCounter_ = 0;
+  this.log_           = [];
+  this.start_         = 0;
+};
+
+TerminalReporter.prototype = {
+  // Public Methods //
+  log: noop,
+
+  reportSpecStarting: noop,
+
+  reportRunnerStarting: function(runner) {
+    this.printLine_('Started');
+    this.start_ = Number(new Date);
+  },
+
+  reportSuiteResults: function(suite) {
+    var specResults = suite.results();
+    var path = [];
+    while(suite) {
+      path.unshift(suite.description);
+      suite = suite.parentSuite;
+    }
+    var description = path.join(' ');
+
+    if (this.isVerbose_)
+      this.log_.push('Spec ' + description);
+
+    outerThis = this;
+    specResults.items_.forEach(function(spec){
+      if (spec.description && spec.failedCount > 0) {
+        if (!outerThis.isVerbose_)
+          outerThis.log_.push(description);
+        outerThis.log_.push('  it ' + spec.description);
+        spec.items_.forEach(function(result){
+        if (!result.passed_) {
+    			var errorMessage = result.trace.stack || result.message;
+            if(outerThis.teamcity_) {
+              outerThis.log_.push("##teamcity[testFailed name='" +  escapeTeamcityString(spec.description) + "' message='[FAILED]' details='" + escapeTeamcityString(outerThis.stackFilter(outerThis.stackFilter(errorMessage))) + "']");
+            } else {
+              outerThis.log_.push(result.message.indexOf('timeout:') == 0 ?
+                                  '  TIMEOUT:' + result.message.substr(8) :
+                                  '  ' +  outerThis.stackFilter(errorMessage) + '\n');
+            }
+          }
+        });
+      } else {
+        if (outerThis.isVerbose_) {
+          outerThis.log_.push('  it ' + spec.description);
+        }
+      }
+    });
+  },
+
+  reportSpecResults: function(spec) {
+    var result = spec.results();
+    var msg = '';
+    if (result.passed()) {
+      msg = this.stringWithColor_('.', this.color_.pass());
+      //      } else if (result.skipped) {  TODO: Research why "result.skipped" returns false when "xit" is called on a spec?
+      //        msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*';
+    } else {
+      msg = this.stringWithColor_('F', this.color_.fail());
+    }
+    this.print_(msg);
+    if (this.columnCounter_++ < 50) return;
+    this.columnCounter_ = 0;
+    this.print_('\n');
+  },
+
+  reportRunnerResults: function(runner) {
+    var elapsed = (Number(new Date) - this.start_) / 1000;
+    var owner   = this;
+
+    this.printLine_('\n');
+    this.log_.forEach(function(entry) {
+      owner.printLine_(entry);
+    });
+    this.printLine_('Finished in ' + elapsed + ' seconds');
+
+    var summary = printRunnerResults(runner);
+    if(runner.results().failedCount === 0 ) {
+      this.printLine_(this.stringWithColor_(summary, this.color_.pass()));
+    }
+    else {
+      this.printLine_(this.stringWithColor_(summary, this.color_.fail()));
+    }
+
+    this.onComplete_(runner, this.log_);
+  },
+
+  // Helper Methods //
+  stringWithColor_: function(str, color) {
+    return (color || this.color_.neutral()) + str + this.color_.neutral();
+  },
+
+  printLine_: function(str) {
+    this.print_(str);
+    this.print_('\n');
+  }
+
+};
+
+
+//
+// Exports
+//
+exports.TerminalReporter = TerminalReporter;

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ced04a4e/tasks/lib/test-browser.js
----------------------------------------------------------------------
diff --git a/tasks/lib/test-browser.js b/tasks/lib/test-browser.js
new file mode 100644
index 0000000..cc4d665
--- /dev/null
+++ b/tasks/lib/test-browser.js
@@ -0,0 +1,86 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+
+var fs       = require('fs');
+var path     = require('path');
+var connect  = require('connect');
+var exec     = require('child_process').exec;
+var bundle   = require('./bundle');
+var collect  = require('./collect');
+
+var pathToTemplate = path.join(__dirname, '..', 'templates', 'suite.html');
+var pathToVendor   = path.join(__dirname, '..', 'vendor');
+var pathToTests    = path.join(__dirname, '..', '..', 'tests');
+
+var template = fs.readFileSync(pathToTemplate, "utf-8");
+
+// middlewar for GET '/cordova.test.js'
+function cordovajs(req, res) {
+    res.writeHead(200, {
+        "Cache-Control": "no-cache",
+        "Content-Type": "text/javascript"
+    });
+    res.end(bundle('test'));
+}
+
+// middleware for GET '/'
+function root(req, res) {
+    res.writeHead(200, {
+        "Cache-Control": "no-cache",
+        "Content-Type": "text/html"
+    });
+
+    //FIXME in place collect thing is atrocious
+    //create the script tags to include
+    var tests = [];
+    collect(path.join(__dirname, '..', '..', 'test'), tests);
+    var specs = tests.map(function (file, path) {
+        return '<script src="' + file.replace(/^.*\/test\//, "/") +
+            '" type="text/javascript" charset="utf-8"></script>';
+    }).join('');
+
+    //inject in the test script includes and write the document
+    res.end(template.replace(/<!-- ##TESTS## -->/g, specs));
+}
+
+// connect router defn
+function routes(app) {
+    app.get('/cordova.test.js', cordovajs);
+    app.get('/', root)
+}
+
+module.exports = function() {
+
+    console.log('starting browser-based tests')
+
+    var vendor = connect.static(pathToVendor);
+    var tests  = connect.static(pathToTests);
+    var router = connect.router(routes);
+
+    connect(vendor, tests, router).listen(3000);
+    
+    console.log("Test Server running on:\n");
+    console.log("http://127.0.0.1:3000\n");
+
+    exec('open http://127.0.0.1:3000');
+};
+

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ced04a4e/tasks/lib/test-jsdom.js
----------------------------------------------------------------------
diff --git a/tasks/lib/test-jsdom.js b/tasks/lib/test-jsdom.js
new file mode 100644
index 0000000..7f88f9f
--- /dev/null
+++ b/tasks/lib/test-jsdom.js
@@ -0,0 +1,80 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+var jsdom, document, window;
+
+var path             = require('path');
+var fs               = require('fs');
+var collect          = require('./collect');
+var jas              = require("./../vendor/jasmine/jasmine");
+var TerminalReporter = require('./reporter').TerminalReporter;
+var testLibName      = path.join(__dirname, '..', '..', 'pkg', 'cordova.test.js')
+var testLib          = fs.readFileSync(testLibName, 'utf8')
+
+try {
+    jsdom    = require("jsdom").jsdom;
+    document = jsdom(null, null, { url: 'http://jsdomtest.info/a?b#c' });
+    window   = document.createWindow();
+} 
+catch (e) {
+    var err = "can't run tests in node: ";
+    err += "run grunt btest instead, or install jsdom via: npm install";
+    throw new Error(err);
+}
+
+module.exports = function(callback) {
+
+    console.log('starting node-based tests');
+
+    // put jasmine in scope
+    Object.keys(jas).forEach(function (key) {
+        this[key] = window[key] = global[key] = jas[key];
+    });
+
+    try {
+        eval(testLib);
+    }
+    catch (e) {
+        console.log("error eval()ing " + testLibName + ": " + e);
+        console.log(e.stack);
+        throw e;
+    }
+
+    // hijack require
+    require = window.cordova.require;
+    define  = window.cordova.define;
+
+    // load in our tests
+    var tests = [];
+    collect(path.join(__dirname, '..', '..', 'test'), tests);
+    for (var x in tests) {
+        eval(fs.readFileSync(tests[x], "utf-8"));
+    }
+
+    var env = jasmine.getEnv();
+    env.addReporter(new TerminalReporter({
+        color: true,
+        onComplete: function(runner) { callback(runner.results().passed()); }
+    }));
+
+    console.log("------------");
+    console.log("Unit Tests:");
+    env.execute();
+};

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ced04a4e/tasks/templates/LICENSE-for-js-file.txt
----------------------------------------------------------------------
diff --git a/tasks/templates/LICENSE-for-js-file.txt b/tasks/templates/LICENSE-for-js-file.txt
new file mode 100644
index 0000000..20f533b
--- /dev/null
+++ b/tasks/templates/LICENSE-for-js-file.txt
@@ -0,0 +1,16 @@
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+     http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ced04a4e/tasks/templates/suite.html
----------------------------------------------------------------------
diff --git a/tasks/templates/suite.html b/tasks/templates/suite.html
new file mode 100644
index 0000000..c7a9150
--- /dev/null
+++ b/tasks/templates/suite.html
@@ -0,0 +1,74 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>EXTERMINATE!</title>
+
+  <link rel="shortcut icon" type="image/png" href="jasmine/jasmine_favicon.png">
+
+  <link rel="stylesheet" type="text/css" href="jasmine/jasmine.css">
+  <script type="text/javascript" src="jasmine/jasmine.js"></script>
+  <script type="text/javascript" src="jasmine/jasmine-html.js"></script>
+
+  <script type="text/javascript">
+    (function() {
+      var jasmineEnv = jasmine.getEnv();
+      jasmineEnv.updateInterval = 1000;
+
+      var trivialReporter = new jasmine.TrivialReporter();
+
+      jasmineEnv.addReporter(trivialReporter);
+
+      jasmineEnv.specFilter = function(spec) {
+        return trivialReporter.specFilter(spec);
+      };
+
+      window.global = window;
+
+      window.cordova = {
+         platform: ""
+      };
+
+      window.addEventListener("load", function () {
+          jasmineEnv.execute();
+      });
+
+    })();
+  </script>
+
+  <script type="text/javascript" src="cordova.test.js"></script>
+
+  <script type="text/javascript">
+      var require = cordova.require;
+      var define = cordova.define;
+  </script>
+
+	<!-- ##TESTS## -->
+	
+	<!-- Note: if you want to run individual tests, remove the tests placeholder above and include the individual tests yourself -->
+	<!-- <script src="test.accelerometer.js" type="text/javascript" charset="utf-8"></script> -->
+</head>
+
+<body>
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ced04a4e/tasks/test.js
----------------------------------------------------------------------
diff --git a/tasks/test.js b/tasks/test.js
index c0bb274..edd6491 100644
--- a/tasks/test.js
+++ b/tasks/test.js
@@ -19,11 +19,11 @@
 module.exports = function(grunt) {
     grunt.registerTask('_test', 'Runs test in node', function() {
         var done = this.async();
-        require('./../test/runner').node(done);
+        require('./lib/test-jsdom')(done);
     });
 
     grunt.registerTask('_btest', 'Runs tests in the browser', function() {
-        require('./../test/runner').browser();
+        require('./lib/test-browser')();
         this.async(); // never finish.
     });
 }

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ced04a4e/test/reporter.js
----------------------------------------------------------------------
diff --git a/test/reporter.js b/test/reporter.js
deleted file mode 100644
index 59d0a5e..0000000
--- a/test/reporter.js
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-/*
-
-From the jasmine-node project: https://github.com/mhevery/jasmine-node
-
-The MIT License
-
-Copyright (c) 2010 Adam Abrons and Misko Hevery http://getangular.com
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
-*/
-
-//
-// Imports
-//
-var util;
-try {
-  util = require('util')
-} catch(e) {
-  util = require('sys')
-}
-
-
-//
-// Helpers
-//
-function noop() {}
-
-printRunnerResults = function(runner){
-  var results = runner.results();
-  var specs = runner.specs();
-  var msg = '';
-  msg += specs.length + ' test' + ((specs.length === 1) ? '' : 's') + ', ';
-  msg += results.totalCount + ' assertion' + ((results.totalCount === 1) ? '' : 's') + ', ';
-  msg += results.failedCount + ' failure' + ((results.failedCount === 1) ? '' : 's') + '\n';
-  return msg;
-};
-
-ANSIColors = {
-  pass:    function() { return '\033[32m'; }, // Green
-  fail:    function() { return '\033[31m'; }, // Red
-  neutral: function() { return '\033[0m';  }  // Normal
-};
-
-NoColors = {
-  pass:    function() { return ''; },
-  fail:    function() { return ''; },
-  neutral: function() { return ''; }
-};
-
-//
-// Reporter implementation
-//
-TerminalReporter = function(config) {
-  this.print_      = config.print      || util.print;
-  this.isVerbose_  = config.verbose    || false;
-  this.onComplete_ = config.onComplete || noop;
-  this.color_      = config.color? ANSIColors: NoColors;
-  this.stackFilter = config.stackFilter || function(t) { return t; }
-
-  this.columnCounter_ = 0;
-  this.log_           = [];
-  this.start_         = 0;
-};
-
-TerminalReporter.prototype = {
-  // Public Methods //
-  log: noop,
-
-  reportSpecStarting: noop,
-
-  reportRunnerStarting: function(runner) {
-    this.printLine_('Started');
-    this.start_ = Number(new Date);
-  },
-
-  reportSuiteResults: function(suite) {
-    var specResults = suite.results();
-    var path = [];
-    while(suite) {
-      path.unshift(suite.description);
-      suite = suite.parentSuite;
-    }
-    var description = path.join(' ');
-
-    if (this.isVerbose_)
-      this.log_.push('Spec ' + description);
-
-    outerThis = this;
-    specResults.items_.forEach(function(spec){
-      if (spec.description && spec.failedCount > 0) {
-        if (!outerThis.isVerbose_)
-          outerThis.log_.push(description);
-        outerThis.log_.push('  it ' + spec.description);
-        spec.items_.forEach(function(result){
-        if (!result.passed_) {
-    			var errorMessage = result.trace.stack || result.message;
-            if(outerThis.teamcity_) {
-              outerThis.log_.push("##teamcity[testFailed name='" +  escapeTeamcityString(spec.description) + "' message='[FAILED]' details='" + escapeTeamcityString(outerThis.stackFilter(outerThis.stackFilter(errorMessage))) + "']");
-            } else {
-              outerThis.log_.push(result.message.indexOf('timeout:') == 0 ?
-                                  '  TIMEOUT:' + result.message.substr(8) :
-                                  '  ' +  outerThis.stackFilter(errorMessage) + '\n');
-            }
-          }
-        });
-      } else {
-        if (outerThis.isVerbose_) {
-          outerThis.log_.push('  it ' + spec.description);
-        }
-      }
-    });
-  },
-
-  reportSpecResults: function(spec) {
-    var result = spec.results();
-    var msg = '';
-    if (result.passed()) {
-      msg = this.stringWithColor_('.', this.color_.pass());
-      //      } else if (result.skipped) {  TODO: Research why "result.skipped" returns false when "xit" is called on a spec?
-      //        msg = (colors) ? (ansi.yellow + '*' + ansi.none) : '*';
-    } else {
-      msg = this.stringWithColor_('F', this.color_.fail());
-    }
-    this.print_(msg);
-    if (this.columnCounter_++ < 50) return;
-    this.columnCounter_ = 0;
-    this.print_('\n');
-  },
-
-  reportRunnerResults: function(runner) {
-    var elapsed = (Number(new Date) - this.start_) / 1000;
-    var owner   = this;
-
-    this.printLine_('\n');
-    this.log_.forEach(function(entry) {
-      owner.printLine_(entry);
-    });
-    this.printLine_('Finished in ' + elapsed + ' seconds');
-
-    var summary = printRunnerResults(runner);
-    if(runner.results().failedCount === 0 ) {
-      this.printLine_(this.stringWithColor_(summary, this.color_.pass()));
-    }
-    else {
-      this.printLine_(this.stringWithColor_(summary, this.color_.fail()));
-    }
-
-    this.onComplete_(runner, this.log_);
-  },
-
-  // Helper Methods //
-  stringWithColor_: function(str, color) {
-    return (color || this.color_.neutral()) + str + this.color_.neutral();
-  },
-
-  printLine_: function(str) {
-    this.print_(str);
-    this.print_('\n');
-  }
-
-};
-
-
-//
-// Exports
-//
-exports.TerminalReporter = TerminalReporter;

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ced04a4e/test/runner.js
----------------------------------------------------------------------
diff --git a/test/runner.js b/test/runner.js
index 23b5702..e64eb40 100644
--- a/test/runner.js
+++ b/test/runner.js
@@ -30,58 +30,6 @@ var collect  = require('./../tasks/lib/collect');
 
 
 module.exports = {
-    node: function(callback) {
-        console.log('starting node-based tests')
-        var jas = require("./../tasks/vendor/jasmine/jasmine"),
-            TerminalReporter = require('./reporter').TerminalReporter,
-            jsdom, document, window;
-
-        try {
-            jsdom = require("jsdom").jsdom;
-            document = jsdom(null, null, { url: 'http://jsdomtest.info/a?b#c' });
-            window = document.createWindow();
-        } catch (e) {
-            //no jsDom (some people don't have compilers)
-            throw new Error("can't run tests in node: run grunt btest instead, or install jsdom via: npm install");
-        }
-
-        //Put jasmine in scope
-        Object.keys(jas).forEach(function (key) {
-            this[key] = window[key] = global[key] = jas[key];
-        });
-
-        //load in our modules
-        var testLibName = _path.join(__dirname, '..', 'pkg', 'cordova.test.js')
-        var testLib     = fs.readFileSync(testLibName, 'utf8')
-        try {
-            eval(testLib);
-        }
-        catch (e) {
-            console.log("error eval()ing " + testLibName + ": " + e)
-            console.log(e.stack)
-            throw e
-        }
-
-        //hijack require
-        require = window.cordova.require;
-        define  = window.cordova.define;
-
-        //load in our tests
-        collect(__dirname, tests);
-        for (var x in tests) {
-            eval(fs.readFileSync(tests[x], "utf-8"));
-        }
-
-        var env = jasmine.getEnv();
-        env.addReporter(new TerminalReporter({
-            color: true,
-            onComplete: function(runner) { callback(runner.results().passed()); }
-        }));
-
-        console.log("------------");
-        console.log("Unit Tests:");
-        env.execute();
-    },
     browser: function () {
         console.log('starting browser-based tests')
         var connect = require('connect'),

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ced04a4e/test/suite.html
----------------------------------------------------------------------
diff --git a/test/suite.html b/test/suite.html
deleted file mode 100644
index c7a9150..0000000
--- a/test/suite.html
+++ /dev/null
@@ -1,74 +0,0 @@
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements.  See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership.  The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License.  You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied.  See the License for the
- specific language governing permissions and limitations
- under the License.
-
--->
-
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>EXTERMINATE!</title>
-
-  <link rel="shortcut icon" type="image/png" href="jasmine/jasmine_favicon.png">
-
-  <link rel="stylesheet" type="text/css" href="jasmine/jasmine.css">
-  <script type="text/javascript" src="jasmine/jasmine.js"></script>
-  <script type="text/javascript" src="jasmine/jasmine-html.js"></script>
-
-  <script type="text/javascript">
-    (function() {
-      var jasmineEnv = jasmine.getEnv();
-      jasmineEnv.updateInterval = 1000;
-
-      var trivialReporter = new jasmine.TrivialReporter();
-
-      jasmineEnv.addReporter(trivialReporter);
-
-      jasmineEnv.specFilter = function(spec) {
-        return trivialReporter.specFilter(spec);
-      };
-
-      window.global = window;
-
-      window.cordova = {
-         platform: ""
-      };
-
-      window.addEventListener("load", function () {
-          jasmineEnv.execute();
-      });
-
-    })();
-  </script>
-
-  <script type="text/javascript" src="cordova.test.js"></script>
-
-  <script type="text/javascript">
-      var require = cordova.require;
-      var define = cordova.define;
-  </script>
-
-	<!-- ##TESTS## -->
-	
-	<!-- Note: if you want to run individual tests, remove the tests placeholder above and include the individual tests yourself -->
-	<!-- <script src="test.accelerometer.js" type="text/javascript" charset="utf-8"></script> -->
-</head>
-
-<body>
-</body>
-</html>


[3/3] js commit: removed old runner logic into tasks

Posted by br...@apache.org.
removed old runner logic into tasks


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

Branch: refs/heads/master
Commit: c608726a8e8a139545113224eb3c9b62d8e75dd8
Parents: a7a5b11
Author: brianleroux <b...@brian.io>
Authored: Thu Dec 12 14:29:31 2013 +1100
Committer: brianleroux <b...@brian.io>
Committed: Thu Dec 12 14:29:31 2013 +1100

----------------------------------------------------------------------
 test/runner.js | 79 -----------------------------------------------------
 1 file changed, 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/c608726a/test/runner.js
----------------------------------------------------------------------
diff --git a/test/runner.js b/test/runner.js
deleted file mode 100644
index e64eb40..0000000
--- a/test/runner.js
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-var fs       = require('fs');
-var util     = require('util');
-var _path    = require('path');
-var exec     = require('child_process').exe;
-var tests    = [];
-var packager = require('./../tasks/lib/packager');
-var bundle   = require('./../tasks/lib/bundle');
-var collect  = require('./../tasks/lib/collect');
-
-
-module.exports = {
-    browser: function () {
-        console.log('starting browser-based tests')
-        var connect = require('connect'),
-            html = fs.readFileSync(__dirname + "/suite.html", "utf-8"),
-            doc,
-            modules,
-            specs,
-            app = connect(
-                connect.static(_path.join(__dirname, '..', 'tasks', 'vendor')),
-                connect.static(__dirname),
-                connect.router(function (app) {
-                    app.get('/cordova.test.js', function (req, res) {
-                        res.writeHead(200, {
-                            "Cache-Control": "no-cache",
-                            "Content-Type": "text/javascript"
-                        });
-                        res.end(bundle('test'));
-                    }),
-                    app.get('/', function (req, res) {
-                        res.writeHead(200, {
-                            "Cache-Control": "no-cache",
-                            "Content-Type": "text/html"
-                        });
-
-                        //create the script tags to include
-                        tests = [];
-                        collect(__dirname, tests);
-                        specs = tests.map(function (file, path) {
-                            return '<script src="' + file.replace(/^.*\/test\//, "/") +
-                                '" type="text/javascript" charset="utf-8"></script>';
-                        }).join('');
-
-                        //inject in the test script includes and write the document
-                        doc = html.replace(/<!-- ##TESTS## -->/g, specs);
-                        res.end(doc);
-                    });
-                })
-            );
-
-        app.listen(3000);
-
-        process.stdout.write("Test Server running on:\n");
-        process.stdout.write("http://127.0.0.1:3000\n");
-
-        exec('open http://127.0.0.1:3000');
-    }
-};


[2/3] js commit: tests passing in browser yay

Posted by br...@apache.org.
tests passing in browser yay


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

Branch: refs/heads/master
Commit: a7a5b11262ca85a85ede7319b0e53bdc2fcb79d4
Parents: ced04a4
Author: brianleroux <b...@brian.io>
Authored: Thu Dec 12 14:28:16 2013 +1100
Committer: brianleroux <b...@brian.io>
Committed: Thu Dec 12 14:28:16 2013 +1100

----------------------------------------------------------------------
 tasks/lib/test-browser.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/a7a5b112/tasks/lib/test-browser.js
----------------------------------------------------------------------
diff --git a/tasks/lib/test-browser.js b/tasks/lib/test-browser.js
index cc4d665..3da62d7 100644
--- a/tasks/lib/test-browser.js
+++ b/tasks/lib/test-browser.js
@@ -29,7 +29,7 @@ var collect  = require('./collect');
 
 var pathToTemplate = path.join(__dirname, '..', 'templates', 'suite.html');
 var pathToVendor   = path.join(__dirname, '..', 'vendor');
-var pathToTests    = path.join(__dirname, '..', '..', 'tests');
+var pathToTests    = path.join(__dirname, '..', '..', 'test');
 
 var template = fs.readFileSync(pathToTemplate, "utf-8");