pax_global_header00006660000000000000000000000064127136256510014522gustar00rootroot0000000000000052 comment=01ac9a31ce8a1896c3b12334c74a6c390a85dddb any-promise-1.3.0/000077500000000000000000000000001271362565100137665ustar00rootroot00000000000000any-promise-1.3.0/.gitignore000066400000000000000000000000311271362565100157500ustar00rootroot00000000000000node_modules build *.swp any-promise-1.3.0/.jshintrc000066400000000000000000000000431271362565100156100ustar00rootroot00000000000000{ "node":true, "strict":true } any-promise-1.3.0/.npmignore000066400000000000000000000000741271362565100157660ustar00rootroot00000000000000.git* test/ test-browser/ build/ .travis.yml *.swp Makefile any-promise-1.3.0/.travis.yml000066400000000000000000000001251271362565100160750ustar00rootroot00000000000000language: node_js sudo: false node_js: - "0.10" - "0.12" - "4" - "5" - "6" any-promise-1.3.0/LICENSE000066400000000000000000000020441271362565100147730ustar00rootroot00000000000000Copyright (C) 2014-2016 Kevin Beaty 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. any-promise-1.3.0/Makefile000066400000000000000000000006741271362565100154350ustar00rootroot00000000000000PROJECT:=any-promise JS_TARGET ?= build/$(PROJECT).js .PHONY: all clean js test serve all: test js clean: rm -rf build test: | node_modules npm test node_modules: npm install %.min.js: %.js | node_modules `npm bin`/uglifyjs $< -o $@ -c -m %.gz: % gzip -c9 $^ > $@ js: $(JS_TARGET) $(JS_TARGET:.js=.min.js) $(JS_TARGET): index.js register-shim.js register.js loader.js | build `npm bin`/browserify $< > $@ build: mkdir -p build any-promise-1.3.0/README.md000066400000000000000000000156321271362565100152540ustar00rootroot00000000000000## Any Promise [![Build Status](https://secure.travis-ci.org/kevinbeaty/any-promise.svg)](http://travis-ci.org/kevinbeaty/any-promise) Let your library support any ES 2015 (ES6) compatible `Promise` and leave the choice to application authors. The application can *optionally* register its preferred `Promise` implementation and it will be exported when requiring `any-promise` from library code. If no preference is registered, defaults to the global `Promise` for newer Node.js versions. The browser version defaults to the window `Promise`, so polyfill or register as necessary. ### Usage with global Promise: Assuming the global `Promise` is the desired implementation: ```bash # Install any libraries depending on any-promise $ npm install mz ``` The installed libraries will use global Promise by default. ```js // in library var Promise = require('any-promise') // the global Promise function promiseReturningFunction(){ return new Promise(function(resolve, reject){...}) } ``` ### Usage with registration: Assuming `bluebird` is the desired Promise implementation: ```bash # Install preferred promise library $ npm install bluebird # Install any-promise to allow registration $ npm install any-promise # Install any libraries you would like to use depending on any-promise $ npm install mz ``` Register your preference in the application entry point before any other `require` of packages that load `any-promise`: ```javascript // top of application index.js or other entry point require('any-promise/register/bluebird') // -or- Equivalent to above, but allows customization of Promise library require('any-promise/register')('bluebird', {Promise: require('bluebird')}) ``` Now that the implementation is registered, you can use any package depending on `any-promise`: ```javascript var fsp = require('mz/fs') // mz/fs will use registered bluebird promises var Promise = require('any-promise') // the registered bluebird promise ``` It is safe to call `register` multiple times, but it must always be with the same implementation. Again, registration is *optional*. It should only be called by the application user if overriding the global `Promise` implementation is desired. ### Optional Application Registration As an application author, you can *optionally* register a preferred `Promise` implementation on application startup (before any call to `require('any-promise')`: You must register your preference before any call to `require('any-promise')` (by you or required packages), and only one implementation can be registered. Typically, this registration would occur at the top of the application entry point. #### Registration shortcuts If you are using a known `Promise` implementation, you can register your preference with a shortcut: ```js require('any-promise/register/bluebird') // -or- import 'any-promise/register/q'; ``` Shortcut registration is the preferred registration method as it works in the browser and Node.js. It is also convenient for using with `import` and many test runners, that offer a `--require` flag: ``` $ ava --require=any-promise/register/bluebird test.js ``` Current known implementations include `bluebird`, `q`, `when`, `rsvp`, `es6-promise`, `promise`, `native-promise-only`, `pinkie`, `vow` and `lie`. If you are not using a known implementation, you can use another registration method described below. #### Basic Registration As an alternative to registration shortcuts, you can call the `register` function with the preferred `Promise` implementation. The benefit of this approach is that a `Promise` library can be required by name without being a known implementation. This approach does NOT work in the browser. To use `any-promise` in the browser use either registration shortcuts or specify the `Promise` constructor using advanced registration (see below). ```javascript require('any-promise/register')('when') // -or- require('any-promise/register')('any other ES6 compatible library (known or otherwise)') ``` This registration method will try to detect the `Promise` constructor from requiring the specified implementation. If you would like to specify your own constructor, see advanced registration. #### Advanced Registration To use the browser version, you should either install a polyfill or explicitly register the `Promise` constructor: ```javascript require('any-promise/register')('bluebird', {Promise: require('bluebird')}) ``` This could also be used for registering a custom `Promise` implementation or subclass. Your preference will be registered globally, allowing a single registration even if multiple versions of `any-promise` are installed in the NPM dependency tree or are using multiple bundled JavaScript files in the browser. You can bypass this global registration in options: ```javascript require('../register')('es6-promise', {Promise: require('es6-promise').Promise, global: false}) ``` ### Library Usage To use any `Promise` constructor, simply require it: ```javascript var Promise = require('any-promise'); return Promise .all([xf, f, init, coll]) .then(fn); return new Promise(function(resolve, reject){ try { resolve(item); } catch(e){ reject(e); } }); ``` Except noted below, libraries using `any-promise` should only use [documented](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) functions as there is no guarantee which implementation will be chosen by the application author. Libraries should never call `register`, only the application user should call if desired. #### Advanced Library Usage If your library needs to branch code based on the registered implementation, you can retrieve it using `var impl = require('any-promise/implementation')`, where `impl` will be the package name (`"bluebird"`, `"when"`, etc.) if registered, `"global.Promise"` if using the global version on Node.js, or `"window.Promise"` if using the browser version. You should always include a default case, as there is no guarantee what package may be registered. ### Support for old Node.js versions Node.js versions prior to `v0.12` may have contained buggy versions of the global `Promise`. For this reason, the global `Promise` is not loaded automatically for these old versions. If using `any-promise` in Node.js versions versions `<= v0.12`, the user should register a desired implementation. If an implementation is not registered, `any-promise` will attempt to discover an installed `Promise` implementation. If no implementation can be found, an error will be thrown on `require('any-promise')`. While the auto-discovery usually avoids errors, it is non-deterministic. It is recommended that the user always register a preferred implementation for older Node.js versions. This auto-discovery is only available for Node.jS versions prior to `v0.12`. Any newer versions will always default to the global `Promise` implementation. ### Related - [any-observable](https://github.com/sindresorhus/any-observable) - `any-promise` for Observables. any-promise-1.3.0/implementation.d.ts000066400000000000000000000000761271362565100176100ustar00rootroot00000000000000declare var implementation: string; export = implementation; any-promise-1.3.0/implementation.js000066400000000000000000000000701271362565100173460ustar00rootroot00000000000000module.exports = require('./register')().implementation any-promise-1.3.0/index.d.ts000066400000000000000000000123501271362565100156700ustar00rootroot00000000000000declare class Promise implements Promise.Thenable { /** * If you call resolve in the body of the callback passed to the constructor, * your promise is fulfilled with result object passed to resolve. * If you call reject your promise is rejected with the object passed to resolve. * For consistency and debugging (eg stack traces), obj should be an instanceof Error. * Any errors thrown in the constructor callback will be implicitly passed to reject(). */ constructor (callback: (resolve : (value?: R | Promise.Thenable) => void, reject: (error?: any) => void) => void); /** * onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. * Both callbacks have a single parameter , the fulfillment value or rejection reason. * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. * If an error is thrown in the callback, the returned promise rejects with that error. * * @param onFulfilled called when/if "promise" resolves * @param onRejected called when/if "promise" rejects */ then (onFulfilled?: (value: R) => U | Promise.Thenable, onRejected?: (error: any) => U | Promise.Thenable): Promise; then (onFulfilled?: (value: R) => U | Promise.Thenable, onRejected?: (error: any) => void): Promise; /** * Sugar for promise.then(undefined, onRejected) * * @param onRejected called when/if "promise" rejects */ catch (onRejected?: (error: any) => U | Promise.Thenable): Promise; /** * Make a new promise from the thenable. * A thenable is promise-like in as far as it has a "then" method. */ static resolve (): Promise; static resolve (value: R | Promise.Thenable): Promise; /** * Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error */ static reject (error: any): Promise; /** * Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects. * the array passed to all can be a mixture of promise-like objects and other objects. * The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value. */ static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable, T3 | Promise.Thenable, T4 | Promise.Thenable , T5 | Promise.Thenable, T6 | Promise.Thenable, T7 | Promise.Thenable, T8 | Promise.Thenable, T9 | Promise.Thenable, T10 | Promise.Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable, T3 | Promise.Thenable, T4 | Promise.Thenable , T5 | Promise.Thenable, T6 | Promise.Thenable, T7 | Promise.Thenable, T8 | Promise.Thenable, T9 | Promise.Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable, T3 | Promise.Thenable, T4 | Promise.Thenable , T5 | Promise.Thenable, T6 | Promise.Thenable, T7 | Promise.Thenable, T8 | Promise.Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable, T3 | Promise.Thenable, T4 | Promise.Thenable , T5 | Promise.Thenable, T6 | Promise.Thenable, T7 | Promise.Thenable]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable, T3 | Promise.Thenable, T4 | Promise.Thenable , T5 | Promise.Thenable, T6 | Promise.Thenable]): Promise<[T1, T2, T3, T4, T5, T6]>; static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable, T3 | Promise.Thenable, T4 | Promise.Thenable , T5 | Promise.Thenable]): Promise<[T1, T2, T3, T4, T5]>; static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable, T3 | Promise.Thenable, T4 | Promise.Thenable ]): Promise<[T1, T2, T3, T4]>; static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable, T3 | Promise.Thenable]): Promise<[T1, T2, T3]>; static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable]): Promise<[T1, T2]>; static all (values: [T1 | Promise.Thenable]): Promise<[T1]>; static all (values: Array>): Promise; /** * Make a Promise that fulfills when any item fulfills, and rejects if any item rejects. */ static race (promises: (R | Promise.Thenable)[]): Promise; } declare namespace Promise { export interface Thenable { then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Thenable; then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => void): Thenable; } } export = Promise; any-promise-1.3.0/index.js000066400000000000000000000000611271362565100154300ustar00rootroot00000000000000module.exports = require('./register')().Promise any-promise-1.3.0/loader.js000066400000000000000000000050251271362565100155740ustar00rootroot00000000000000"use strict" // global key for user preferred registration var REGISTRATION_KEY = '@@any-promise/REGISTRATION', // Prior registration (preferred or detected) registered = null /** * Registers the given implementation. An implementation must * be registered prior to any call to `require("any-promise")`, * typically on application load. * * If called with no arguments, will return registration in * following priority: * * For Node.js: * * 1. Previous registration * 2. global.Promise if node.js version >= 0.12 * 3. Auto detected promise based on first sucessful require of * known promise libraries. Note this is a last resort, as the * loaded library is non-deterministic. node.js >= 0.12 will * always use global.Promise over this priority list. * 4. Throws error. * * For Browser: * * 1. Previous registration * 2. window.Promise * 3. Throws error. * * Options: * * Promise: Desired Promise constructor * global: Boolean - Should the registration be cached in a global variable to * allow cross dependency/bundle registration? (default true) */ module.exports = function(root, loadImplementation){ return function register(implementation, opts){ implementation = implementation || null opts = opts || {} // global registration unless explicitly {global: false} in options (default true) var registerGlobal = opts.global !== false; // load any previous global registration if(registered === null && registerGlobal){ registered = root[REGISTRATION_KEY] || null } if(registered !== null && implementation !== null && registered.implementation !== implementation){ // Throw error if attempting to redefine implementation throw new Error('any-promise already defined as "'+registered.implementation+ '". You can only register an implementation before the first '+ ' call to require("any-promise") and an implementation cannot be changed') } if(registered === null){ // use provided implementation if(implementation !== null && typeof opts.Promise !== 'undefined'){ registered = { Promise: opts.Promise, implementation: implementation } } else { // require implementation if implementation is specified but not provided registered = loadImplementation(implementation) } if(registerGlobal){ // register preference globally in case multiple installations root[REGISTRATION_KEY] = registered } } return registered } } any-promise-1.3.0/package.json000066400000000000000000000017711271362565100162620ustar00rootroot00000000000000{ "name": "any-promise", "version": "1.3.0", "description": "Resolve any installed ES6 compatible promise", "main": "index.js", "typings": "index.d.ts", "browser": { "./register.js": "./register-shim.js" }, "scripts": { "test": "ava" }, "repository": { "type": "git", "url": "https://github.com/kevinbeaty/any-promise" }, "keywords": [ "promise", "es6" ], "author": "Kevin Beaty", "license": "MIT", "bugs": { "url": "https://github.com/kevinbeaty/any-promise/issues" }, "homepage": "http://github.com/kevinbeaty/any-promise", "dependencies": {}, "devDependencies": { "ava": "^0.14.0", "bluebird": "^3.0.0", "es6-promise": "^3.0.0", "is-promise": "^2.0.0", "lie": "^3.0.0", "mocha": "^2.0.0", "native-promise-only": "^0.8.0", "phantomjs-prebuilt": "^2.0.0", "pinkie": "^2.0.0", "promise": "^7.0.0", "q": "^1.0.0", "rsvp": "^3.0.0", "vow": "^0.4.0", "when": "^3.0.0", "zuul": "^3.0.0" } } any-promise-1.3.0/register-shim.js000066400000000000000000000010411271362565100171020ustar00rootroot00000000000000"use strict"; module.exports = require('./loader')(window, loadImplementation) /** * Browser specific loadImplementation. Always uses `window.Promise` * * To register a custom implementation, must register with `Promise` option. */ function loadImplementation(){ if(typeof window.Promise === 'undefined'){ throw new Error("any-promise browser requires a polyfill or explicit registration"+ " e.g: require('any-promise/register/bluebird')") } return { Promise: window.Promise, implementation: 'window.Promise' } } any-promise-1.3.0/register.d.ts000066400000000000000000000005521271362565100164060ustar00rootroot00000000000000import Promise = require('./index'); declare function register (module?: string, options?: register.Options): register.Register; declare namespace register { export interface Register { Promise: typeof Promise; implementation: string; } export interface Options { Promise?: typeof Promise; global?: boolean } } export = register; any-promise-1.3.0/register.js000066400000000000000000000055361271362565100161610ustar00rootroot00000000000000"use strict" module.exports = require('./loader')(global, loadImplementation); /** * Node.js version of loadImplementation. * * Requires the given implementation and returns the registration * containing {Promise, implementation} * * If implementation is undefined or global.Promise, loads it * Otherwise uses require */ function loadImplementation(implementation){ var impl = null if(shouldPreferGlobalPromise(implementation)){ // if no implementation or env specified use global.Promise impl = { Promise: global.Promise, implementation: 'global.Promise' } } else if(implementation){ // if implementation specified, require it var lib = require(implementation) impl = { Promise: lib.Promise || lib, implementation: implementation } } else { // try to auto detect implementation. This is non-deterministic // and should prefer other branches, but this is our last chance // to load something without throwing error impl = tryAutoDetect() } if(impl === null){ throw new Error('Cannot find any-promise implementation nor'+ ' global.Promise. You must install polyfill or call'+ ' require("any-promise/register") with your preferred'+ ' implementation, e.g. require("any-promise/register/bluebird")'+ ' on application load prior to any require("any-promise").') } return impl } /** * Determines if the global.Promise should be preferred if an implementation * has not been registered. */ function shouldPreferGlobalPromise(implementation){ if(implementation){ return implementation === 'global.Promise' } else if(typeof global.Promise !== 'undefined'){ // Load global promise if implementation not specified // Versions < 0.11 did not have global Promise // Do not use for version < 0.12 as version 0.11 contained buggy versions var version = (/v(\d+)\.(\d+)\.(\d+)/).exec(process.version) return !(version && +version[1] == 0 && +version[2] < 12) } // do not have global.Promise or another implementation was specified return false } /** * Look for common libs as last resort there is no guarantee that * this will return a desired implementation or even be deterministic. * The priority is also nearly arbitrary. We are only doing this * for older versions of Node.js <0.12 that do not have a reasonable * global.Promise implementation and we the user has not registered * the preference. This preserves the behavior of any-promise <= 0.1 * and may be deprecated or removed in the future */ function tryAutoDetect(){ var libs = [ "es6-promise", "promise", "native-promise-only", "bluebird", "rsvp", "when", "q", "pinkie", "lie", "vow"] var i = 0, len = libs.length for(; i < len; i++){ try { return loadImplementation(libs[i]) } catch(e){} } return null } any-promise-1.3.0/register/000077500000000000000000000000001271362565100156125ustar00rootroot00000000000000any-promise-1.3.0/register/bluebird.d.ts000066400000000000000000000000121271362565100201650ustar00rootroot00000000000000export {} any-promise-1.3.0/register/bluebird.js000066400000000000000000000001211271362565100177320ustar00rootroot00000000000000'use strict'; require('../register')('bluebird', {Promise: require('bluebird')}) any-promise-1.3.0/register/es6-promise.d.ts000066400000000000000000000000121271362565100205460ustar00rootroot00000000000000export {} any-promise-1.3.0/register/es6-promise.js000066400000000000000000000001371271362565100203220ustar00rootroot00000000000000'use strict'; require('../register')('es6-promise', {Promise: require('es6-promise').Promise}) any-promise-1.3.0/register/lie.d.ts000066400000000000000000000000121271362565100171460ustar00rootroot00000000000000export {} any-promise-1.3.0/register/lie.js000066400000000000000000000001071271362565100167170ustar00rootroot00000000000000'use strict'; require('../register')('lie', {Promise: require('lie')}) any-promise-1.3.0/register/native-promise-only.d.ts000066400000000000000000000000121271362565100223160ustar00rootroot00000000000000export {} any-promise-1.3.0/register/native-promise-only.js000066400000000000000000000001471271362565100220730ustar00rootroot00000000000000'use strict'; require('../register')('native-promise-only', {Promise: require('native-promise-only')}) any-promise-1.3.0/register/pinkie.d.ts000066400000000000000000000000121271362565100176540ustar00rootroot00000000000000export {} any-promise-1.3.0/register/pinkie.js000066400000000000000000000001151271362565100174240ustar00rootroot00000000000000'use strict'; require('../register')('pinkie', {Promise: require('pinkie')}) any-promise-1.3.0/register/promise.d.ts000066400000000000000000000000121271362565100200530ustar00rootroot00000000000000export {} any-promise-1.3.0/register/promise.js000066400000000000000000000001171271362565100176250ustar00rootroot00000000000000'use strict'; require('../register')('promise', {Promise: require('promise')}) any-promise-1.3.0/register/q.d.ts000066400000000000000000000000121271362565100166350ustar00rootroot00000000000000export {} any-promise-1.3.0/register/q.js000066400000000000000000000001131271362565100164030ustar00rootroot00000000000000'use strict'; require('../register')('q', {Promise: require('q').Promise}) any-promise-1.3.0/register/rsvp.d.ts000066400000000000000000000000121271362565100173670ustar00rootroot00000000000000export {} any-promise-1.3.0/register/rsvp.js000066400000000000000000000001211271362565100171340ustar00rootroot00000000000000'use strict'; require('../register')('rsvp', {Promise: require('rsvp').Promise}) any-promise-1.3.0/register/vow.d.ts000066400000000000000000000000121271362565100172100ustar00rootroot00000000000000export {} any-promise-1.3.0/register/vow.js000066400000000000000000000001171271362565100167620ustar00rootroot00000000000000'use strict'; require('../register')('vow', {Promise: require('vow').Promise}) any-promise-1.3.0/register/when.d.ts000066400000000000000000000000121271362565100173360ustar00rootroot00000000000000export {} any-promise-1.3.0/register/when.js000066400000000000000000000001211271362565100171030ustar00rootroot00000000000000'use strict'; require('../register')('when', {Promise: require('when').Promise}) any-promise-1.3.0/test-browser/000077500000000000000000000000001271362565100164265ustar00rootroot00000000000000any-promise-1.3.0/test-browser/local.js000066400000000000000000000012121271362565100200520ustar00rootroot00000000000000'use strict'; require('../register')('es6-promise', {Promise: require('es6-promise').Promise, global: false}) var REGISTRATION_KEY = '@@any-promise/REGISTRATION' var Promise = require('..') var implementation = require('../implementation') var isPromise = require('is-promise') it('Register local test in browser', function(){ if(!isPromise(new Promise(noop))){ throw new Error('Promise not exported') } if(typeof window[REGISTRATION_KEY] !== 'undefined'){ throw new Error('Expecting local registration') } if(implementation !== 'es6-promise'){ throw new Error('Implementation not expected: '+impl) } }) function noop(){} any-promise-1.3.0/test-browser/polyfill.js000066400000000000000000000011371271362565100206200ustar00rootroot00000000000000'use strict'; require('es6-promise').polyfill() var REGISTRATION_KEY = '@@any-promise/REGISTRATION' var Promise = require('..') var implementation = require('../implementation') var isPromise = require('is-promise') it('Polyfill test in browser', function(){ if(!isPromise(new Promise(noop))){ throw new Error('Promise not exported') } if(implementation !== 'window.Promise'){ throw new Error('Expecting window.Promise as implementation') } if(window[REGISTRATION_KEY].implementation !== 'window.Promise'){ throw new Error('Expecting global registration') } }) function noop(){} any-promise-1.3.0/test-browser/register.js000066400000000000000000000011561271362565100206130ustar00rootroot00000000000000'use strict'; require('../register')('bluebird', {Promise: require('bluebird')}) var REGISTRATION_KEY = '@@any-promise/REGISTRATION' var Promise = require('..') var implementation = require('../implementation') var isPromise = require('is-promise') it('Register test in browser', function(){ if(!isPromise(new Promise(noop))){ throw new Error('Promise not exported') } if(implementation !== 'bluebird'){ throw new Error('Expecting bluebird as implementation') } if(window[REGISTRATION_KEY].implementation !== 'bluebird'){ throw new Error('Expecting global registration') } }) function noop(){} any-promise-1.3.0/test-browser/shortcut.js000066400000000000000000000011131271362565100206330ustar00rootroot00000000000000'use strict'; require('../register/bluebird') var REGISTRATION_KEY = '@@any-promise/REGISTRATION' var Promise = require('..') var implementation = require('../implementation') var isPromise = require('is-promise') it('Shortcut test in browser', function(){ if(!isPromise(new Promise(noop))){ throw new Error('Promise not exported') } if(implementation !== 'bluebird'){ throw new Error('Expecting bluebird as implementation') } if(window[REGISTRATION_KEY].implementation !== 'bluebird'){ throw new Error('Expecting global registration') } }) function noop(){} any-promise-1.3.0/test/000077500000000000000000000000001271362565100147455ustar00rootroot00000000000000any-promise-1.3.0/test/bluebird-shortcut.js000066400000000000000000000006601271362565100207460ustar00rootroot00000000000000import '../register/bluebird' var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var BluebirdPromise = require('bluebird') var isPromise = require('is-promise') test(t => { t.is(implementation, 'bluebird') t.is(Promise, BluebirdPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/bluebird.js000066400000000000000000000006641271362565100171010ustar00rootroot00000000000000require('../register')('bluebird') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var BluebirdPromise = require('bluebird') var isPromise = require('is-promise') test(t => { t.is(implementation, 'bluebird') t.is(Promise, BluebirdPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/browser.js000066400000000000000000000014531271362565100167710ustar00rootroot00000000000000var test = require('ava') var Promise = require('..') var version = (/v(\d+)\.(\d+)\.(\d+)/).exec(process.version) var {spawn} = require('child_process') if (+version[1] <= 5) { test('skipped browser tests for Node.js <= 5', () => {}) } else { ;['register', 'local', 'polyfill', 'shortcut'].forEach(filename => { test.serial('Browser test: '+filename, () => zuul(filename)) }) } function zuul(file){ return new Promise((resolve, reject) => { var zuul = spawn( 'zuul', ['--phantom', '--ui', 'mocha-bdd', '--', '../test-browser/'+file+'.js'], {stdio: 'inherit'}) zuul.on('error', (err) => reject(err)) zuul.on('close', (code, err) => { if(code !== 0){ reject('Zuul did not exit successfully '+code) } else { resolve() } }) }) } any-promise-1.3.0/test/defaults.js000066400000000000000000000012761271362565100171200ustar00rootroot00000000000000var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var isPromise = require('is-promise') test(t => { var version = (/v(\d+)\.(\d+)\.(\d+)/).exec(process.version) if(version && +version[1] == 0 && +version[2] < 12){ // Node < 0.12 should load first successful require in // priority list if not registered t.is(implementation, 'es6-promise') } else { // Node >= 0.12 should load global.Promise if not registered t.is(implementation, 'global.Promise') } t.is(Promise, global.Promise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/es6-promise-shortcut.js000066400000000000000000000006671271362565100213360ustar00rootroot00000000000000import '../register/es6-promise' var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var ES6Promise = require('es6-promise').Promise var isPromise = require('is-promise') test(t => { t.is(implementation, 'es6-promise') t.is(Promise, ES6Promise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/es6-promise.js000066400000000000000000000006731271362565100174620ustar00rootroot00000000000000require('../register')('es6-promise') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var ES6Promise = require('es6-promise').Promise var isPromise = require('is-promise') test(t => { t.is(implementation, 'es6-promise') t.is(Promise, ES6Promise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/global.js000066400000000000000000000007471271362565100165530ustar00rootroot00000000000000if(typeof global.Promise === 'undefined'){ require('es6-promise').polyfill() } require('../register')('global.Promise') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var isPromise = require('is-promise') test(t => { t.is(implementation, 'global.Promise') t.is(Promise, global.Promise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/lie-shortcut.js000066400000000000000000000006301271362565100177240ustar00rootroot00000000000000require('../register/lie') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var LiePromise = require('lie') var isPromise = require('is-promise') test(t => { t.is(implementation, 'lie') t.is(Promise, LiePromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/lie.js000066400000000000000000000006331271362565100160560ustar00rootroot00000000000000require('../register')('lie') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var LiePromise = require('lie') var isPromise = require('is-promise') test(t => { t.is(implementation, 'lie') t.is(Promise, LiePromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/native-promise-only-shortcut.js000066400000000000000000000007071271362565100231010ustar00rootroot00000000000000import '../register/native-promise-only' var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var NPOPromise = require('native-promise-only') var isPromise = require('is-promise') test(t => { t.is(implementation, 'native-promise-only') t.is(Promise, NPOPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/native-promise-only.js000066400000000000000000000007131271362565100212250ustar00rootroot00000000000000require('../register')('native-promise-only') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var NPOPromise = require('native-promise-only') var isPromise = require('is-promise') test(t => { t.is(implementation, 'native-promise-only') t.is(Promise, NPOPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/pinkie-shortcut.js000066400000000000000000000006471271362565100204420ustar00rootroot00000000000000require('../register/pinkie') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var PinkiePromise = require('pinkie') var isPromise = require('is-promise') test(t => { t.is(implementation, 'pinkie') t.is(Promise, PinkiePromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/pinkie.js000066400000000000000000000006521271362565100165650ustar00rootroot00000000000000require('../register')('pinkie') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var PinkiePromise = require('pinkie') var isPromise = require('is-promise') test(t => { t.is(implementation, 'pinkie') t.is(Promise, PinkiePromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/polyfill.js000066400000000000000000000011411271362565100171320ustar00rootroot00000000000000require('es6-promise').polyfill() var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var isPromise = require('is-promise') test(t => { // The implementation will either be global.Promise or es6-promise // depending on node version. This is a bit of a hack for this test // but works as test because es6-promise is first successfull require // and we polyfilled with es6-promise t.is(Promise, global.Promise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/promise-shortcut.js000066400000000000000000000006531271362565100206360ustar00rootroot00000000000000import '../register/promise' var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var PromisePromise = require('promise') var isPromise = require('is-promise') test(t => { t.is(implementation, 'promise') t.is(Promise, PromisePromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/promise.js000066400000000000000000000006571271362565100167710ustar00rootroot00000000000000require('../register')('promise') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var PromisePromise = require('promise') var isPromise = require('is-promise') test(t => { t.is(implementation, 'promise') t.is(Promise, PromisePromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/q-shortcut.js000066400000000000000000000006251271362565100174170ustar00rootroot00000000000000import '../register/q' var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var QPromise = require('q').Promise var isPromise = require('is-promise') test(t => { t.is(implementation, 'q') t.is(Promise, QPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/q.js000066400000000000000000000006311271362565100155430ustar00rootroot00000000000000require('../register')('q') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var QPromise = require('q').Promise var isPromise = require('is-promise') test(t => { t.is(implementation, 'q') t.is(Promise, QPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/register-local.js000066400000000000000000000006651271362565100202260ustar00rootroot00000000000000require('../register')('bluebird', {global: false}) var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var BluebirdPromise = require('bluebird') var isPromise = require('is-promise') test(t => { t.is(implementation, 'bluebird') t.is(Promise, BluebirdPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.falsy(global['@@any-promise/REGISTRATION']) }) any-promise-1.3.0/test/rsvp-shortcut.js000066400000000000000000000006441271362565100201520ustar00rootroot00000000000000import '../register/rsvp' var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var RSVPPromise = require('rsvp').Promise var isPromise = require('is-promise') test(t => { t.is(implementation, 'rsvp') t.is(Promise, RSVPPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/rsvp.js000066400000000000000000000006501271362565100162760ustar00rootroot00000000000000require('../register')('rsvp') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var RSVPPromise = require('rsvp').Promise var isPromise = require('is-promise') test(t => { t.is(implementation, 'rsvp') t.is(Promise, RSVPPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/vow-shortcut.js000066400000000000000000000006401271362565100177670ustar00rootroot00000000000000require('../register/vow') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var VowPromise = require('vow').Promise var isPromise = require('is-promise') test(t => { t.is(implementation, 'vow') t.is(Promise, VowPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/vow.js000066400000000000000000000006431271362565100161210ustar00rootroot00000000000000require('../register')('vow') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var VowPromise = require('vow').Promise var isPromise = require('is-promise') test(t => { t.is(implementation, 'vow') t.is(Promise, VowPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/when-shortcut.js000066400000000000000000000006441271362565100201210ustar00rootroot00000000000000import '../register/when' var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var WhenPromise = require('when').Promise var isPromise = require('is-promise') test(t => { t.is(implementation, 'when') t.is(Promise, WhenPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) }) any-promise-1.3.0/test/when.js000066400000000000000000000006501271362565100162450ustar00rootroot00000000000000require('../register')('when') var test = require('ava') var implementation = require('../implementation') var Promise = require('..') var WhenPromise = require('when').Promise var isPromise = require('is-promise') test(t => { t.is(implementation, 'when') t.is(Promise, WhenPromise) t.truthy(isPromise(new Promise(() => {}))) t.truthy(Promise.all) t.truthy(global['@@any-promise/REGISTRATION'].implementation) })