Skip to content
Permalink
Browse files
added jake test command for issue #7
  • Loading branch information
gtanner committed Dec 14, 2011
1 parent 51d347c commit 318183b9708cd34ee6512830d868f4e80c387610
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 47 deletions.
@@ -1,3 +1,4 @@
pkg/
tags
.DS_Store
node_modules/
@@ -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'));
@@ -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');

@@ -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>
@@ -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);

@@ -0,0 +1,4 @@
npm install -g jake
npm install connect
git submodule init
git submodule update
@@ -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.