1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-12 02:42:48 +00:00

updated bunch of file paths and changed the way posts are loaded

This commit is contained in:
2016-01-05 12:28:04 -06:00
parent 4bb8cae81e
commit 6ab45fe935
13249 changed files with 317868 additions and 2101398 deletions

4
node_modules/mpromise/.npmignore generated vendored Normal file
View File

@@ -0,0 +1,4 @@
*.sw*
node_modules/
.DS_Store
.idea

5
node_modules/mpromise/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,5 @@
language: node_js
node_js:
- 0.8
- 0.10
- 0.11

74
node_modules/mpromise/History.md generated vendored Normal file
View File

@@ -0,0 +1,74 @@
0.5.1 / 2014-01-20
==================
* fixed; `end` is much more consistent (especially for `then` chains)
0.4.4 / 2014-01-20
==================
* fixed; `end` is much more consistent (especially for `then` chains)
0.4.3 / 2013-12-17
==================
* fixed; non-A+ behavior on fulfill and reject [lbeschastny](https://github.com/lbeschastny)
* tests; simplified harness + compatible with travis + compatible with windows
0.5.0 / 2013-12-14
==================
* fixed; non-A+ behavior on fulfill and reject [lbeschastny](https://github.com/lbeschastny)
* tests; simplified harness + compatible with travis + compatible with windows
0.4.2 / 2013-11-26
==================
* fixed; enter the domain only if not the present domain
* added; `end` returns the promise
0.4.1 / 2013-10-26
==================
* Add `all`
* Longjohn for easier debugging
* can end a promise chain with an error handler
* Add ```chain```
0.4.0 / 2013-10-24
==================
* fixed; now plays nice with domains #3 [refack](https://github.com/refack)
* updated; compatibility for Promises A+ 2.0.0 [refack](https://github.com/refack)
* updated; guard against invalid arguments [refack](https://github.com/refack)
0.3.0 / 2013-07-25
==================
* updated; sliced to 0.0.5
* fixed; then is passed all fulfillment values
* use setImmediate if available
* conform to Promises A+ 1.1
0.2.1 / 2013-02-09
==================
* fixed; conformancy with A+ 1.2
0.2.0 / 2013-01-09
==================
* added; .end()
* fixed; only catch handler executions
0.1.0 / 2013-01-08
==================
* cleaned up API
* customizable event names
* docs
0.0.1 / 2013-01-07
==================
* original release

22
node_modules/mpromise/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2012 [Aaron Heckmann](aaron.heckmann+github@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

224
node_modules/mpromise/README.md generated vendored Normal file
View File

@@ -0,0 +1,224 @@
#mpromise
==========
[![Build Status](https://travis-ci.org/aheckmann/mpromise.png)](https://travis-ci.org/aheckmann/mpromise)
A [promises/A+](https://github.com/promises-aplus/promises-spec) conformant implementation, written for [mongoose](http://mongoosejs.com).
## installation
```
$ npm install mpromise
```
## docs
An `mpromise` can be in any of three states, pending, fulfilled (success), or rejected (error). Once it is either fulfilled or rejected it's state can no longer be changed.
The exports object is the Promise constructor.
```js
var Promise = require('mpromise');
```
The constructor accepts an optional function which is executed when the promise is first resolved (either fulfilled or rejected).
```js
var promise = new Promise(fn);
```
This is the same as passing the `fn` to `onResolve` directly.
```js
var promise = new Promise;
promise.onResolve(function (err, args..) {
...
});
```
### Methods
####fulfill
Fulfilling a promise with values:
```js
var promise = new Promise;
promise.fulfill(args...);
```
If the promise has already been fulfilled or rejected, no action is taken.
####reject
Rejecting a promise with a reason:
```js
var promise = new Promise;
promise.reject(reason);
```
If the promise has already been fulfilled or rejected, no action is taken.
####resolve
Node.js callback style promise resolution `(err, args...)`:
```js
var promise = new Promise;
promise.resolve([reason], [arg1, arg2, ...]);
```
If the promise has already been fulfilled or rejected, no action is taken.
####onFulfill
To register a function for execution when the promise is fulfilled, pass it to `onFulfill`. When executed it will receive the arguments passed to `fulfill()`.
```js
var promise = new Promise;
promise.onFulfill(function (a, b) {
assert.equal(3, a + b);
});
promise.fulfill(1, 2);
```
The function will only be called once when the promise is fulfilled, never when rejected.
Registering a function with `onFulfill` after the promise has already been fulfilled results in the immediate execution of the function with the original arguments used to fulfill the promise.
```js
var promise = new Promise;
promise.fulfill(" :D ");
promise.onFulfill(function (arg) {
console.log(arg); // logs " :D "
})
```
####onReject
To register a function for execution when the promise is rejected, pass it to `onReject`. When executed it will receive the argument passed to `reject()`.
```js
var promise = new Promise;
promise.onReject(function (reason) {
assert.equal('sad', reason);
});
promise.reject('sad');
```
The function will only be called once when the promise is rejected, never when fulfilled.
Registering a function with `onReject` after the promise has already been rejected results in the immediate execution of the function with the original argument used to reject the promise.
```js
var promise = new Promise;
promise.reject(" :( ");
promise.onReject(function (reason) {
console.log(reason); // logs " :( "
})
```
####onResolve
Allows registration of node.js style callbacks `(err, args..)` to handle either promise resolution type (fulfill or reject).
```js
// fulfillment
var promise = new Promise;
promise.onResolve(function (err, a, b) {
console.log(a + b); // logs 3
});
promise.fulfill(1, 2);
// rejection
var promise = new Promise;
promise.onResolve(function (err) {
if (err) {
console.log(err.message); // logs "failed"
}
});
promise.reject(new Error('failed'));
```
####then
Creates a new promise and returns it. If `onFulfill` or `onReject` are passed, they are added as SUCCESS/ERROR callbacks to this promise after the nextTick.
Conforms to [promises/A+](https://github.com/promises-aplus/promises-spec) specification and passes its [tests](https://github.com/promises-aplus/promises-tests).
```js
// promise.then(onFulfill, onReject);
var p = new Promise;
p.then(function (arg) {
return arg + 1;
}).then(function (arg) {
throw new Error(arg + ' is an error!');
}).then(null, function (err) {
assert.ok(err instanceof Error);
assert.equal('2 is an error', err.message);
});
p.fullfill(1);
```
####end
Signifies that this promise was the last in a chain of `then()s`: if a handler passed to the call to `then` which produced this promise throws, the exception be rethrown.
You can pass an OnReject handler to `end` so that exceptions will be handled (like a final catch clause);
This method returns it's promise for easy use with `return`.
```js
var p = new Promise;
p.then(function(){ throw new Error('shucks') });
setTimeout(function () {
p.fulfill();
// error was caught and swallowed by the promise returned from
// p.then(). we either have to always register handlers on
// the returned promises or we can do the following...
}, 10);
// this time we use .end() which prevents catching thrown errors
var p = new Promise;
setTimeout(function () {
p.fulfill(); // throws "shucks"
}, 10);
return p.then(function(){ throw new Error('shucks') }).end(); // <--
```
### chain
Allows direct promise to promise chaining (especially useful by a outside aggregating function). It doesn't use the asynchronous `resolve` algorithm and so excepts only another Promise as it's argument.
```js
function makeMeAPromise(i) {
var p = new Promise;
p.fulfill(i);
return p;
}
var returnPromise = initialPromise = new Promise;
for (i=0; i<10; ++i)
returnPromise = returnPromise.chain(makeMeAPromise(i));
initialPromise.fulfill();
return returnPromise;
```
###Event names
If you'd like to alter this implementations event names used to signify success and failure you may do so by setting `Promise.SUCCESS` or `Promise.FAILURE` respectively.
```js
Promise.SUCCESS = 'complete';
Promise.FAILURE = 'err';
```
###Luke, use the Source
For more ideas read the [source](https://github.com/aheckmann/mpromise/blob/master/lib), [tests](https://github.com/aheckmann/mpromise/blob/master/test), or the [mongoose implementation](https://github.com/LearnBoost/mongoose/blob/3.6x/lib/promise.js).
## license
[MIT](https://github.com/aheckmann/mpromise/blob/master/LICENSE)

440
node_modules/mpromise/lib/promise.js generated vendored Normal file
View File

@@ -0,0 +1,440 @@
'use strict';
var util = require('util');
var EventEmitter = require('events').EventEmitter;
function toArray(arr, start, end) {
return Array.prototype.slice.call(arr, start, end)
}
function strongUnshift(x, arrLike) {
var arr = toArray(arrLike);
arr.unshift(x);
return arr;
}
/**
* Promise constructor.
*
* _NOTE: The success and failure event names can be overridden by setting `Promise.SUCCESS` and `Promise.FAILURE` respectively._
*
* @param {Function} back a function that accepts `fn(err, ...){}` as signature
* @inherits NodeJS EventEmitter http://nodejs.org/api/events.html#events_class_events_eventemitter
* @event `reject`: Emits when the promise is rejected (event name may be overridden)
* @event `fulfill`: Emits when the promise is fulfilled (event name may be overridden)
* @api public
*/
function Promise(back) {
this.emitter = new EventEmitter();
this.emitted = {};
this.ended = false;
if ('function' == typeof back)
this.onResolve(back);
}
/*
* Module exports.
*/
module.exports = Promise;
/*!
* event names
*/
Promise.SUCCESS = 'fulfill';
Promise.FAILURE = 'reject';
/**
* Adds `listener` to the `event`.
*
* If `event` is either the success or failure event and the event has already been emitted, the`listener` is called immediately and passed the results of the original emitted event.
*
* @param {String} event
* @param {Function} callback
* @return {Promise} this
* @api private
*/
Promise.prototype.on = function (event, callback) {
if (this.emitted[event])
callback.apply(undefined, this.emitted[event]);
else
this.emitter.on(event, callback);
return this;
};
/**
* Keeps track of emitted events to run them on `on`.
*
* @api private
*/
Promise.prototype.safeEmit = function (event) {
// ensures a promise can't be fulfill() or reject() more than once
if (event == Promise.SUCCESS || event == Promise.FAILURE) {
if (this.emitted[Promise.SUCCESS] || this.emitted[Promise.FAILURE]) {
return this;
}
this.emitted[event] = toArray(arguments, 1);
}
this.emitter.emit.apply(this.emitter, arguments);
return this;
};
/**
* Fulfills this promise with passed arguments.
*
* If this promise has already been fulfilled or rejected, no action is taken.
*
* @api public
*/
Promise.prototype.fulfill = function () {
return this.safeEmit.apply(this, strongUnshift(Promise.SUCCESS, arguments));
};
/**
* Rejects this promise with `reason`.
*
* If this promise has already been fulfilled or rejected, no action is taken.
*
* @api public
* @param {Object|String} reason
* @return {Promise} this
*/
Promise.prototype.reject = function (reason) {
if (this.ended && !this.hasRejectListeners()) throw reason;
return this.safeEmit(Promise.FAILURE, reason);
};
/**
* Resolves this promise to a rejected state if `err` is passed or
* fulfilled state if no `err` is passed.
*
* @param {Error} [err] error or null
* @param {Object} [val] value to fulfill the promise with
* @api public
*/
Promise.prototype.resolve = function (err, val) {
if (err) return this.reject(err);
return this.fulfill(val);
};
/**
* Adds a listener to the SUCCESS event.
*
* @return {Promise} this
* @api public
*/
Promise.prototype.onFulfill = function (fn) {
if (!fn) return this;
if ('function' != typeof fn) throw new TypeError("fn should be a function");
return this.on(Promise.SUCCESS, fn);
};
Promise.prototype.hasRejectListeners = function () {
return this.emitter.listeners(Promise.FAILURE).length > 0;
};
/**
* Adds a listener to the FAILURE event.
*
* @return {Promise} this
* @api public
*/
Promise.prototype.onReject = function (fn) {
if (!fn) return this;
if ('function' != typeof fn) throw new TypeError("fn should be a function");
return this.on(Promise.FAILURE, fn);
};
/**
* Adds a single function as a listener to both SUCCESS and FAILURE.
*
* It will be executed with traditional node.js argument position:
* function (err, args...) {}
*
* Also marks the promise as `end`ed, since it's the common use-case, and yet has no
* side effects unless `fn` is undefined or null.
*
* @param {Function} fn
* @return {Promise} this
*/
Promise.prototype.onResolve = function (fn) {
this.end();
if (!fn) return this;
if ('function' != typeof fn) throw new TypeError("fn should be a function");
this.on(Promise.FAILURE, function (err) { fn.call(this, err); });
this.on(Promise.SUCCESS, function () { fn.apply(this, strongUnshift(null, arguments)); });
return this;
};
/**
* Creates a new promise and returns it. If `onFulfill` or
* `onReject` are passed, they are added as SUCCESS/ERROR callbacks
* to this promise after the next tick.
*
* Conforms to [promises/A+](https://github.com/promises-aplus/promises-spec) specification. Read for more detail how to use this method.
*
* ####Example:
*
* var p = new Promise;
* p.then(function (arg) {
* return arg + 1;
* }).then(function (arg) {
* throw new Error(arg + ' is an error!');
* }).then(null, function (err) {
* assert.ok(err instanceof Error);
* assert.equal('2 is an error', err.message);
* });
* p.complete(1);
*
* @see promises-A+ https://github.com/promises-aplus/promises-spec
* @param {Function} onFulfill
* @param {Function} [onReject]
* @return {Promise} newPromise
*/
Promise.prototype.then = function (onFulfill, onReject) {
var newPromise = new Promise;
if ('function' == typeof onFulfill) {
this.onFulfill(handler(newPromise, onFulfill));
} else {
this.onFulfill(newPromise.fulfill.bind(newPromise));
}
if ('function' == typeof onReject) {
this.onReject(handler(newPromise, onReject));
} else {
this.onReject(newPromise.reject.bind(newPromise));
}
return newPromise;
};
function handler(promise, fn) {
function newTickHandler() {
var pDomain = promise.emitter.domain;
if (pDomain && pDomain !== process.domain) pDomain.enter();
try {
var x = fn.apply(undefined, boundHandler.args);
} catch (err) {
promise.reject(err);
return;
}
resolve(promise, x);
}
function boundHandler() {
boundHandler.args = arguments;
process.nextTick(newTickHandler);
}
return boundHandler;
}
function resolve(promise, x) {
function fulfillOnce() {
if (done++) return;
resolve.apply(undefined, strongUnshift(promise, arguments));
}
function rejectOnce(reason) {
if (done++) return;
promise.reject(reason);
}
if (promise === x) {
promise.reject(new TypeError("promise and x are the same"));
return;
}
var rest = toArray(arguments, 1);
var type = typeof x;
if ('undefined' == type || null == x || !('object' == type || 'function' == type)) {
promise.fulfill.apply(promise, rest);
return;
}
try {
var theThen = x.then;
} catch (err) {
promise.reject(err);
return;
}
if ('function' != typeof theThen) {
promise.fulfill.apply(promise, rest);
return;
}
var done = 0;
try {
var ret = theThen.call(x, fulfillOnce, rejectOnce);
return ret;
} catch (err) {
if (done++) return;
promise.reject(err);
}
}
/**
* Signifies that this promise was the last in a chain of `then()s`: if a handler passed to the call to `then` which produced this promise throws, the exception will go uncaught.
*
* ####Example:
*
* var p = new Promise;
* p.then(function(){ throw new Error('shucks') });
* setTimeout(function () {
* p.fulfill();
* // error was caught and swallowed by the promise returned from
* // p.then(). we either have to always register handlers on
* // the returned promises or we can do the following...
* }, 10);
*
* // this time we use .end() which prevents catching thrown errors
* var p = new Promise;
* var p2 = p.then(function(){ throw new Error('shucks') }).end(); // <--
* setTimeout(function () {
* p.fulfill(); // throws "shucks"
* }, 10);
*
* @api public
* @param {Function} [onReject]
* @return {Promise} this
*/
Promise.prototype.end = function (onReject) {
this.onReject(onReject);
this.ended = true;
return this;
};
/**
* A debug utility function that adds handlers to a promise that will log some output to the `console`
*
* ####Example:
*
* var p = new Promise;
* p.then(function(){ throw new Error('shucks') });
* setTimeout(function () {
* p.fulfill();
* // error was caught and swallowed by the promise returned from
* // p.then(). we either have to always register handlers on
* // the returned promises or we can do the following...
* }, 10);
*
* // this time we use .end() which prevents catching thrown errors
* var p = new Promise;
* var p2 = p.then(function(){ throw new Error('shucks') }).end(); // <--
* setTimeout(function () {
* p.fulfill(); // throws "shucks"
* }, 10);
*
* @api public
* @param {Promise} p
* @param {String} name
* @return {Promise} this
*/
Promise.trace = function (p, name) {
p.then(
function () {
console.log("%s fulfill %j", name, toArray(arguments));
},
function () {
console.log("%s reject %j", name, toArray(arguments));
}
)
};
Promise.prototype.chain = function (p2) {
var p1 = this;
p1.onFulfill(p2.fulfill.bind(p2));
p1.onReject(p2.reject.bind(p2));
return p2;
};
Promise.prototype.all = function (promiseOfArr) {
var pRet = new Promise;
this.then(promiseOfArr).then(
function (promiseArr) {
var count = 0;
var ret = [];
var errSentinel;
if (!promiseArr.length) pRet.resolve();
promiseArr.forEach(function (promise, index) {
if (errSentinel) return;
count++;
promise.then(
function (val) {
if (errSentinel) return;
ret[index] = val;
--count;
if (count == 0) pRet.fulfill(ret);
},
function (err) {
if (errSentinel) return;
errSentinel = err;
pRet.reject(err);
}
);
});
return pRet;
}
, pRet.reject.bind(pRet)
);
return pRet;
};
Promise.hook = function (arr) {
var p1 = new Promise;
var pFinal = new Promise;
var signalP = function () {
--count;
if (count == 0)
pFinal.fulfill();
return pFinal;
};
var count = 1;
var ps = p1;
arr.forEach(function (hook) {
ps = ps.then(
function () {
var p = new Promise;
count++;
hook(p.resolve.bind(p), signalP);
return p;
}
)
});
ps = ps.then(signalP);
p1.resolve();
return ps;
};
/* This is for the A+ tests, but it's very useful as well */
Promise.fulfilled = function fulfilled() { var p = new Promise; p.fulfill.apply(p, arguments); return p; };
Promise.rejected = function rejected(reason) { return new Promise().reject(reason); };
Promise.deferred = function deferred() {
var p = new Promise;
return {
promise: p,
reject: p.reject.bind(p),
resolve: p.fulfill.bind(p),
callback: p.resolve.bind(p)
}
};
/* End A+ tests adapter bit */

87
node_modules/mpromise/package.json generated vendored Normal file
View File

@@ -0,0 +1,87 @@
{
"_args": [
[
"mpromise@0.5.4",
"/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/mongoose"
]
],
"_from": "mpromise@0.5.4",
"_id": "mpromise@0.5.4",
"_inCache": true,
"_installable": true,
"_location": "/mpromise",
"_npmUser": {
"email": "refael@empeeric.com",
"name": "refack"
},
"_npmVersion": "1.3.26",
"_phantomChildren": {},
"_requested": {
"name": "mpromise",
"raw": "mpromise@0.5.4",
"rawSpec": "0.5.4",
"scope": null,
"spec": "0.5.4",
"type": "version"
},
"_requiredBy": [
"/mongoose"
],
"_resolved": "https://registry.npmjs.org/mpromise/-/mpromise-0.5.4.tgz",
"_shasum": "b610613ec6de37419f944b35f0783b4de9f5dc75",
"_shrinkwrap": null,
"_spec": "mpromise@0.5.4",
"_where": "/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/mongoose",
"author": {
"email": "aaron.heckmann+github@gmail.com",
"name": "Aaron Heckmann"
},
"bugs": {
"url": "https://github.com/aheckmann/mpromise/issues"
},
"dependencies": {},
"description": "Promises A+ conformant implementation",
"devDependencies": {
"mocha": "1.17.1",
"promises-aplus-tests": "2.0.3"
},
"directories": {},
"dist": {
"shasum": "b610613ec6de37419f944b35f0783b4de9f5dc75",
"tarball": "http://registry.npmjs.org/mpromise/-/mpromise-0.5.4.tgz"
},
"homepage": "https://github.com/aheckmann/mpromise",
"keywords": [
"a+",
"aplus",
"mongoose",
"plus",
"promise"
],
"license": "MIT",
"main": "lib/promise.js",
"maintainers": [
{
"name": "aaron",
"email": "aaron.heckmann+github@gmail.com"
},
{
"name": "refack",
"email": "refael@empeeric.com"
}
],
"name": "mpromise",
"optionalDependencies": {},
"publishConfig": {
"tag": "beta"
},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git://github.com/aheckmann/mpromise.git"
},
"scripts": {
"test": "mocha"
},
"version": "0.5.4"
}

28
node_modules/mpromise/test/promise.domain.test.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
var Promise = require('../')
, Domain = require('domain').Domain
, assert = require('assert');
describe("domains", function () {
it("exceptions should not breakout of domain boundaries", function (done) {
if (process.version.indexOf('v0.10') != 0) return done();
var d = new Domain;
d.on('error', function (err) {
assert.equal(err.message, 'gaga');
done()
});
var p = new Promise();
d.run(function () {
p.then(
function () {}
).then(
function () { throw new Error('gaga'); }
).end();
});
process.nextTick(function () {
p.fulfill();
});
});
});

554
node_modules/mpromise/test/promise.test.js generated vendored Normal file
View File

@@ -0,0 +1,554 @@
/*global describe,it */
/**
* Module dependencies.
*/
var assert = require('assert');
var Promise = require('../');
/**
* Test.
*/
describe('promise', function () {
it('events fire right after fulfill()', function (done) {
var promise = new Promise()
, called = 0;
promise.on('fulfill', function (a, b) {
assert.equal(a, '1');
assert.equal(b, '2');
called++;
});
promise.fulfill('1', '2');
promise.on('fulfill', function (a, b) {
assert.equal(a, '1');
assert.equal(b, '2');
called++;
});
assert.equal(2, called);
done();
});
it('events fire right after reject()', function (done) {
var promise = new Promise()
, called = 0;
promise.on('reject', function (err) {
assert.ok(err instanceof Error);
called++;
});
promise.reject(new Error('booyah'));
promise.on('reject', function (err) {
assert.ok(err instanceof Error);
called++;
});
assert.equal(2, called);
done()
});
describe('onResolve()', function () {
it('from constructor works', function (done) {
var called = 0;
var promise = new Promise(function (err) {
assert.ok(err instanceof Error);
called++;
});
promise.reject(new Error('dawg'));
assert.equal(1, called);
done();
});
it('after fulfill()', function (done) {
var promise = new Promise()
, called = 0;
promise.fulfill('woot');
promise.onResolve(function (err, data) {
assert.equal(data, 'woot');
called++;
});
promise.onResolve(function (err) {
assert.strictEqual(err, null);
called++;
});
assert.equal(2, called);
done();
})
});
describe('onFulfill shortcut', function () {
it('works', function (done) {
var promise = new Promise()
, called = 0;
promise.onFulfill(function (woot) {
assert.strictEqual(woot, undefined);
called++;
});
promise.fulfill();
assert.equal(1, called);
done();
});
});
describe('onReject shortcut', function () {
it('works', function (done) {
var promise = new Promise()
, called = 0;
promise.onReject(function (err) {
assert.ok(err instanceof Error);
called++;
});
promise.reject(new Error);
assert.equal(1, called);
done();
})
});
describe('return values', function () {
it('on()', function (done) {
var promise = new Promise();
assert.ok(promise.on('jump', function () {}) instanceof Promise);
done()
});
it('onFulfill()', function (done) {
var promise = new Promise();
assert.ok(promise.onFulfill(function () {}) instanceof Promise);
done();
});
it('onReject()', function (done) {
var promise = new Promise();
assert.ok(promise.onReject(function () {}) instanceof Promise);
done();
});
it('onResolve()', function (done) {
var promise = new Promise();
assert.ok(promise.onResolve(function () {}) instanceof Promise);
done();
})
});
describe('casting errors', function () {
describe('reject()', function () {
it('does not cast arguments to Error', function (done) {
var p = new Promise(function (err) {
assert.equal(3, err);
done();
});
p.reject(3);
})
})
});
describe('then', function () {
describe('catching', function () {
it('should not catch returned promise fulfillments', function (done) {
var errorSentinal
, p = new Promise;
p.then(function () { throw errorSentinal = new Error("boo!") });
p.fulfill();
done();
});
it('should not catch returned promise fulfillments even async', function (done) {
var errorSentinal
, p = new Promise;
p.then(function () { throw errorSentinal = new Error("boo!") });
setTimeout(function () {
p.fulfill();
done();
}, 10);
});
it('can be disabled using .end()', function (done) {
if (process.version.indexOf('v0.8') == 0) return done();
var errorSentinal
, overTimeout
, domain = require('domain').create();
domain.once('error', function (err) {
assert(err, errorSentinal);
clearTimeout(overTimeout);
done()
});
domain.run(function () {
var p = new Promise;
var p2 = p.then(function () {
throw errorSentinal = new Error('shucks')
});
p2.end();
p.fulfill();
});
overTimeout = setTimeout(function () { done(new Error('error was swallowed')); }, 10);
});
it('can be disabled using .end() even when async', function (done) {
if (process.version.indexOf('v0.10') != 0) return done();
var errorSentinal
, overTimeout
, domain = require('domain').create();
domain.on('error', function (err) {
assert(err, errorSentinal);
clearTimeout(overTimeout);
done()
});
domain.run(function () {
var p = new Promise;
var p2 = p.then(function () {
throw errorSentinal = new Error("boo!")
});
p2.end();
setTimeout(function () {p.fulfill();}, 10);
});
overTimeout = setTimeout(function () { done(new Error('error was swallowed')); }, 20);
});
it('can be handled using .end() so no throwing', function (done) {
var errorSentinal
, overTimeout
, domain = require('domain').create();
domain.run(function () {
var p = new Promise;
var p2 = p.then(function () {
throw errorSentinal = new Error("boo!")
});
p2.end(function (err) {
assert.equal(err, errorSentinal);
clearTimeout(overTimeout);
done()
});
setTimeout(function () {p.fulfill();}, 10);
});
overTimeout = setTimeout(function () { done(new Error('error was swallowed')); }, 20);
});
});
it('persistent', function (done) {
var p = new Promise;
v = null;
function ensure(val) {
v = v || val;
assert.equal(v, val);
}
function guard() {
throw new Error('onReject should not be called');
}
p.then(ensure, guard).end();
p.fulfill('foo');
p.fulfill('bar');
p.reject(new Error('baz'));
p.then(ensure, guard).end();
setTimeout(done, 0);
});
it('accepts multiple completion values', function (done) {
var p = new Promise;
p.then(function (a, b) {
assert.equal(2, arguments.length);
assert.equal('hi', a);
assert.equal(4, b);
done();
}, done).end();
p.fulfill('hi', 4);
})
});
describe('fulfill values and splats', function () {
it('should handle multiple values', function (done) {
var p = new Promise;
p.onFulfill(function (a, b, c) {
assert.equal('a', a);
assert.equal('b', b);
assert.equal('c', c);
done();
});
p.fulfill('a', 'b', 'c');
});
it('should handle multiple values from a then', function (done) {
Promise.fulfilled().then(
function () {
return Promise.fulfilled().then(
function () {
var p = new Promise;
p.fulfill('a', 'b', 'c');
return p;
}
);
}
).onFulfill(
function (a, b, c) {
assert.equal('a', a);
assert.equal('b', b);
assert.equal('c', c);
done();
}
).end()
});
it('should work with `fulfilled` convenience method', function (done) {
Promise.fulfilled('a', 'b', 'c').then(function (a, b, c) {
assert.equal('a', a);
assert.equal('b', b);
assert.equal('c', c);
done();
})
});
});
describe('end', function () {
it("should return the promise", function (done) {
var p = new Promise;
var p1 = p.end();
assert.equal(p, p1);
done();
});
it("should throw for chain", function (done) {
var p = new Promise;
p.then().then().then().then().end();
try {
p.reject('bad');
} catch (e) {
done();
}
});
it("should not throw for chain with reject handler", function (done) {
var p = new Promise;
p.then().then().then().then().end(function () {
done();
});
try {
p.reject('bad');
} catch (e) {
done(e);
}
});
});
describe('chain', function () {
it('should propagate fulfillment', function (done) {
var varSentinel = {a: 'a'};
var p1 = new Promise;
p1.chain(new Promise(function (err, doc) {
assert.equal(doc, varSentinel);
done();
}));
p1.fulfill(varSentinel);
});
it('should propagate rejection', function (done) {
var e = new Error("gaga");
var p1 = new Promise;
p1.chain(new Promise(function (err) {
assert.equal(err, e);
done();
}));
p1.reject(e);
});
it('should propagate resolution err', function (done) {
var e = new Error("gaga");
var p1 = new Promise;
p1.chain(new Promise(function (err) {
assert.equal(err, e);
done();
}));
p1.resolve(e);
});
it('should propagate resolution val', function (done) {
var varSentinel = {a: 'a'};
var p1 = new Promise;
p1.chain(new Promise(function (err, val) {
assert.equal(val, varSentinel);
done();
}));
p1.resolve(null, varSentinel);
})
});
describe("all", function () {
it("works", function (done) {
var count = 0;
var p = new Promise;
var p2 = p.all(function () {
return [
(function () {
var p = new Promise();
count++;
p.resolve();
return p;
})()
, (function () {
var p = new Promise();
count++;
p.resolve();
return p;
})()
];
});
p2.then(function () {
assert.equal(count, 2);
done();
});
p.resolve();
});
it("handles rejects", function (done) {
var count = 0;
var p = new Promise;
var p2 = p.all(function () {
return [
(function () {
var p = new Promise();
count++;
p.resolve();
return p;
})()
, (function () {
count++;
throw new Error("gaga");
})()
];
});
p2.onReject(function (err) {
assert(err.message, "gaga");
assert.equal(count, 2);
done();
});
p.resolve();
});
});
describe("deferred", function () {
it("works", function (done) {
var d = Promise.deferred();
assert.ok(d.promise instanceof Promise);
assert.ok(d.reject instanceof Function);
assert.ok(d.resolve instanceof Function);
assert.ok(d.callback instanceof Function);
done();
});
});
describe("hook", function () {
it("works", function (done) {
var run = 0;
var l1 = function (ser, par) {
run++;
ser();
par();
};
Promise.hook([l1, l1, l1]).then(function () {
assert(run, 3);
done();
})
});
it("works with async serial hooks", function (done) {
this.timeout(800);
var run = 0;
var l1 = function (ser, par) {
run++;
setTimeout(function () {ser();}, 200);
par();
};
Promise.hook([l1, l1, l1]).then(function () {
assert(run, 3);
done();
})
});
it("works with async parallel hooks", function (done) {
this.timeout(400);
var run = 0;
var l1 = function (ser, par) {
run++;
ser();
setTimeout(function () {par();}, 200);
};
Promise.hook([l1, l1, l1]).then(function () {
assert(run, 3);
done();
})
});
it("catches errors in hook logic", function (done) {
var run = 0;
var l1 = function (ser, par) {
run++;
ser();
par();
};
var l2 = function (ser, par) {
run++;
ser();
par();
throw new Error("err")
};
Promise.hook([l1, l2, l1]).end(function (err) {
assert(run, 2);
done();
});
});
});
});

15
node_modules/mpromise/test/promises.Aplus.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
/**
* Module dependencies.
*/
var Promise = require('../lib/promise');
var aplus = require('promises-aplus-tests');
// tests
describe("run A+ suite", function () {
aplus.mocha({
fulfilled: Promise.fulfilled,
rejected: Promise.rejected,
deferred: Promise.deferred
});
});