mobile_template 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +28 -0
- data/Rakefile +3 -0
- data/bin/mobile_template +71 -0
- data/lib/mobile_template/version.rb +4 -0
- data/lib/mobile_template.rb +5 -0
- data/mobile_template.gemspec +21 -0
- data/templates/assets/Gemfile +4 -0
- data/templates/assets/config.rb +96 -0
- data/templates/assets/config.ru +4 -0
- data/templates/assets/source/images/vendor/ajax-loader.gif +0 -0
- data/templates/assets/source/images/vendor/ajax-loader.png +0 -0
- data/templates/assets/source/images/vendor/icons-18-black.png +0 -0
- data/templates/assets/source/images/vendor/icons-18-white.png +0 -0
- data/templates/assets/source/images/vendor/icons-36-black.png +0 -0
- data/templates/assets/source/images/vendor/icons-36-white.png +0 -0
- data/templates/assets/source/index.html.erb +2 -0
- data/templates/assets/source/javascripts/app/index.js.coffee +2 -0
- data/templates/assets/source/javascripts/application.js.coffee +5 -0
- data/templates/assets/source/javascripts/vendor/cordova.js +4841 -0
- data/templates/assets/source/javascripts/vendor/jquery.js +9267 -0
- data/templates/assets/source/javascripts/vendor/jquery.mobile.js +7410 -0
- data/templates/assets/source/layout.erb +24 -0
- data/templates/assets/source/stylesheets/application.css.scss +2 -0
- data/templates/assets/source/stylesheets/vendor/jquery.mobile.css.scss +1872 -0
- data/templates/cordova_android/.gitignore +18 -0
- data/templates/cordova_android/LICENSE +202 -0
- data/templates/cordova_android/NOTICE +5 -0
- data/templates/cordova_android/README.md +95 -0
- data/templates/cordova_android/VERSION +1 -0
- data/templates/cordova_android/bin/BOOM +4 -0
- data/templates/cordova_android/bin/autotest +2 -0
- data/templates/cordova_android/bin/bench +29 -0
- data/templates/cordova_android/bin/create +46 -0
- data/templates/cordova_android/bin/create.bat +1 -0
- data/templates/cordova_android/bin/create.js +88 -0
- data/templates/cordova_android/bin/create.xml +79 -0
- data/templates/cordova_android/bin/node_modules/.bin/cake +7 -0
- data/templates/cordova_android/bin/node_modules/.bin/coffee +7 -0
- data/templates/cordova_android/bin/node_modules/.bin/nodeunit +120 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/.npmignore +11 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/LICENSE +22 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/README +48 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/Rakefile +78 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/bin/cake +7 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/bin/coffee +7 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/extras/jsl.conf +44 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/browser.js +75 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/cake.js +76 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/coffee-script.js +135 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/command.js +301 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/grammar.js +591 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/helpers.js +66 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/index.js +8 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/lexer.js +656 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/nodes.js +2289 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/optparse.js +111 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/parser.js +676 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/repl.js +123 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/rewriter.js +363 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/scope.js +120 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/package.json +27 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/.gitignore +5 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/.npmignore +3 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/CONTRIBUTORS.md +60 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/LICENSE +19 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/Makefile +126 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/README.md +432 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit +120 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit.json +10 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/async.js +623 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/console.log.js +55 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/ejs.js +125 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/json2.js +483 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/nodeunit.js +1757 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite1.js +12 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite2.js +13 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/test.html +16 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/img/example_fail.png +0 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/img/example_pass.png +0 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/index.js +3 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/assert.js +316 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/core.js +260 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/nodeunit.js +82 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/browser.js +119 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/default.js +123 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/html.js +107 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/index.js +9 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/junit.js +183 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/minimal.js +112 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/skip_passed.js +105 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/track.js +48 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/types.js +187 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/utils.js +209 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/man1/nodeunit.1 +95 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/nodelint.cfg +4 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/package.json +56 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/share/junit.xml.ejs +19 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/share/license.js +11 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/share/nodeunit.css +70 -0
- data/templates/cordova_android/bin/templates/project/.cordova/android/readme.md +1 -0
- data/templates/cordova_android/bin/templates/project/.cordova/readme.md +3 -0
- data/templates/cordova_android/bin/templates/project/cordova/create +36 -0
- data/templates/cordova_android/bin/templates/project/cordova/debug +9 -0
- data/templates/cordova_android/bin/templates/project/cordova/emulate +12 -0
- data/templates/cordova_android/bin/templates/project/cordova/log +3 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/Activity.java +16 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/AndroidManifest.xml +50 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/index.html +42 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/main.js +146 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/master.css +96 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/drawable/icon.png +0 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/cordova.xml +5 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/plugins.xml +19 -0
- data/templates/cordova_android/bin/test +26 -0
- data/templates/cordova_android/bin/tests/autotest.coffee +4 -0
- data/templates/cordova_android/bin/tests/create.coffee +21 -0
- data/templates/cordova_android/bin/tests/debug.coffee +0 -0
- data/templates/cordova_android/bin/tests/test.coffee +0 -0
- data/templates/cordova_android/framework/.classpath +8 -0
- data/templates/cordova_android/framework/.project +33 -0
- data/templates/cordova_android/framework/AndroidManifest.xml +68 -0
- data/templates/cordova_android/framework/ant.properties +34 -0
- data/templates/cordova_android/framework/assets/js/accelerometer.js +137 -0
- data/templates/cordova_android/framework/assets/js/app.js +89 -0
- data/templates/cordova_android/framework/assets/js/battery.js +134 -0
- data/templates/cordova_android/framework/assets/js/camera.js +168 -0
- data/templates/cordova_android/framework/assets/js/capture.js +203 -0
- data/templates/cordova_android/framework/assets/js/compass.js +168 -0
- data/templates/cordova_android/framework/assets/js/contact.js +310 -0
- data/templates/cordova_android/framework/assets/js/cordova.android.js +4841 -0
- data/templates/cordova_android/framework/assets/js/cordova.js.base +924 -0
- data/templates/cordova_android/framework/assets/js/crypto.js +54 -0
- data/templates/cordova_android/framework/assets/js/device.js +83 -0
- data/templates/cordova_android/framework/assets/js/file.js +1082 -0
- data/templates/cordova_android/framework/assets/js/filetransfer.js +125 -0
- data/templates/cordova_android/framework/assets/js/geolocation.js +209 -0
- data/templates/cordova_android/framework/assets/js/header.txt +19 -0
- data/templates/cordova_android/framework/assets/js/media.js +233 -0
- data/templates/cordova_android/framework/assets/js/network.js +100 -0
- data/templates/cordova_android/framework/assets/js/notification.js +133 -0
- data/templates/cordova_android/framework/assets/js/position.js +100 -0
- data/templates/cordova_android/framework/assets/js/storage.js +439 -0
- data/templates/cordova_android/framework/assets/www/index.html +27 -0
- data/templates/cordova_android/framework/build.xml +216 -0
- data/templates/cordova_android/framework/libs/commons-codec-1.3.jar +0 -0
- data/templates/cordova_android/framework/proguard-project.txt +20 -0
- data/templates/cordova_android/framework/project.properties +14 -0
- data/templates/cordova_android/framework/res/drawable/icon.png +0 -0
- data/templates/cordova_android/framework/res/drawable/splash.png +0 -0
- data/templates/cordova_android/framework/res/layout/main.xml +29 -0
- data/templates/cordova_android/framework/res/values/strings.xml +23 -0
- data/templates/cordova_android/framework/res/xml/cordova.xml +37 -0
- data/templates/cordova_android/framework/res/xml/plugins.xml +37 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/IPlugin.java +27 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/LOG.java +28 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/PhonegapActivity.java +28 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/Plugin.java +27 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/PluginManager.java +35 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/PluginResult.java +53 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AccelListener.java +311 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/App.java +198 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AudioHandler.java +364 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AudioPlayer.java +450 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AuthenticationToken.java +69 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/BatteryListener.java +156 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CallbackServer.java +431 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CameraLauncher.java +500 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Capture.java +400 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CompassListener.java +308 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessor.java +198 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessorSdk5.java +1934 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactManager.java +113 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CordovaChromeClient.java +314 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CordovaWebViewClient.java +306 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Device.java +219 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/DirectoryManager.java +161 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/DroidGap.java +1417 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ExifHelper.java +165 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/FileTransfer.java +458 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/FileUploadResult.java +63 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/FileUtils.java +1048 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/GeoBroker.java +165 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/GeoListener.java +133 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/GpsListener.java +163 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/HttpHandler.java +80 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java +104 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/NetworkListener.java +153 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/NetworkManager.java +248 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Notification.java +366 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceNode.java +34 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceSet.java +62 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/StandAlone.java +35 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Storage.java +239 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/TempListener.java +112 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/CordovaInterface.java +145 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/IPlugin.java +116 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/LOG.java +234 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/Plugin.java +210 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginManager.java +359 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginResult.java +119 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/EncodingException.java +28 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/FileExistsException.java +28 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/InvalidModificationException.java +29 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/NoModificationAllowedException.java +28 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/TypeMismatchException.java +29 -0
- data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceNodeTest.java +53 -0
- data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceSetTest.java +73 -0
- metadata +279 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
this.suite1 = {
|
2
|
+
'test one': function (test) {
|
3
|
+
test.ok(true, 'everythings ok');
|
4
|
+
setTimeout(function () {
|
5
|
+
test.done();
|
6
|
+
}, 10);
|
7
|
+
},
|
8
|
+
'apples and oranges': function (test) {
|
9
|
+
test.equal('apples', 'oranges', 'comparing apples and oranges');
|
10
|
+
test.done();
|
11
|
+
}
|
12
|
+
};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
this.suite2 = {
|
2
|
+
'another test': function (test) {
|
3
|
+
setTimeout(function () {
|
4
|
+
// lots of assertions
|
5
|
+
test.ok(true, 'everythings ok');
|
6
|
+
test.ok(true, 'everythings ok');
|
7
|
+
test.ok(true, 'everythings ok');
|
8
|
+
test.ok(true, 'everythings ok');
|
9
|
+
test.ok(true, 'everythings ok');
|
10
|
+
test.done();
|
11
|
+
}, 10);
|
12
|
+
}
|
13
|
+
};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Example tests</title>
|
4
|
+
<script src="nodeunit.js"></script>
|
5
|
+
<script src="suite1.js"></script>
|
6
|
+
<script src="suite2.js"></script>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<script>
|
10
|
+
nodeunit.run({
|
11
|
+
'suite1': suite1,
|
12
|
+
'suite2': suite2
|
13
|
+
});
|
14
|
+
</script>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,316 @@
|
|
1
|
+
/**
|
2
|
+
* This file is based on the node.js assert module, but with some small
|
3
|
+
* changes for browser-compatibility
|
4
|
+
* THIS FILE SHOULD BE BROWSER-COMPATIBLE JS!
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Added for browser compatibility
|
10
|
+
*/
|
11
|
+
|
12
|
+
var _keys = function(obj){
|
13
|
+
if(Object.keys) return Object.keys(obj);
|
14
|
+
var keys = [];
|
15
|
+
for(var k in obj){
|
16
|
+
if(obj.hasOwnProperty(k)) keys.push(k);
|
17
|
+
}
|
18
|
+
return keys;
|
19
|
+
};
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
// http://wiki.commonjs.org/wiki/Unit_Testing/1.0
|
24
|
+
//
|
25
|
+
// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
|
26
|
+
//
|
27
|
+
// Originally from narwhal.js (http://narwhaljs.org)
|
28
|
+
// Copyright (c) 2009 Thomas Robinson <280north.com>
|
29
|
+
//
|
30
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
31
|
+
// of this software and associated documentation files (the 'Software'), to
|
32
|
+
// deal in the Software without restriction, including without limitation the
|
33
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
34
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
35
|
+
// furnished to do so, subject to the following conditions:
|
36
|
+
//
|
37
|
+
// The above copyright notice and this permission notice shall be included in
|
38
|
+
// all copies or substantial portions of the Software.
|
39
|
+
//
|
40
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
41
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
42
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
43
|
+
// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
44
|
+
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
45
|
+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
46
|
+
|
47
|
+
|
48
|
+
var pSlice = Array.prototype.slice;
|
49
|
+
|
50
|
+
// 1. The assert module provides functions that throw
|
51
|
+
// AssertionError's when particular conditions are not met. The
|
52
|
+
// assert module must conform to the following interface.
|
53
|
+
|
54
|
+
var assert = exports;
|
55
|
+
|
56
|
+
// 2. The AssertionError is defined in assert.
|
57
|
+
// new assert.AssertionError({message: message, actual: actual, expected: expected})
|
58
|
+
|
59
|
+
assert.AssertionError = function AssertionError (options) {
|
60
|
+
this.name = "AssertionError";
|
61
|
+
this.message = options.message;
|
62
|
+
this.actual = options.actual;
|
63
|
+
this.expected = options.expected;
|
64
|
+
this.operator = options.operator;
|
65
|
+
var stackStartFunction = options.stackStartFunction || fail;
|
66
|
+
|
67
|
+
if (Error.captureStackTrace) {
|
68
|
+
Error.captureStackTrace(this, stackStartFunction);
|
69
|
+
}
|
70
|
+
};
|
71
|
+
// code from util.inherits in node
|
72
|
+
assert.AssertionError.super_ = Error;
|
73
|
+
|
74
|
+
|
75
|
+
// EDITED FOR BROWSER COMPATIBILITY: replaced Object.create call
|
76
|
+
// TODO: test what effect this may have
|
77
|
+
var ctor = function () { this.constructor = assert.AssertionError; };
|
78
|
+
ctor.prototype = Error.prototype;
|
79
|
+
assert.AssertionError.prototype = new ctor();
|
80
|
+
|
81
|
+
|
82
|
+
assert.AssertionError.prototype.toString = function() {
|
83
|
+
if (this.message) {
|
84
|
+
return [this.name+":", this.message].join(' ');
|
85
|
+
} else {
|
86
|
+
return [ this.name+":"
|
87
|
+
, JSON.stringify(this.expected )
|
88
|
+
, this.operator
|
89
|
+
, JSON.stringify(this.actual)
|
90
|
+
].join(" ");
|
91
|
+
}
|
92
|
+
};
|
93
|
+
|
94
|
+
// assert.AssertionError instanceof Error
|
95
|
+
|
96
|
+
assert.AssertionError.__proto__ = Error.prototype;
|
97
|
+
|
98
|
+
// At present only the three keys mentioned above are used and
|
99
|
+
// understood by the spec. Implementations or sub modules can pass
|
100
|
+
// other keys to the AssertionError's constructor - they will be
|
101
|
+
// ignored.
|
102
|
+
|
103
|
+
// 3. All of the following functions must throw an AssertionError
|
104
|
+
// when a corresponding condition is not met, with a message that
|
105
|
+
// may be undefined if not provided. All assertion methods provide
|
106
|
+
// both the actual and expected values to the assertion error for
|
107
|
+
// display purposes.
|
108
|
+
|
109
|
+
function fail(actual, expected, message, operator, stackStartFunction) {
|
110
|
+
throw new assert.AssertionError({
|
111
|
+
message: message,
|
112
|
+
actual: actual,
|
113
|
+
expected: expected,
|
114
|
+
operator: operator,
|
115
|
+
stackStartFunction: stackStartFunction
|
116
|
+
});
|
117
|
+
}
|
118
|
+
|
119
|
+
// EXTENSION! allows for well behaved errors defined elsewhere.
|
120
|
+
assert.fail = fail;
|
121
|
+
|
122
|
+
// 4. Pure assertion tests whether a value is truthy, as determined
|
123
|
+
// by !!guard.
|
124
|
+
// assert.ok(guard, message_opt);
|
125
|
+
// This statement is equivalent to assert.equal(true, guard,
|
126
|
+
// message_opt);. To test strictly for the value true, use
|
127
|
+
// assert.strictEqual(true, guard, message_opt);.
|
128
|
+
|
129
|
+
assert.ok = function ok(value, message) {
|
130
|
+
if (!!!value) fail(value, true, message, "==", assert.ok);
|
131
|
+
};
|
132
|
+
|
133
|
+
// 5. The equality assertion tests shallow, coercive equality with
|
134
|
+
// ==.
|
135
|
+
// assert.equal(actual, expected, message_opt);
|
136
|
+
|
137
|
+
assert.equal = function equal(actual, expected, message) {
|
138
|
+
if (actual != expected) fail(actual, expected, message, "==", assert.equal);
|
139
|
+
};
|
140
|
+
|
141
|
+
// 6. The non-equality assertion tests for whether two objects are not equal
|
142
|
+
// with != assert.notEqual(actual, expected, message_opt);
|
143
|
+
|
144
|
+
assert.notEqual = function notEqual(actual, expected, message) {
|
145
|
+
if (actual == expected) {
|
146
|
+
fail(actual, expected, message, "!=", assert.notEqual);
|
147
|
+
}
|
148
|
+
};
|
149
|
+
|
150
|
+
// 7. The equivalence assertion tests a deep equality relation.
|
151
|
+
// assert.deepEqual(actual, expected, message_opt);
|
152
|
+
|
153
|
+
assert.deepEqual = function deepEqual(actual, expected, message) {
|
154
|
+
if (!_deepEqual(actual, expected)) {
|
155
|
+
fail(actual, expected, message, "deepEqual", assert.deepEqual);
|
156
|
+
}
|
157
|
+
};
|
158
|
+
|
159
|
+
function _deepEqual(actual, expected) {
|
160
|
+
// 7.1. All identical values are equivalent, as determined by ===.
|
161
|
+
if (actual === expected) {
|
162
|
+
return true;
|
163
|
+
// 7.2. If the expected value is a Date object, the actual value is
|
164
|
+
// equivalent if it is also a Date object that refers to the same time.
|
165
|
+
} else if (actual instanceof Date && expected instanceof Date) {
|
166
|
+
return actual.getTime() === expected.getTime();
|
167
|
+
|
168
|
+
// 7.3. Other pairs that do not both pass typeof value == "object",
|
169
|
+
// equivalence is determined by ==.
|
170
|
+
} else if (typeof actual != 'object' && typeof expected != 'object') {
|
171
|
+
return actual == expected;
|
172
|
+
|
173
|
+
// 7.4. For all other Object pairs, including Array objects, equivalence is
|
174
|
+
// determined by having the same number of owned properties (as verified
|
175
|
+
// with Object.prototype.hasOwnProperty.call), the same set of keys
|
176
|
+
// (although not necessarily the same order), equivalent values for every
|
177
|
+
// corresponding key, and an identical "prototype" property. Note: this
|
178
|
+
// accounts for both named and indexed properties on Arrays.
|
179
|
+
} else {
|
180
|
+
return objEquiv(actual, expected);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
function isUndefinedOrNull (value) {
|
185
|
+
return value === null || value === undefined;
|
186
|
+
}
|
187
|
+
|
188
|
+
function isArguments (object) {
|
189
|
+
return Object.prototype.toString.call(object) == '[object Arguments]';
|
190
|
+
}
|
191
|
+
|
192
|
+
function objEquiv (a, b) {
|
193
|
+
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
|
194
|
+
return false;
|
195
|
+
// an identical "prototype" property.
|
196
|
+
if (a.prototype !== b.prototype) return false;
|
197
|
+
//~~~I've managed to break Object.keys through screwy arguments passing.
|
198
|
+
// Converting to array solves the problem.
|
199
|
+
if (isArguments(a)) {
|
200
|
+
if (!isArguments(b)) {
|
201
|
+
return false;
|
202
|
+
}
|
203
|
+
a = pSlice.call(a);
|
204
|
+
b = pSlice.call(b);
|
205
|
+
return _deepEqual(a, b);
|
206
|
+
}
|
207
|
+
try{
|
208
|
+
var ka = _keys(a),
|
209
|
+
kb = _keys(b),
|
210
|
+
key, i;
|
211
|
+
} catch (e) {//happens when one is a string literal and the other isn't
|
212
|
+
return false;
|
213
|
+
}
|
214
|
+
// having the same number of owned properties (keys incorporates hasOwnProperty)
|
215
|
+
if (ka.length != kb.length)
|
216
|
+
return false;
|
217
|
+
//the same set of keys (although not necessarily the same order),
|
218
|
+
ka.sort();
|
219
|
+
kb.sort();
|
220
|
+
//~~~cheap key test
|
221
|
+
for (i = ka.length - 1; i >= 0; i--) {
|
222
|
+
if (ka[i] != kb[i])
|
223
|
+
return false;
|
224
|
+
}
|
225
|
+
//equivalent values for every corresponding key, and
|
226
|
+
//~~~possibly expensive deep test
|
227
|
+
for (i = ka.length - 1; i >= 0; i--) {
|
228
|
+
key = ka[i];
|
229
|
+
if (!_deepEqual(a[key], b[key] ))
|
230
|
+
return false;
|
231
|
+
}
|
232
|
+
return true;
|
233
|
+
}
|
234
|
+
|
235
|
+
// 8. The non-equivalence assertion tests for any deep inequality.
|
236
|
+
// assert.notDeepEqual(actual, expected, message_opt);
|
237
|
+
|
238
|
+
assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
|
239
|
+
if (_deepEqual(actual, expected)) {
|
240
|
+
fail(actual, expected, message, "notDeepEqual", assert.notDeepEqual);
|
241
|
+
}
|
242
|
+
};
|
243
|
+
|
244
|
+
// 9. The strict equality assertion tests strict equality, as determined by ===.
|
245
|
+
// assert.strictEqual(actual, expected, message_opt);
|
246
|
+
|
247
|
+
assert.strictEqual = function strictEqual(actual, expected, message) {
|
248
|
+
if (actual !== expected) {
|
249
|
+
fail(actual, expected, message, "===", assert.strictEqual);
|
250
|
+
}
|
251
|
+
};
|
252
|
+
|
253
|
+
// 10. The strict non-equality assertion tests for strict inequality, as determined by !==.
|
254
|
+
// assert.notStrictEqual(actual, expected, message_opt);
|
255
|
+
|
256
|
+
assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
|
257
|
+
if (actual === expected) {
|
258
|
+
fail(actual, expected, message, "!==", assert.notStrictEqual);
|
259
|
+
}
|
260
|
+
};
|
261
|
+
|
262
|
+
function _throws (shouldThrow, block, err, message) {
|
263
|
+
var exception = null,
|
264
|
+
threw = false,
|
265
|
+
typematters = true;
|
266
|
+
|
267
|
+
message = message || "";
|
268
|
+
|
269
|
+
//handle optional arguments
|
270
|
+
if (arguments.length == 3) {
|
271
|
+
if (typeof(err) == "string") {
|
272
|
+
message = err;
|
273
|
+
typematters = false;
|
274
|
+
}
|
275
|
+
} else if (arguments.length == 2) {
|
276
|
+
typematters = false;
|
277
|
+
}
|
278
|
+
|
279
|
+
try {
|
280
|
+
block();
|
281
|
+
} catch (e) {
|
282
|
+
threw = true;
|
283
|
+
exception = e;
|
284
|
+
}
|
285
|
+
|
286
|
+
if (shouldThrow && !threw) {
|
287
|
+
fail( "Missing expected exception"
|
288
|
+
+ (err && err.name ? " ("+err.name+")." : '.')
|
289
|
+
+ (message ? " " + message : "")
|
290
|
+
);
|
291
|
+
}
|
292
|
+
if (!shouldThrow && threw && typematters && exception instanceof err) {
|
293
|
+
fail( "Got unwanted exception"
|
294
|
+
+ (err && err.name ? " ("+err.name+")." : '.')
|
295
|
+
+ (message ? " " + message : "")
|
296
|
+
);
|
297
|
+
}
|
298
|
+
if ((shouldThrow && threw && typematters && !(exception instanceof err)) ||
|
299
|
+
(!shouldThrow && threw)) {
|
300
|
+
throw exception;
|
301
|
+
}
|
302
|
+
};
|
303
|
+
|
304
|
+
// 11. Expected to throw an error:
|
305
|
+
// assert.throws(block, Error_opt, message_opt);
|
306
|
+
|
307
|
+
assert.throws = function(block, /*optional*/error, /*optional*/message) {
|
308
|
+
_throws.apply(this, [true].concat(pSlice.call(arguments)));
|
309
|
+
};
|
310
|
+
|
311
|
+
// EXTENSION! This is annoying to write outside this module.
|
312
|
+
assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
|
313
|
+
_throws.apply(this, [false].concat(pSlice.call(arguments)));
|
314
|
+
};
|
315
|
+
|
316
|
+
assert.ifError = function (err) { if (err) {throw err;}};
|
@@ -0,0 +1,260 @@
|
|
1
|
+
/*!
|
2
|
+
* Nodeunit
|
3
|
+
* Copyright (c) 2010 Caolan McMahon
|
4
|
+
* MIT Licensed
|
5
|
+
*
|
6
|
+
* THIS FILE SHOULD BE BROWSER-COMPATIBLE JS!
|
7
|
+
* You can use @REMOVE_LINE_FOR_BROWSER to remove code from the browser build.
|
8
|
+
* Only code on that line will be removed, its mostly to avoid requiring code
|
9
|
+
* that is node specific
|
10
|
+
*/
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Module dependencies
|
14
|
+
*/
|
15
|
+
|
16
|
+
var async = require('../deps/async'), //@REMOVE_LINE_FOR_BROWSER
|
17
|
+
types = require('./types'); //@REMOVE_LINE_FOR_BROWSER
|
18
|
+
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Added for browser compatibility
|
22
|
+
*/
|
23
|
+
|
24
|
+
var _keys = function(obj){
|
25
|
+
if(Object.keys) return Object.keys(obj);
|
26
|
+
var keys = [];
|
27
|
+
for(var k in obj){
|
28
|
+
if(obj.hasOwnProperty(k)) keys.push(k);
|
29
|
+
}
|
30
|
+
return keys;
|
31
|
+
};
|
32
|
+
|
33
|
+
|
34
|
+
var _copy = function(obj){
|
35
|
+
var nobj = Object();
|
36
|
+
var keys = _keys(obj);
|
37
|
+
for (var i = 0; i < keys.length; i++){
|
38
|
+
nobj[keys[i]] = obj[keys[i]];
|
39
|
+
}
|
40
|
+
return nobj;
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Runs a test function (fn) from a loaded module. After the test function
|
46
|
+
* calls test.done(), the callback is executed with an assertionList as its
|
47
|
+
* second argument.
|
48
|
+
*
|
49
|
+
* @param {String} name
|
50
|
+
* @param {Function} fn
|
51
|
+
* @param {Object} opt
|
52
|
+
* @param {Function} callback
|
53
|
+
* @api public
|
54
|
+
*/
|
55
|
+
|
56
|
+
exports.runTest = function (name, fn, opt, callback) {
|
57
|
+
var options = types.options(opt);
|
58
|
+
|
59
|
+
options.testStart(name);
|
60
|
+
var start = new Date().getTime();
|
61
|
+
var test = types.test(name, start, options, callback);
|
62
|
+
|
63
|
+
try {
|
64
|
+
fn(test);
|
65
|
+
}
|
66
|
+
catch (e) {
|
67
|
+
test.done(e);
|
68
|
+
}
|
69
|
+
};
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Takes an object containing test functions or other test suites as properties
|
73
|
+
* and runs each in series. After all tests have completed, the callback is
|
74
|
+
* called with a list of all assertions as the second argument.
|
75
|
+
*
|
76
|
+
* If a name is passed to this function it is prepended to all test and suite
|
77
|
+
* names that run within it.
|
78
|
+
*
|
79
|
+
* @param {String} name
|
80
|
+
* @param {Object} suite
|
81
|
+
* @param {Object} opt
|
82
|
+
* @param {Function} callback
|
83
|
+
* @api public
|
84
|
+
*/
|
85
|
+
|
86
|
+
exports.runSuite = function (name, suite, opt, callback) {
|
87
|
+
var keys = _keys(suite);
|
88
|
+
|
89
|
+
async.concatSeries(keys, function (k, cb) {
|
90
|
+
var prop = suite[k], _name;
|
91
|
+
|
92
|
+
_name = name ? [].concat(name, k) : [k];
|
93
|
+
|
94
|
+
_name.toString = function () {
|
95
|
+
// fallback for old one
|
96
|
+
return this.join(' - ');
|
97
|
+
};
|
98
|
+
|
99
|
+
if (typeof prop === 'function') {
|
100
|
+
if (!opt.testspec || _name.indexOf(opt.testspec) != -1){
|
101
|
+
if (opt.moduleStart)
|
102
|
+
opt.moduleStart();
|
103
|
+
exports.runTest(_name, suite[k], opt, cb);
|
104
|
+
} else
|
105
|
+
return cb();
|
106
|
+
}
|
107
|
+
else {
|
108
|
+
exports.runSuite(_name, suite[k], opt, cb);
|
109
|
+
}
|
110
|
+
}, callback);
|
111
|
+
};
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Run each exported test function or test suite from a loaded module.
|
115
|
+
*
|
116
|
+
* @param {String} name
|
117
|
+
* @param {Object} mod
|
118
|
+
* @param {Object} opt
|
119
|
+
* @param {Function} callback
|
120
|
+
* @api public
|
121
|
+
*/
|
122
|
+
|
123
|
+
exports.runModule = function (name, mod, opt, callback) {
|
124
|
+
var options = _copy(types.options(opt));
|
125
|
+
|
126
|
+
var _run = false;
|
127
|
+
var _moduleStart = options.moduleStart;
|
128
|
+
function run_once(){
|
129
|
+
if (!_run){
|
130
|
+
_run = true;
|
131
|
+
_moduleStart(name);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
options.moduleStart = run_once;
|
135
|
+
|
136
|
+
var start = new Date().getTime();
|
137
|
+
|
138
|
+
exports.runSuite(null, mod, options, function (err, a_list) {
|
139
|
+
var end = new Date().getTime();
|
140
|
+
var assertion_list = types.assertionList(a_list, end - start);
|
141
|
+
options.moduleDone(name, assertion_list);
|
142
|
+
callback(null, a_list);
|
143
|
+
});
|
144
|
+
};
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Treats an object literal as a list of modules keyed by name. Runs each
|
148
|
+
* module and finished with calling 'done'. You can think of this as a browser
|
149
|
+
* safe alternative to runFiles in the nodeunit module.
|
150
|
+
*
|
151
|
+
* @param {Object} modules
|
152
|
+
* @param {Object} opt
|
153
|
+
* @api public
|
154
|
+
*/
|
155
|
+
|
156
|
+
// TODO: add proper unit tests for this function
|
157
|
+
exports.runModules = function (modules, opt) {
|
158
|
+
var all_assertions = [];
|
159
|
+
var options = types.options(opt);
|
160
|
+
var start = new Date().getTime();
|
161
|
+
|
162
|
+
async.concatSeries(_keys(modules), function (k, cb) {
|
163
|
+
exports.runModule(k, modules[k], options, cb);
|
164
|
+
},
|
165
|
+
function (err, all_assertions) {
|
166
|
+
var end = new Date().getTime();
|
167
|
+
options.done(types.assertionList(all_assertions, end - start));
|
168
|
+
});
|
169
|
+
};
|
170
|
+
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Wraps a test function with setUp and tearDown functions.
|
174
|
+
* Used by testCase.
|
175
|
+
*
|
176
|
+
* @param {Function} setUp
|
177
|
+
* @param {Function} tearDown
|
178
|
+
* @param {Function} fn
|
179
|
+
* @api private
|
180
|
+
*/
|
181
|
+
|
182
|
+
var wrapTest = function (setUp, tearDown, fn) {
|
183
|
+
return function (test) {
|
184
|
+
var context = {};
|
185
|
+
if (tearDown) {
|
186
|
+
var done = test.done;
|
187
|
+
test.done = function (err) {
|
188
|
+
try {
|
189
|
+
tearDown.call(context, function (err2) {
|
190
|
+
if (err && err2) {
|
191
|
+
test._assertion_list.push(
|
192
|
+
types.assertion({error: err})
|
193
|
+
);
|
194
|
+
return done(err2);
|
195
|
+
}
|
196
|
+
done(err || err2);
|
197
|
+
});
|
198
|
+
}
|
199
|
+
catch (e) {
|
200
|
+
done(e);
|
201
|
+
}
|
202
|
+
};
|
203
|
+
}
|
204
|
+
if (setUp) {
|
205
|
+
setUp.call(context, function (err) {
|
206
|
+
if (err) {
|
207
|
+
return test.done(err);
|
208
|
+
}
|
209
|
+
fn.call(context, test);
|
210
|
+
});
|
211
|
+
}
|
212
|
+
else {
|
213
|
+
fn.call(context, test);
|
214
|
+
}
|
215
|
+
}
|
216
|
+
};
|
217
|
+
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Wraps a group of tests with setUp and tearDown functions.
|
221
|
+
* Used by testCase.
|
222
|
+
*
|
223
|
+
* @param {Function} setUp
|
224
|
+
* @param {Function} tearDown
|
225
|
+
* @param {Object} group
|
226
|
+
* @api private
|
227
|
+
*/
|
228
|
+
|
229
|
+
var wrapGroup = function (setUp, tearDown, group) {
|
230
|
+
var tests = {};
|
231
|
+
var keys = _keys(group);
|
232
|
+
for (var i=0; i<keys.length; i++) {
|
233
|
+
var k = keys[i];
|
234
|
+
if (typeof group[k] === 'function') {
|
235
|
+
tests[k] = wrapTest(setUp, tearDown, group[k]);
|
236
|
+
}
|
237
|
+
else if (typeof group[k] === 'object') {
|
238
|
+
tests[k] = wrapGroup(setUp, tearDown, group[k]);
|
239
|
+
}
|
240
|
+
}
|
241
|
+
return tests;
|
242
|
+
}
|
243
|
+
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Utility for wrapping a suite of test functions with setUp and tearDown
|
247
|
+
* functions.
|
248
|
+
*
|
249
|
+
* @param {Object} suite
|
250
|
+
* @return {Object}
|
251
|
+
* @api public
|
252
|
+
*/
|
253
|
+
|
254
|
+
exports.testCase = function (suite) {
|
255
|
+
var setUp = suite.setUp;
|
256
|
+
var tearDown = suite.tearDown;
|
257
|
+
delete suite.setUp;
|
258
|
+
delete suite.tearDown;
|
259
|
+
return wrapGroup(setUp, tearDown, suite);
|
260
|
+
};
|