Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 4cf7f3b9fbed1600e7e2c4457dfc2833dcaf61e2 1 parent c3757d8
@briancavalier briancavalier authored
View
3  .gitignore
@@ -1,2 +1,3 @@
.npmignore
-.idea/
+.idea/
+experiments/
View
3  .gitmodules
@@ -1,3 +0,0 @@
-[submodule "test/util"]
- path = test/util
- url = https://github.com/cujojs/util.git
View
47 test/all.js
@@ -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
14 test/apply.js
@@ -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
25 test/buster.js
@@ -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
17 test/cancelable.js
@@ -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
20 test/delay.js
@@ -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
17 test/isPromise.js
@@ -1,10 +1,15 @@
// 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 = {
@@ -12,11 +17,11 @@ fakePromise = {
};
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
8 test/map.js
@@ -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
8 test/reduce.js
@@ -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) {
View
177 test/test-config.js
@@ -1,177 +0,0 @@
-(function(global, doh) {
-
- function assertIsPromise(it) {
- doh.assertTrue(when.isPromise(it));
- }
-
- function assertIsNotPromise(it) {
- doh.assertFalse(when.isPromise(it));
- }
-
- function assertResolutionEquals(expected, dohDeferred) {
- return function(result) {
- dohDeferred.callback(expected === result);
- };
- }
-
- function rejecter(dohDeferred) {
- return function(e) {
- dohDeferred.errback(e);
- };
- }
-
- doh.assertIsPromise = assertIsPromise;
- doh.assertIsNotPromise = assertIsNotPromise;
- doh.assertResolutionEquals = assertResolutionEquals;
- doh.rejecter = rejecter;
-
- function indexOf(array, val) {
- var len, i;
- len = array.length;
- i = 0;
- for(;i<len; i++) {
- if(i in array && array[i] === val) {
- return i;
- }
- }
-
- return -1;
- }
-
- function getArrayAssertion(dohd, expected, expectedLength) {
- // Return a promise handler that will verify the results
- return function (val) {
- var success = expectedLength === val.length;
-
- // This test may be overlay lax
- // The question of order and array position for when.some
- // is still up in the air, so this test simply ensures
- // that the results values are somewhere in the expected
- // set.
- for (var i = 0; i < expectedLength; i++) {
- success = success && (indexOf(expected, val[i]) >= 0);
- }
-
- dohd.callback(success);
- }
- }
-
- function assertSameContents(dohd, array1, array2) {
- var len1, len2, i, success;
-
- len1 = array1.length;
- len2 = array2.length;
-
- success = len1 === len2;
-
- i = 0;
- while (success && i < len1) {
- success = success && array1[i] === array2[i];
- ++i;
- }
-
- dohd.callback(success);
-
- }
-
- doh.asyncHelper = {
- indexOf: indexOf,
- map: function(array, mapper) {
- var result, len, i;
-
- result = [];
- len = array.length;
- i = 0;
-
- for(;i<len; i++) {
- if(i in array) {
- result[i] = mapper(array[i]);
- }
- }
-
- return result;
- },
- deferN: function(n) {
- // Create an array of N values, and N deferreds.
- // Each deferred will resolve to its corresponding value
- // after a random timeout
-
- var values, deferreds, i = 0;
-
- values = [];
- deferreds = [];
-
- for (; i < n; i++) {
- values.push(i);
- deferreds.push(when.defer());
- }
-
- for (i = 0; i < n; i++) {
- (function(i) {
- setTimeout(function() {
- deferreds[i].resolve(values[i]);
- }, Math.random() * 10);
- })(i);
- }
-
- return { values: values, promises: deferreds };
- },
- assertSome: function(expected, promisesOrValues, howMany, howManyExpected) {
- var dohd = new doh.Deferred();
-
- when.some(promisesOrValues, howMany,
- getArrayAssertion(dohd, expected, howManyExpected),
- doh.rejecter(dohd)
- );
-
- return dohd;
- },
- assertAll: function(expected, promisesOrValues) {
- var dohd = new doh.Deferred();
-
- when.all(promisesOrValues,
- function(results) {
- assertSameContents(dohd, expected, results);
- },
- doh.rejecter(dohd)
- );
-
- return dohd;
- },
- assertSameContents: assertSameContents,
- assertRejected: function(promise, value) {
- var dohd, args;
-
- dohd = new doh.Deferred();
-
- args = arguments;
-
- promise.then(
- function(e) { dohd.errback(e); },
- function(v) {
- dohd.callback(args.length < 2 ? true : (value === v));
- }
- );
-
- return dohd;
- },
- assertResolved: function(promise, value) {
- var dohd, args;
-
- dohd = new doh.Deferred();
-
- args = arguments;
-
- promise.then(
- function(v) {
- dohd.callback(args.length < 2 ? true : (value === v));
- },
- function(e) { dohd.errback(e); }
- );
-
- return dohd;
- }
-
- }
-
-})(this, doh);
View
8 test/then.js
@@ -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
var defer, undef;
View
18 test/timeout.js
@@ -1,12 +1,14 @@
// Test boilerplate
-var buster, assert, refute, when;
+var buster, assert, refute, when, when_timeout;
+
+if (typeof require != "undefined") {
+ buster = require("buster");
+ when = require('../when');
+ when_timeout = require('../timeout');
+}
-buster = require('buster');
assert = buster.assert;
refute = buster.refute;
-
-when = require('../when');
-timeout = require('../timeout');
// end boilerplate
function FakePromise(val) {
@@ -17,7 +19,7 @@ function FakePromise(val) {
buster.testCase('when/timeout', {
'should reject after timeout': function(done) {
- timeout(new FakePromise(1), 0).then(
+ when_timeout(new FakePromise(1), 0).then(
function() {
buster.fail();
done();
@@ -33,7 +35,7 @@ buster.testCase('when/timeout', {
var d = when.defer();
d.reject(1);
- timeout(d, 0).then(
+ when_timeout(d, 0).then(
function() {
buster.fail();
done();
@@ -49,7 +51,7 @@ buster.testCase('when/timeout', {
var d = when.defer();
d.resolve(1);
- timeout(d, 0).then(
+ when_timeout(d, 0).then(
function(val) {
assert.equals(val, 1);
done();
View
8 test/when.js
@@ -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 identity(val) { return val; }
Please sign in to comment.
Something went wrong with that request. Please try again.