Permalink
Browse files

Updated buster unit tests to also run in browsers via buster server

  • Loading branch information...
1 parent c3757d8 commit 4cf7f3b9fbed1600e7e2c4457dfc2833dcaf61e2 @briancavalier briancavalier committed Feb 6, 2012
Showing with 117 additions and 256 deletions.
  1. +2 −1 .gitignore
  2. +0 −3 .gitmodules
  3. +23 −24 test/all.js
  4. +8 −6 test/apply.js
  5. +22 −3 test/buster.js
  6. +10 −7 test/cancelable.js
  7. +11 −9 test/delay.js
  8. +11 −6 test/isPromise.js
  9. +5 −3 test/map.js
  10. +5 −3 test/reduce.js
  11. +0 −177 test/test-config.js
  12. +5 −3 test/then.js
  13. +10 −8 test/timeout.js
  14. +5 −3 test/when.js
View
@@ -1,2 +1,3 @@
.npmignore
-.idea/
+.idea/
+experiments/
View
@@ -1,3 +0,0 @@
-[submodule "test/util"]
- path = test/util
- url = https://github.com/cujojs/util.git
View
@@ -1,27 +1,26 @@
-// DOH seems to faily consistently on the first test suite, so I'm putting
-// in this fake suite so it will fail and all the real tests results will
-// be meaningful.
-doh.registerUrl('_fake', '../../_fake-doh.html');
+// Test boilerplate
+var buster, assert, refute, when;
-doh.registerUrl('when.isPromise', '../../isPromise.html');
-doh.registerUrl('when', '../../when.html');
-doh.registerUrl('assimilate', '../../assimilate.html');
-doh.registerUrl('when.defer', '../../defer.html');
-doh.registerUrl('when.some', '../../some.html');
-doh.registerUrl('when.any', '../../any.html');
-doh.registerUrl('when.all', '../../all.html');
-doh.registerUrl('when.chain', '../../chain.html');
+if (typeof require != "undefined") {
+ buster = require("buster");
+ when = require('../when');
+}
-doh.registerUrl('when.map', '../../map.html');
-doh.registerUrl('when.reduce', '../../reduce.html');
+assert = buster.assert;
+refute = buster.refute;
+// end boilerplate
-doh.registerUrl('checkHandlers', '../../checkHandlers.html');
-
-// Helpers
-doh.registerUrl('when/cancelable', '../../cancelable.html');
-doh.registerUrl('when/timeout', '../../timeout.html');
-doh.registerUrl('when/delay', '../../delay.html');
-
-doh.registerUrl('when/apply', '../../apply.html');
-
-doh.run();
+buster.testCase('when.all', {
+ 'should resolve with empty input': function(done) {
+ when.all([],
+ function(result) {
+ assert.equals(result, []);
+ done();
+ },
+ function() {
+ buster.fail();
+ done();
+ }
+ );
+ }
+});
View
@@ -1,11 +1,13 @@
// Test boilerplate
-var buster, assert, refute, when;
+var buster, assert, refute, when_apply;
+
+if (typeof require != "undefined") {
+ buster = require("buster");
+ when_apply = require('../apply');
+}
-buster = require('buster');
assert = buster.assert;
refute = buster.refute;
-
-apply = require('../apply');
// end boilerplate
// variadic arguments-based callback
@@ -22,12 +24,12 @@ function f() {
buster.testCase('when/apply', {
'should spread array onto arguments': function() {
- assert.equals(6, apply(f)([1,2,3]));
+ assert.equals(6, when_apply(f)([1,2,3]));
},
'should fail for non Array-like input': function() {
assert.exception(function() {
- apply(f)(1,2,3);
+ when_apply(f)(1,2,3);
});
}
});
View
@@ -1,5 +1,24 @@
-exports['when'] = {
+var tests = [
+ 'isPromise.js',
+ 'then.js',
+ 'when.js',
+ 'all.js',
+ 'map.js',
+ 'reduce.js',
+ 'apply.js',
+ 'delay.js',
+ 'timeout.js',
+ 'cancelable.js'
+// '*.js'
+];
+
+exports['when:node'] = {
env: 'node',
- tests: [ 'isPromise.js', 'then.js', 'when.js', 'apply.js', 'delay.js', 'timeout.js', 'cancelable.js',
- 'map.js', 'reduce.js' ]
+ tests: tests
+};
+
+exports['when:browser'] = {
+ env: 'browser',
+ libs: [ '../when.js', '../apply.js', '../delay.js', '../timeout.js', '../cancelable.js' ],
+ tests: tests
};
View
@@ -1,12 +1,15 @@
// Test boilerplate
-var buster, assert, refute, when;
+var buster, assert, refute, when, when_cancelable;
+
+if (typeof require != "undefined") {
+ buster = require("buster");
+ when = require('../when');
+ when_cancelable = require('../cancelable');
+}
-buster = require('buster');
assert = buster.assert;
refute = buster.refute;
-when = require('../when');
-cancelable = require('../cancelable');
// end boilerplate
function FakePromise(val) {
@@ -17,12 +20,12 @@ function FakePromise(val) {
buster.testCase('when/cancelable', {
'should decorate deferred with a cancel() method': function() {
- var c = cancelable(when.defer(), function() {});
+ var c = when_cancelable(when.defer(), function() {});
assert.typeOf(c.cancel, 'function');
},
'should propagate a rejection when a cancelabled deferred is canceled': function(done) {
- var c = cancelable(when.defer(), function() { return 1; });
+ var c = when_cancelable(when.defer(), function() { return 1; });
c.cancel();
c.then(
@@ -38,7 +41,7 @@ buster.testCase('when/cancelable', {
},
'should not invoke canceler when rejected normally': function(done) {
- var c = cancelable(when.defer(), function() { return 1; });
+ var c = when_cancelable(when.defer(), function() { return 1; });
c.reject(2);
c.then(
View
@@ -1,12 +1,14 @@
// Test boilerplate
-var buster, assert, refute, when;
+var buster, assert, refute, when, when_delay;
+
+if (typeof require != "undefined") {
+ buster = require("buster");
+ when = require('../when');
+ when_delay = require('../delay');
+}
-buster = require('buster');
assert = buster.assert;
refute = buster.refute;
-
-when = require('../when');
-delay = require('../delay');
// end boilerplate
function now() {
@@ -21,7 +23,7 @@ function FakePromise(val) {
buster.testCase('when/delay', {
'should resolve after delay': function(done) {
- delay(0).then(
+ when_delay(0).then(
function() {
assert(true);
done();
@@ -34,7 +36,7 @@ buster.testCase('when/delay', {
},
'should resolve with provided value after delay': function(done) {
- delay(1, 0).then(
+ when_delay(1, 0).then(
function(val) {
assert.equals(val, 1);
done();
@@ -49,7 +51,7 @@ buster.testCase('when/delay', {
'should delay by the provided value': function(done) {
var start = now();
- delay(100).then(
+ when_delay(100).then(
function() {
assert((now() - start) > 50);
done();
@@ -65,7 +67,7 @@ buster.testCase('when/delay', {
var d = when.defer();
d.reject(1);
- delay(d.promise, 0).then(
+ when_delay(d.promise, 0).then(
function() {
buster.fail();
done();
View
@@ -1,22 +1,27 @@
// Test boilerplate
-var buster, when;
+var buster, assert, refute, when;
-buster = require('buster');
-when = require('../when');
-// end boilerplate
+if (typeof require != "undefined") {
+ buster = require("buster");
+ when = require('../when');
+}
+assert = buster.assert;
+refute = buster.refute;
+
+// end boilerplate
var fakePromise, undef;
fakePromise = {
then:function () {}
};
function assertIsPromise(it) {
- buster.assert(when.isPromise(it));
+ assert(when.isPromise(it));
}
function assertIsNotPromise(it) {
- buster.refute(when.isPromise(it));
+ refute(when.isPromise(it));
}
buster.testCase('when.isPromise', {
View
@@ -1,11 +1,13 @@
// Test boilerplate
var buster, assert, refute, when;
-buster = require('buster');
+if (typeof require != "undefined") {
+ buster = require("buster");
+ when = require('../when');
+}
+
assert = buster.assert;
refute = buster.refute;
-
-when = require('../when');
// end boilerplate
function mapper(val) {
View
@@ -1,11 +1,13 @@
// Test boilerplate
var buster, assert, refute, when;
-buster = require('buster');
+if (typeof require != "undefined") {
+ buster = require("buster");
+ when = require('../when');
+}
+
assert = buster.assert;
refute = buster.refute;
-
-when = require('../when');
// end boilerplate
function plus(sum, val) {
Oops, something went wrong.

0 comments on commit 4cf7f3b

Please sign in to comment.