Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add npm test, travis config, remove globals.

  • Loading branch information...
commit 4a7314a393f0723272dedc0a1ea8a362da4b205d 1 parent ec2b5f0
@braddunbar braddunbar authored
View
3  .gitignore
@@ -1 +1,2 @@
-raw
+raw
+node_modules
View
5 .travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+ - 0.8
+notifications:
+ email: false
View
8 package.json
@@ -6,5 +6,11 @@
"author" : "Jeremy Ashkenas <jeremy@documentcloud.org>",
"repository" : {"type": "git", "url": "git://github.com/documentcloud/underscore.git"},
"main" : "underscore.js",
- "version" : "1.4.3"
+ "version" : "1.4.3",
+ "devDependencies": {
+ "phantomjs": "0.2.2"
+ },
+ "scripts": {
+ "test": "phantomjs test/vendor/runner.js test/index.html?noglobals=true"
+ }
}
View
2  test/arrays.js
@@ -182,7 +182,7 @@ $(document).ready(function() {
equal(_.indexOf(null, 2), -1, 'handles nulls properly');
numbers = [1, 2, 3, 1, 2, 3, 1, 2, 3];
- index = _.lastIndexOf(numbers, 2, 2);
+ var index = _.lastIndexOf(numbers, 2, 2);
equal(index, 1, 'supports the fromIndex argument');
});
View
2  test/collections.js
@@ -22,7 +22,7 @@ $(document).ready(function() {
equal(answers.join(", "), 'one, two, three', 'iterating over objects works, and ignores the object prototype.');
delete obj.constructor.prototype.four;
- answer = null;
+ var answer = null;
_.each([1, 2, 3], function(num, index, arr){ if (_.include(arr, num)) answer = true; });
ok(answer, 'can reference the original collection from inside the iterator');
View
4 test/objects.js
@@ -555,7 +555,7 @@ $(document).ready(function() {
value();
ok(returned == 6 && intercepted == 6, 'can use tapped objects in a chain');
});
-
+
test("has", function () {
var obj = {foo: "bar", func: function () {} };
ok (_.has(obj, "foo"), "has() checks that the object has a property.");
@@ -563,7 +563,7 @@ $(document).ready(function() {
ok (_.has(obj, "func"), "has() works for functions too.");
obj.hasOwnProperty = null;
ok (_.has(obj, "foo"), "has() works even when the hasOwnProperty method is deleted.");
- child = {};
+ var child = {};
child.prototype = obj;
ok (_.has(child, "foo") == false, "has() does not check the prototype chain for a property.")
});
View
6 test/utility.js
@@ -82,7 +82,7 @@ $(document).ready(function() {
equal(escapeTemplate({a: true}), 'checked="checked"', 'can handle slash escapes in interpolations.');
var fancyTemplate = _.template("<ul><% \
- for (key in people) { \
+ for (var key in people) { \
%><li><%= people[key] %></li><% } %></ul>");
result = fancyTemplate({people : {moe : "Moe", larry : "Larry", curly : "Curly"}});
equal(result, "<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>", 'can run arbitrary javascript in templates');
@@ -137,7 +137,7 @@ $(document).ready(function() {
interpolate : /\{\{=([\s\S]+?)\}\}/g
};
- var custom = _.template("<ul>{{ for (key in people) { }}<li>{{= people[key] }}</li>{{ } }}</ul>");
+ var custom = _.template("<ul>{{ for (var key in people) { }}<li>{{= people[key] }}</li>{{ } }}</ul>");
result = custom({people : {moe : "Moe", larry : "Larry", curly : "Curly"}});
equal(result, "<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>", 'can run arbitrary javascript in templates');
@@ -152,7 +152,7 @@ $(document).ready(function() {
interpolate : /<\?=([\s\S]+?)\?>/g
};
- var customWithSpecialChars = _.template("<ul><? for (key in people) { ?><li><?= people[key] ?></li><? } ?></ul>");
+ var customWithSpecialChars = _.template("<ul><? for (var key in people) { ?><li><?= people[key] ?></li><? } ?></ul>");
result = customWithSpecialChars({people : {moe : "Moe", larry : "Larry", curly : "Curly"}});
equal(result, "<ul><li>Moe</li><li>Larry</li><li>Curly</li></ul>", 'can run arbitrary javascript in templates');
View
98 test/vendor/runner.js
@@ -0,0 +1,98 @@
+/*
+ * Qt+WebKit powered headless test runner using Phantomjs
+ *
+ * Phantomjs installation: http://code.google.com/p/phantomjs/wiki/BuildInstructions
+ *
+ * Run with:
+ * phantomjs runner.js [url-of-your-qunit-testsuite]
+ *
+ * E.g.
+ * phantomjs runner.js http://localhost/qunit/test
+ */
+
+/*jshint latedef:false */
+/*global phantom:true require:true console:true */
+var url = phantom.args[0],
+ page = require('webpage').create();
+
+// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
+page.onConsoleMessage = function(msg) {
+ console.log(msg);
+};
+
+page.onInitialized = function() {
+ page.evaluate(addLogging);
+};
+page.open(url, function(status){
+ if (status !== "success") {
+ console.log("Unable to access network: " + status);
+ phantom.exit(1);
+ } else {
+ // page.evaluate(addLogging);
+ var interval = setInterval(function() {
+ if (finished()) {
+ clearInterval(interval);
+ onfinishedTests();
+ }
+ }, 500);
+ }
+});
+
+function finished() {
+ return page.evaluate(function(){
+ return !!window.qunitDone;
+ });
+}
+
+function onfinishedTests() {
+ var output = page.evaluate(function() {
+ return JSON.stringify(window.qunitDone);
+ });
+ phantom.exit(JSON.parse(output).failed > 0 ? 1 : 0);
+}
+
+function addLogging() {
+ window.document.addEventListener( "DOMContentLoaded", function() {
+ var current_test_assertions = [];
+
+ QUnit.testDone(function(result) {
+ var i,
+ name = result.module + ': ' + result.name;
+
+ if (result.failed) {
+ console.log('Assertion Failed: ' + name);
+
+ for (i = 0; i < current_test_assertions.length; i++) {
+ console.log(' ' + current_test_assertions[i]);
+ }
+ }
+
+ current_test_assertions = [];
+ });
+
+ QUnit.log(function(details) {
+ var response;
+
+ if (details.result) {
+ return;
+ }
+
+ response = details.message || '';
+
+ if (typeof details.expected !== 'undefined') {
+ if (response) {
+ response += ', ';
+ }
+
+ response += 'expected: ' + details.expected + ', but was: ' + details.actual;
+ }
+
+ current_test_assertions.push('Failed assertion: ' + response);
+ });
+
+ QUnit.done(function(result){
+ console.log('Took ' + result.runtime + 'ms to run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed + ' failed.');
+ window.qunitDone = result;
+ });
+ }, false );
+}
Please sign in to comment.
Something went wrong with that request. Please try again.