Browse files

added jake test command for issue #7

  • Loading branch information...
1 parent 51d347c commit 318183b9708cd34ee6512830d868f4e80c387610 @gtanner gtanner committed Dec 14, 2011
Showing with 79 additions and 47 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 Jakefile
  3. +28 −26 build/packager.js
  4. +7 −5 test/index.html → build/test.html
  5. +27 −16 build/test.js
  6. +4 −0 configure
  7. +9 −0 test/test.utils.js
View
1 .gitignore
@@ -1,3 +1,4 @@
pkg/
tags
.DS_Store
+node_modules/
View
3 Jakefile
@@ -27,3 +27,6 @@ task('build', ['clean'], function () {
util.puts(fs.readFileSync("build/dalek", "utf-8"));
});
+
+desc("starts a webserver to point at to run the unit tests");
+task('test', [], require('./build/test'));
View
54 build/packager.js
@@ -1,11 +1,17 @@
var util = require('util'),
fs = require('fs');
+function include(files, transform) {
+ files = files.map ? files : [files];
+ return files.map(function (file) {
+ var str = fs.readFileSync(file, "utf-8") + "\n";
+ return transform ? transform(str, file) : str;
+ }).join('\n');
+}
+
module.exports = {
- bundle: function (platform) {
- var util = require('util'),
- fs = require('fs'),
- files = [
+ modules: function (platform) {
+ var files = [
"lib/utils.js",
"lib/plugin/navigator.js",
"lib/plugin/notification.js",
@@ -16,42 +22,38 @@ module.exports = {
"lib/channel.js",
"lib/builder.js",
"lib/exec/" +platform + ".js"
- ],
- include = function (files, transform) {
- files = files.map ? files : [files];
- return files.map(function (file) {
- var str = fs.readFileSync(file, "utf-8") + "\n";
- return transform ? transform(str, file) : str;
- }).join('\n');
- }
+ ]
output = "";
- //include LICENSE
- output += include("LICENSE", function (file) {
- return "/*\n" + file + "\n*/\n";
- });
-
- //include require
- output += include("thirdparty/almond.js");
-
//include modules
output += include(files, function (file, path) {
var id = path.replace(/lib\//, "phonegap/").replace(/\.js$/, '');
return "define('" + id + "', function (require, exports, module) {\n" + file + "});\n";
});
- //include platform
- output += include('lib/platform/' + platform + '.js', function (file, path) {
- return "define('phonegap/platform'" +
- ", function (require, exports, module) {\n" + file + "});\n";
- });
-
//include phonegap
output += include('lib/phonegap.js', function (file, path) {
return "define('phonegap'" +
", function (require, exports, module) {\n" + file + "});\n";
});
+ return output;
+ },
+
+ bundle: function (platform) {
+ var output = "";
+
+ //include LICENSE
+ output += include("LICENSE", function (file) {
+ return "/*\n" + file + "\n*/\n";
+ });
+
+ //include require
+ output += include("thirdparty/almond.js");
+
+ //include modules
+ output += this.modules(platform);
+
//include bootstrap
output += include('lib/bootstrap.js');
View
12 test/index.html → build/test.html
@@ -9,8 +9,11 @@
<script type="text/javascript" src="../thirdparty/jasmine/jasmine.js"></script>
<script type="text/javascript" src="../thirdparty/jasmine/jasmine-html.js"></script>
+ <script type="text/javascript" src="../thirdparty/almond.js"></script>
+
<script type="text/javascript">
(function() {
+ require.unordered = true;
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
@@ -38,12 +41,11 @@
})();
</script>
- <script type="text/javascript" src="../pkg/phonegap.ios.js"></script>
-
- <!-- include tests files here... -->
- <script type="text/javascript" src="test.accelerometer.js"></script>
-
+ <script type="text/javascript">
+ "##MODULES##"
+ </script>
+ <!-- TESTS -->
</head>
<body>
View
43 build/test.js
@@ -1,14 +1,32 @@
+var fs = require('fs'),
+ _path = require('path');
+
+function collect(path, files, matches) {
+ matches = matches || function (path) {
+ return path.match(/\.js$/);
+ };
+
+ if (fs.statSync(path).isDirectory()) {
+ fs.readdirSync(path).forEach(function (item) {
+ collect(_path.join(path, item), files, matches);
+ });
+ } else if (matches(path)) {
+ files.push(path);
+ }
+}
+
module.exports = function () {
var connect = require('connect'),
- fs = require('fs'),
+ packager = require('./packager'),
tests = [],
- html = fs.readFileSync(__dirname + "/btest/test.html", "utf-8"),
+ html = fs.readFileSync(__dirname + "/../build/test.html", "utf-8"),
doc,
modules,
specs,
app = connect(
connect.static(__dirname + "/../lib/"),
connect.static(__dirname + "/../"),
+ connect.static(__dirname + "/../test/"),
connect.router(function (app) {
app.get('/', function (req, res) {
res.writeHead(200, {
@@ -20,22 +38,15 @@ module.exports = function () {
})
);
- utils.collect(__dirname + "/../lib", libs);
- utils.collect(__dirname + "/../test", tests);
-
- modules = libs.reduce(function (str, file) {
- str += '"' + file.replace(/^.*lib\//, "").replace(/\.js$/, "") + '",\n';
- return str;
- }, "").replace(/\,\n$/g, "\n");
+ collect(__dirname + "/../test", tests);
- specs = tests.reduce(function (str, file) {
- str += '<script src="' +
- file.replace(/^.*test/, "test") +
- '" type="text/javascript" charset="utf-8"></script>\n';
- return str;
- }, "");
+ specs = tests.map(function (file, path) {
+ return '<script src="' + file.replace(/^.*test/, "test") +
+ '" type="text/javascript" charset="utf-8"></script>';
+ }).join();
+ modules = packager.modules('ios');
- doc = html.replace(/<!-- SPECS -->/g, specs).replace(/"##FILES##"/g, modules);
+ doc = html.replace(/<!-- TESTS -->/g, specs).replace(/"##MODULES##"/g, modules);
app.listen(3000);
View
4 configure
@@ -0,0 +1,4 @@
+npm install -g jake
+npm install connect
+git submodule init
+git submodule update
View
9 test/test.utils.js
@@ -0,0 +1,9 @@
+describe("utils", function () {
+ var utils = require('phonegap/utils');
+
+ describe("clone", function () {
+ it("can clone null", function () {
+ expect(utils.clone(null)).toBeNull();
+ });
+ });
+});

0 comments on commit 318183b

Please sign in to comment.