├── .gitignore ├── .jshintrc ├── .npmignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── implementation.d.ts ├── implementation.js ├── index.d.ts ├── index.js ├── loader.js ├── package.json ├── register-shim.js ├── register.d.ts ├── register.js ├── register ├── bluebird.d.ts ├── bluebird.js ├── es6-promise.d.ts ├── es6-promise.js ├── lie.d.ts ├── lie.js ├── native-promise-only.d.ts ├── native-promise-only.js ├── pinkie.d.ts ├── pinkie.js ├── promise.d.ts ├── promise.js ├── q.d.ts ├── q.js ├── rsvp.d.ts ├── rsvp.js ├── vow.d.ts ├── vow.js ├── when.d.ts └── when.js ├── test-browser ├── local.js ├── polyfill.js ├── register.js └── shortcut.js └── test ├── bluebird-shortcut.js ├── bluebird.js ├── browser.js ├── defaults.js ├── es6-promise-shortcut.js ├── es6-promise.js ├── global.js ├── lie-shortcut.js ├── lie.js ├── native-promise-only-shortcut.js ├── native-promise-only.js ├── pinkie-shortcut.js ├── pinkie.js ├── polyfill.js ├── promise-shortcut.js ├── promise.js ├── q-shortcut.js ├── q.js ├── register-local.js ├── rsvp-shortcut.js ├── rsvp.js ├── vow-shortcut.js ├── vow.js ├── when-shortcut.js └── when.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | *.swp 4 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node":true, 3 | "strict":true 4 | } 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git* 2 | test/ 3 | test-browser/ 4 | build/ 5 | .travis.yml 6 | *.swp 7 | Makefile 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | node_js: 4 | - "0.10" 5 | - "0.12" 6 | - "4" 7 | - "5" 8 | - "6" 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2014-2016 Kevin Beaty 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PROJECT:=any-promise 2 | 3 | JS_TARGET ?= build/$(PROJECT).js 4 | JS_WEBPACK ?= build/$(PROJECT)-wp.js 5 | 6 | .PHONY: all clean js test serve 7 | all: test js 8 | 9 | clean: 10 | rm -rf build 11 | 12 | test: | node_modules 13 | npm test 14 | 15 | node_modules: 16 | npm install 17 | 18 | %.min.js: %.js | node_modules 19 | `npm bin`/uglifyjs $< -o $@ -c -m 20 | 21 | %.gz: % 22 | gzip -c9 $^ > $@ 23 | 24 | js: $(JS_TARGET) $(JS_TARGET:.js=.min.js) $(JS_WEBPACK) $(JS_WEBPACK:.js=.min.js) 25 | 26 | $(JS_TARGET): index.js register-shim.js register.js loader.js | build 27 | `npm bin`/browserify $< > $@ 28 | 29 | $(JS_WEBPACK): index.js register-shim.js register.js loader.js | build 30 | `npm bin`/webpack $< $@ 31 | 32 | build: 33 | mkdir -p build 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Any Promise 2 | 3 | [![Build Status](https://secure.travis-ci.org/kevinbeaty/any-promise.svg)](http://travis-ci.org/kevinbeaty/any-promise) 4 | 5 | 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. 6 | 7 | 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. 8 | 9 | ### Usage with global Promise: 10 | 11 | Assuming the global `Promise` is the desired implementation: 12 | 13 | ```bash 14 | # Install any libraries depending on any-promise 15 | $ npm install mz 16 | ``` 17 | 18 | The installed libraries will use global Promise by default. 19 | 20 | ```js 21 | // in library 22 | var Promise = require('any-promise') // the global Promise 23 | 24 | function promiseReturningFunction(){ 25 | return new Promise(function(resolve, reject){...}) 26 | } 27 | ``` 28 | 29 | ### Usage with registration: 30 | 31 | Assuming `bluebird` is the desired Promise implementation: 32 | 33 | ```bash 34 | # Install preferred promise library 35 | $ npm install bluebird 36 | # Install any-promise to allow registration 37 | $ npm install any-promise 38 | # Install any libraries you would like to use depending on any-promise 39 | $ npm install mz 40 | ``` 41 | 42 | Register your preference in the application entry point before any other `require` of packages that load `any-promise`: 43 | 44 | ```javascript 45 | // top of application index.js or other entry point 46 | require('any-promise/register/bluebird') 47 | 48 | // -or- Equivalent to above, but allows customization of Promise library 49 | require('any-promise/register')('bluebird', {Promise: require('bluebird')}) 50 | ``` 51 | 52 | Now that the implementation is registered, you can use any package depending on `any-promise`: 53 | 54 | 55 | ```javascript 56 | var fsp = require('mz/fs') // mz/fs will use registered bluebird promises 57 | var Promise = require('any-promise') // the registered bluebird promise 58 | ``` 59 | 60 | It is safe to call `register` multiple times, but it must always be with the same implementation. 61 | 62 | Again, registration is *optional*. It should only be called by the application user if overriding the global `Promise` implementation is desired. 63 | 64 | ### Optional Application Registration 65 | 66 | As an application author, you can *optionally* register a preferred `Promise` implementation on application startup (before any call to `require('any-promise')`: 67 | 68 | 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. 69 | 70 | 71 | #### Registration shortcuts 72 | 73 | If you are using a known `Promise` implementation, you can register your preference with a shortcut: 74 | 75 | 76 | ```js 77 | require('any-promise/register/bluebird') 78 | // -or- 79 | import 'any-promise/register/q'; 80 | ``` 81 | 82 | 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: 83 | 84 | ``` 85 | $ ava --require=any-promise/register/bluebird test.js 86 | ``` 87 | 88 | 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. 89 | 90 | 91 | #### Basic Registration 92 | 93 | 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). 94 | 95 | ```javascript 96 | require('any-promise/register')('when') 97 | // -or- require('any-promise/register')('any other ES6 compatible library (known or otherwise)') 98 | ``` 99 | 100 | 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. 101 | 102 | 103 | #### Advanced Registration 104 | 105 | To use the browser version, you should either install a polyfill or explicitly register the `Promise` constructor: 106 | 107 | ```javascript 108 | require('any-promise/register')('bluebird', {Promise: require('bluebird')}) 109 | ``` 110 | 111 | This could also be used for registering a custom `Promise` implementation or subclass. 112 | 113 | 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: 114 | 115 | 116 | ```javascript 117 | require('../register')('es6-promise', {Promise: require('es6-promise').Promise, global: false}) 118 | ``` 119 | 120 | ### Library Usage 121 | 122 | To use any `Promise` constructor, simply require it: 123 | 124 | ```javascript 125 | var Promise = require('any-promise'); 126 | 127 | return Promise 128 | .all([xf, f, init, coll]) 129 | .then(fn); 130 | 131 | 132 | return new Promise(function(resolve, reject){ 133 | try { 134 | resolve(item); 135 | } catch(e){ 136 | reject(e); 137 | } 138 | }); 139 | 140 | ``` 141 | 142 | 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. 143 | 144 | 145 | #### Advanced Library Usage 146 | 147 | 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. 148 | 149 | 150 | ### Support for old Node.js versions 151 | 152 | 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. 153 | 154 | 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. 155 | 156 | 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. 157 | 158 | ### Related 159 | 160 | - [any-observable](https://github.com/sindresorhus/any-observable) - `any-promise` for Observables. 161 | 162 | -------------------------------------------------------------------------------- /implementation.d.ts: -------------------------------------------------------------------------------- 1 | declare var implementation: string; 2 | 3 | export = implementation; 4 | -------------------------------------------------------------------------------- /implementation.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./register')().implementation 2 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare class Promise implements Promise.Thenable { 2 | /** 3 | * If you call resolve in the body of the callback passed to the constructor, 4 | * your promise is fulfilled with result object passed to resolve. 5 | * If you call reject your promise is rejected with the object passed to resolve. 6 | * For consistency and debugging (eg stack traces), obj should be an instanceof Error. 7 | * Any errors thrown in the constructor callback will be implicitly passed to reject(). 8 | */ 9 | constructor (callback: (resolve : (value?: R | Promise.Thenable) => void, reject: (error?: any) => void) => void); 10 | 11 | /** 12 | * onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. 13 | * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. 14 | * Both callbacks have a single parameter , the fulfillment value or rejection reason. 15 | * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. 16 | * If an error is thrown in the callback, the returned promise rejects with that error. 17 | * 18 | * @param onFulfilled called when/if "promise" resolves 19 | * @param onRejected called when/if "promise" rejects 20 | */ 21 | then (onFulfilled?: (value: R) => U | Promise.Thenable, onRejected?: (error: any) => U | Promise.Thenable): Promise; 22 | then (onFulfilled?: (value: R) => U | Promise.Thenable, onRejected?: (error: any) => void): Promise; 23 | 24 | /** 25 | * Sugar for promise.then(undefined, onRejected) 26 | * 27 | * @param onRejected called when/if "promise" rejects 28 | */ 29 | catch (onRejected?: (error: any) => U | Promise.Thenable): Promise; 30 | 31 | /** 32 | * Make a new promise from the thenable. 33 | * A thenable is promise-like in as far as it has a "then" method. 34 | */ 35 | static resolve (): Promise; 36 | static resolve (value: R | Promise.Thenable): Promise; 37 | 38 | /** 39 | * Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error 40 | */ 41 | static reject (error: any): Promise; 42 | 43 | /** 44 | * Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects. 45 | * the array passed to all can be a mixture of promise-like objects and other objects. 46 | * The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value. 47 | */ 48 | 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]>; 49 | 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]>; 50 | 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]>; 51 | 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]>; 52 | 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]>; 53 | static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable, T3 | Promise.Thenable, T4 | Promise.Thenable , T5 | Promise.Thenable]): Promise<[T1, T2, T3, T4, T5]>; 54 | static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable, T3 | Promise.Thenable, T4 | Promise.Thenable ]): Promise<[T1, T2, T3, T4]>; 55 | static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable, T3 | Promise.Thenable]): Promise<[T1, T2, T3]>; 56 | static all (values: [T1 | Promise.Thenable, T2 | Promise.Thenable]): Promise<[T1, T2]>; 57 | static all (values: [T1 | Promise.Thenable]): Promise<[T1]>; 58 | static all (values: Array>): Promise; 59 | 60 | /** 61 | * Make a Promise that fulfills when any item fulfills, and rejects if any item rejects. 62 | */ 63 | static race (promises: (R | Promise.Thenable)[]): Promise; 64 | } 65 | 66 | declare namespace Promise { 67 | export interface Thenable { 68 | then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Thenable; 69 | then (onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => void): Thenable; 70 | } 71 | } 72 | 73 | export = Promise; 74 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./register')().Promise 2 | -------------------------------------------------------------------------------- /loader.js: -------------------------------------------------------------------------------- 1 | "use strict" 2 | // global key for user preferred registration 3 | var REGISTRATION_KEY = '@@any-promise/REGISTRATION', 4 | // Prior registration (preferred or detected) 5 | registered = null 6 | 7 | /** 8 | * Registers the given implementation. An implementation must 9 | * be registered prior to any call to `require("any-promise")`, 10 | * typically on application load. 11 | * 12 | * If called with no arguments, will return registration in 13 | * following priority: 14 | * 15 | * For Node.js: 16 | * 17 | * 1. Previous registration 18 | * 2. global.Promise if node.js version >= 0.12 19 | * 3. Auto detected promise based on first sucessful require of 20 | * known promise libraries. Note this is a last resort, as the 21 | * loaded library is non-deterministic. node.js >= 0.12 will 22 | * always use global.Promise over this priority list. 23 | * 4. Throws error. 24 | * 25 | * For Browser: 26 | * 27 | * 1. Previous registration 28 | * 2. window.Promise 29 | * 3. Throws error. 30 | * 31 | * Options: 32 | * 33 | * Promise: Desired Promise constructor 34 | * global: Boolean - Should the registration be cached in a global variable to 35 | * allow cross dependency/bundle registration? (default true) 36 | */ 37 | module.exports = function(root, loadImplementation){ 38 | return function register(implementation, opts){ 39 | implementation = implementation || null 40 | opts = opts || {} 41 | // global registration unless explicitly {global: false} in options (default true) 42 | var registerGlobal = opts.global !== false; 43 | 44 | // load any previous global registration 45 | if(registered === null && registerGlobal){ 46 | registered = root[REGISTRATION_KEY] || null 47 | } 48 | 49 | if(registered !== null 50 | && implementation !== null 51 | && registered.implementation !== implementation){ 52 | // Throw error if attempting to redefine implementation 53 | throw new Error('any-promise already defined as "'+registered.implementation+ 54 | '". You can only register an implementation before the first '+ 55 | ' call to require("any-promise") and an implementation cannot be changed') 56 | } 57 | 58 | if(registered === null){ 59 | // use provided implementation 60 | if(implementation !== null && typeof opts.Promise !== 'undefined'){ 61 | registered = { 62 | Promise: opts.Promise, 63 | implementation: implementation 64 | } 65 | } else { 66 | // require implementation if implementation is specified but not provided 67 | registered = loadImplementation(implementation) 68 | } 69 | 70 | if(registerGlobal){ 71 | // register preference globally in case multiple installations 72 | root[REGISTRATION_KEY] = registered 73 | } 74 | } 75 | 76 | return registered 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "any-promise", 3 | "version": "1.3.0", 4 | "description": "Resolve any installed ES6 compatible promise", 5 | "main": "index.js", 6 | "typings": "index.d.ts", 7 | "browser": { 8 | "./register.js": "./register-shim.js" 9 | }, 10 | "scripts": { 11 | "test": "ava" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/kevinbeaty/any-promise" 16 | }, 17 | "keywords": [ 18 | "promise", 19 | "es6" 20 | ], 21 | "author": "Kevin Beaty", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/kevinbeaty/any-promise/issues" 25 | }, 26 | "homepage": "http://github.com/kevinbeaty/any-promise", 27 | "dependencies": {}, 28 | "devDependencies": { 29 | "ava": "^0.14.0", 30 | "bluebird": "^3.0.0", 31 | "es6-promise": "^3.0.0", 32 | "is-promise": "^2.0.0", 33 | "lie": "^3.0.0", 34 | "mocha": "^2.0.0", 35 | "native-promise-only": "^0.8.0", 36 | "phantomjs-prebuilt": "^2.0.0", 37 | "pinkie": "^2.0.0", 38 | "promise": "^7.0.0", 39 | "q": "^1.0.0", 40 | "rsvp": "^3.0.0", 41 | "vow": "^0.4.0", 42 | "webpack": "^1.0.0", 43 | "when": "^3.0.0", 44 | "zuul": "^3.0.0" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /register-shim.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = require('./loader')(window, loadImplementation) 3 | 4 | /** 5 | * Browser specific loadImplementation. Always uses `window.Promise` 6 | * 7 | * To register a custom implementation, must register with `Promise` option. 8 | */ 9 | function loadImplementation(){ 10 | if(typeof window.Promise === 'undefined'){ 11 | throw new Error("any-promise browser requires a polyfill or explicit registration"+ 12 | " e.g: require('any-promise/register/bluebird')") 13 | } 14 | return { 15 | Promise: window.Promise, 16 | implementation: 'window.Promise' 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /register.d.ts: -------------------------------------------------------------------------------- 1 | import Promise = require('./index'); 2 | 3 | declare function register (module?: string, options?: register.Options): register.Register; 4 | 5 | declare namespace register { 6 | export interface Register { 7 | Promise: typeof Promise; 8 | implementation: string; 9 | } 10 | 11 | export interface Options { 12 | Promise?: typeof Promise; 13 | global?: boolean 14 | } 15 | } 16 | 17 | export = register; 18 | -------------------------------------------------------------------------------- /register.js: -------------------------------------------------------------------------------- 1 | "use strict" 2 | module.exports = require('./loader')(global, loadImplementation); 3 | 4 | /** 5 | * Node.js version of loadImplementation. 6 | * 7 | * Requires the given implementation and returns the registration 8 | * containing {Promise, implementation} 9 | * 10 | * If implementation is undefined or global.Promise, loads it 11 | * Otherwise uses require 12 | */ 13 | function loadImplementation(implementation){ 14 | var impl = null 15 | 16 | if(shouldPreferGlobalPromise(implementation)){ 17 | // if no implementation or env specified use global.Promise 18 | impl = { 19 | Promise: global.Promise, 20 | implementation: 'global.Promise' 21 | } 22 | } else if(implementation){ 23 | // if implementation specified, require it 24 | var lib = require(implementation) 25 | impl = { 26 | Promise: lib.Promise || lib, 27 | implementation: implementation 28 | } 29 | } else { 30 | // try to auto detect implementation. This is non-deterministic 31 | // and should prefer other branches, but this is our last chance 32 | // to load something without throwing error 33 | impl = tryAutoDetect() 34 | } 35 | 36 | if(impl === null){ 37 | throw new Error('Cannot find any-promise implementation nor'+ 38 | ' global.Promise. You must install polyfill or call'+ 39 | ' require("any-promise/register") with your preferred'+ 40 | ' implementation, e.g. require("any-promise/register/bluebird")'+ 41 | ' on application load prior to any require("any-promise").') 42 | } 43 | 44 | return impl 45 | } 46 | 47 | /** 48 | * Determines if the global.Promise should be preferred if an implementation 49 | * has not been registered. 50 | */ 51 | function shouldPreferGlobalPromise(implementation){ 52 | if(implementation){ 53 | return implementation === 'global.Promise' 54 | } else if(typeof global.Promise !== 'undefined'){ 55 | // Load global promise if implementation not specified 56 | // Versions < 0.11 did not have global Promise 57 | // Do not use for version < 0.12 as version 0.11 contained buggy versions 58 | var version = (/v(\d+)\.(\d+)\.(\d+)/).exec(process.version) 59 | return !(version && +version[1] == 0 && +version[2] < 12) 60 | } 61 | 62 | // do not have global.Promise or another implementation was specified 63 | return false 64 | } 65 | 66 | /** 67 | * Look for common libs as last resort there is no guarantee that 68 | * this will return a desired implementation or even be deterministic. 69 | * The priority is also nearly arbitrary. We are only doing this 70 | * for older versions of Node.js <0.12 that do not have a reasonable 71 | * global.Promise implementation and we the user has not registered 72 | * the preference. This preserves the behavior of any-promise <= 0.1 73 | * and may be deprecated or removed in the future 74 | */ 75 | function tryAutoDetect(){ 76 | var libs = [ 77 | "es6-promise", 78 | "promise", 79 | "native-promise-only", 80 | "bluebird", 81 | "rsvp", 82 | "when", 83 | "q", 84 | "pinkie", 85 | "lie", 86 | "vow"] 87 | var i = 0, len = libs.length 88 | for(; i < len; i++){ 89 | try { 90 | return loadImplementation(libs[i]) 91 | } catch(e){} 92 | } 93 | return null 94 | } 95 | -------------------------------------------------------------------------------- /register/bluebird.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /register/bluebird.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('bluebird', {Promise: require('bluebird')}) 3 | -------------------------------------------------------------------------------- /register/es6-promise.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /register/es6-promise.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('es6-promise', {Promise: require('es6-promise').Promise}) 3 | -------------------------------------------------------------------------------- /register/lie.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /register/lie.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('lie', {Promise: require('lie')}) 3 | -------------------------------------------------------------------------------- /register/native-promise-only.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /register/native-promise-only.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('native-promise-only', {Promise: require('native-promise-only')}) 3 | -------------------------------------------------------------------------------- /register/pinkie.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /register/pinkie.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('pinkie', {Promise: require('pinkie')}) 3 | -------------------------------------------------------------------------------- /register/promise.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /register/promise.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('promise', {Promise: require('promise')}) 3 | -------------------------------------------------------------------------------- /register/q.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /register/q.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('q', {Promise: require('q').Promise}) 3 | -------------------------------------------------------------------------------- /register/rsvp.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /register/rsvp.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('rsvp', {Promise: require('rsvp').Promise}) 3 | -------------------------------------------------------------------------------- /register/vow.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /register/vow.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('vow', {Promise: require('vow').Promise}) 3 | -------------------------------------------------------------------------------- /register/when.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /register/when.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('when', {Promise: require('when').Promise}) 3 | -------------------------------------------------------------------------------- /test-browser/local.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('es6-promise', {Promise: require('es6-promise').Promise, global: false}) 3 | 4 | var REGISTRATION_KEY = '@@any-promise/REGISTRATION' 5 | var Promise = require('..') 6 | var implementation = require('../implementation') 7 | var isPromise = require('is-promise') 8 | 9 | it('Register local test in browser', function(){ 10 | if(!isPromise(new Promise(noop))){ 11 | throw new Error('Promise not exported') 12 | } 13 | if(typeof window[REGISTRATION_KEY] !== 'undefined'){ 14 | throw new Error('Expecting local registration') 15 | } 16 | 17 | if(implementation !== 'es6-promise'){ 18 | throw new Error('Implementation not expected: '+impl) 19 | } 20 | }) 21 | 22 | function noop(){} 23 | -------------------------------------------------------------------------------- /test-browser/polyfill.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('es6-promise').polyfill() 3 | 4 | var REGISTRATION_KEY = '@@any-promise/REGISTRATION' 5 | var Promise = require('..') 6 | var implementation = require('../implementation') 7 | var isPromise = require('is-promise') 8 | 9 | it('Polyfill test in browser', function(){ 10 | if(!isPromise(new Promise(noop))){ 11 | throw new Error('Promise not exported') 12 | } 13 | if(implementation !== 'window.Promise'){ 14 | throw new Error('Expecting window.Promise as implementation') 15 | } 16 | 17 | if(window[REGISTRATION_KEY].implementation !== 'window.Promise'){ 18 | throw new Error('Expecting global registration') 19 | } 20 | }) 21 | 22 | function noop(){} 23 | -------------------------------------------------------------------------------- /test-browser/register.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register')('bluebird', {Promise: require('bluebird')}) 3 | 4 | var REGISTRATION_KEY = '@@any-promise/REGISTRATION' 5 | var Promise = require('..') 6 | var implementation = require('../implementation') 7 | var isPromise = require('is-promise') 8 | 9 | it('Register test in browser', function(){ 10 | if(!isPromise(new Promise(noop))){ 11 | throw new Error('Promise not exported') 12 | } 13 | if(implementation !== 'bluebird'){ 14 | throw new Error('Expecting bluebird as implementation') 15 | } 16 | 17 | if(window[REGISTRATION_KEY].implementation !== 'bluebird'){ 18 | throw new Error('Expecting global registration') 19 | } 20 | }) 21 | 22 | function noop(){} 23 | -------------------------------------------------------------------------------- /test-browser/shortcut.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../register/bluebird') 3 | 4 | var REGISTRATION_KEY = '@@any-promise/REGISTRATION' 5 | var Promise = require('..') 6 | var implementation = require('../implementation') 7 | var isPromise = require('is-promise') 8 | 9 | it('Shortcut test in browser', function(){ 10 | if(!isPromise(new Promise(noop))){ 11 | throw new Error('Promise not exported') 12 | } 13 | if(implementation !== 'bluebird'){ 14 | throw new Error('Expecting bluebird as implementation') 15 | } 16 | 17 | if(window[REGISTRATION_KEY].implementation !== 'bluebird'){ 18 | throw new Error('Expecting global registration') 19 | } 20 | }) 21 | 22 | function noop(){} 23 | -------------------------------------------------------------------------------- /test/bluebird-shortcut.js: -------------------------------------------------------------------------------- 1 | import '../register/bluebird' 2 | 3 | var test = require('ava') 4 | var implementation = require('../implementation') 5 | var Promise = require('..') 6 | var BluebirdPromise = require('bluebird') 7 | var isPromise = require('is-promise') 8 | 9 | test(t => { 10 | t.is(implementation, 'bluebird') 11 | t.is(Promise, BluebirdPromise) 12 | t.truthy(isPromise(new Promise(() => {}))) 13 | t.truthy(Promise.all) 14 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 15 | }) 16 | -------------------------------------------------------------------------------- /test/bluebird.js: -------------------------------------------------------------------------------- 1 | require('../register')('bluebird') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var BluebirdPromise = require('bluebird') 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'bluebird') 10 | t.is(Promise, BluebirdPromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/browser.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var Promise = require('..') 3 | var version = (/v(\d+)\.(\d+)\.(\d+)/).exec(process.version) 4 | var {spawn} = require('child_process') 5 | 6 | if (+version[1] <= 5) { 7 | test('skipped browser tests for Node.js <= 5', () => {}) 8 | } else { 9 | ;['register', 'local', 'polyfill', 'shortcut'].forEach(filename => { 10 | test.serial('Browser test: '+filename, () => zuul(filename)) 11 | }) 12 | } 13 | 14 | function zuul(file){ 15 | return new Promise((resolve, reject) => { 16 | var zuul = spawn( 17 | 'zuul', 18 | ['--phantom', '--ui', 'mocha-bdd', '--', '../test-browser/'+file+'.js'], 19 | {stdio: 'inherit'}) 20 | 21 | zuul.on('error', (err) => reject(err)) 22 | zuul.on('close', (code, err) => { 23 | if(code !== 0){ 24 | reject('Zuul did not exit successfully '+code) 25 | } else { 26 | resolve() 27 | } 28 | }) 29 | }) 30 | } 31 | -------------------------------------------------------------------------------- /test/defaults.js: -------------------------------------------------------------------------------- 1 | var test = require('ava') 2 | var implementation = require('../implementation') 3 | var Promise = require('..') 4 | var isPromise = require('is-promise') 5 | 6 | test(t => { 7 | var version = (/v(\d+)\.(\d+)\.(\d+)/).exec(process.version) 8 | if(version && +version[1] == 0 && +version[2] < 12){ 9 | // Node < 0.12 should load first successful require in 10 | // priority list if not registered 11 | t.is(implementation, 'es6-promise') 12 | } else { 13 | // Node >= 0.12 should load global.Promise if not registered 14 | t.is(implementation, 'global.Promise') 15 | } 16 | t.is(Promise, global.Promise) 17 | t.truthy(isPromise(new Promise(() => {}))) 18 | t.truthy(Promise.all) 19 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 20 | }) 21 | -------------------------------------------------------------------------------- /test/es6-promise-shortcut.js: -------------------------------------------------------------------------------- 1 | import '../register/es6-promise' 2 | 3 | var test = require('ava') 4 | var implementation = require('../implementation') 5 | var Promise = require('..') 6 | var ES6Promise = require('es6-promise').Promise 7 | var isPromise = require('is-promise') 8 | 9 | test(t => { 10 | t.is(implementation, 'es6-promise') 11 | t.is(Promise, ES6Promise) 12 | t.truthy(isPromise(new Promise(() => {}))) 13 | t.truthy(Promise.all) 14 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 15 | }) 16 | -------------------------------------------------------------------------------- /test/es6-promise.js: -------------------------------------------------------------------------------- 1 | require('../register')('es6-promise') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var ES6Promise = require('es6-promise').Promise 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'es6-promise') 10 | t.is(Promise, ES6Promise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/global.js: -------------------------------------------------------------------------------- 1 | if(typeof global.Promise === 'undefined'){ 2 | require('es6-promise').polyfill() 3 | } 4 | require('../register')('global.Promise') 5 | 6 | var test = require('ava') 7 | var implementation = require('../implementation') 8 | var Promise = require('..') 9 | var isPromise = require('is-promise') 10 | 11 | test(t => { 12 | t.is(implementation, 'global.Promise') 13 | t.is(Promise, global.Promise) 14 | t.truthy(isPromise(new Promise(() => {}))) 15 | t.truthy(Promise.all) 16 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 17 | }) 18 | -------------------------------------------------------------------------------- /test/lie-shortcut.js: -------------------------------------------------------------------------------- 1 | require('../register/lie') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var LiePromise = require('lie') 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'lie') 10 | t.is(Promise, LiePromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/lie.js: -------------------------------------------------------------------------------- 1 | require('../register')('lie') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var LiePromise = require('lie') 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'lie') 10 | t.is(Promise, LiePromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/native-promise-only-shortcut.js: -------------------------------------------------------------------------------- 1 | import '../register/native-promise-only' 2 | 3 | var test = require('ava') 4 | var implementation = require('../implementation') 5 | var Promise = require('..') 6 | var NPOPromise = require('native-promise-only') 7 | var isPromise = require('is-promise') 8 | 9 | test(t => { 10 | t.is(implementation, 'native-promise-only') 11 | t.is(Promise, NPOPromise) 12 | t.truthy(isPromise(new Promise(() => {}))) 13 | t.truthy(Promise.all) 14 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 15 | }) 16 | -------------------------------------------------------------------------------- /test/native-promise-only.js: -------------------------------------------------------------------------------- 1 | require('../register')('native-promise-only') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var NPOPromise = require('native-promise-only') 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'native-promise-only') 10 | t.is(Promise, NPOPromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/pinkie-shortcut.js: -------------------------------------------------------------------------------- 1 | require('../register/pinkie') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var PinkiePromise = require('pinkie') 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'pinkie') 10 | t.is(Promise, PinkiePromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/pinkie.js: -------------------------------------------------------------------------------- 1 | require('../register')('pinkie') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var PinkiePromise = require('pinkie') 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'pinkie') 10 | t.is(Promise, PinkiePromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/polyfill.js: -------------------------------------------------------------------------------- 1 | require('es6-promise').polyfill() 2 | 3 | var test = require('ava') 4 | var implementation = require('../implementation') 5 | var Promise = require('..') 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | // The implementation will either be global.Promise or es6-promise 10 | // depending on node version. This is a bit of a hack for this test 11 | // but works as test because es6-promise is first successfull require 12 | // and we polyfilled with es6-promise 13 | t.is(Promise, global.Promise) 14 | t.truthy(isPromise(new Promise(() => {}))) 15 | t.truthy(Promise.all) 16 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 17 | }) 18 | -------------------------------------------------------------------------------- /test/promise-shortcut.js: -------------------------------------------------------------------------------- 1 | import '../register/promise' 2 | 3 | var test = require('ava') 4 | var implementation = require('../implementation') 5 | var Promise = require('..') 6 | var PromisePromise = require('promise') 7 | var isPromise = require('is-promise') 8 | 9 | test(t => { 10 | t.is(implementation, 'promise') 11 | t.is(Promise, PromisePromise) 12 | t.truthy(isPromise(new Promise(() => {}))) 13 | t.truthy(Promise.all) 14 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 15 | }) 16 | -------------------------------------------------------------------------------- /test/promise.js: -------------------------------------------------------------------------------- 1 | require('../register')('promise') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var PromisePromise = require('promise') 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'promise') 10 | t.is(Promise, PromisePromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/q-shortcut.js: -------------------------------------------------------------------------------- 1 | import '../register/q' 2 | 3 | var test = require('ava') 4 | var implementation = require('../implementation') 5 | var Promise = require('..') 6 | var QPromise = require('q').Promise 7 | var isPromise = require('is-promise') 8 | 9 | test(t => { 10 | t.is(implementation, 'q') 11 | t.is(Promise, QPromise) 12 | t.truthy(isPromise(new Promise(() => {}))) 13 | t.truthy(Promise.all) 14 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 15 | }) 16 | -------------------------------------------------------------------------------- /test/q.js: -------------------------------------------------------------------------------- 1 | require('../register')('q') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var QPromise = require('q').Promise 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'q') 10 | t.is(Promise, QPromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/register-local.js: -------------------------------------------------------------------------------- 1 | require('../register')('bluebird', {global: false}) 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var BluebirdPromise = require('bluebird') 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'bluebird') 10 | t.is(Promise, BluebirdPromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.falsy(global['@@any-promise/REGISTRATION']) 14 | }) 15 | -------------------------------------------------------------------------------- /test/rsvp-shortcut.js: -------------------------------------------------------------------------------- 1 | import '../register/rsvp' 2 | 3 | var test = require('ava') 4 | var implementation = require('../implementation') 5 | var Promise = require('..') 6 | var RSVPPromise = require('rsvp').Promise 7 | var isPromise = require('is-promise') 8 | 9 | test(t => { 10 | t.is(implementation, 'rsvp') 11 | t.is(Promise, RSVPPromise) 12 | t.truthy(isPromise(new Promise(() => {}))) 13 | t.truthy(Promise.all) 14 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 15 | }) 16 | -------------------------------------------------------------------------------- /test/rsvp.js: -------------------------------------------------------------------------------- 1 | require('../register')('rsvp') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var RSVPPromise = require('rsvp').Promise 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'rsvp') 10 | t.is(Promise, RSVPPromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/vow-shortcut.js: -------------------------------------------------------------------------------- 1 | require('../register/vow') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var VowPromise = require('vow').Promise 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'vow') 10 | t.is(Promise, VowPromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/vow.js: -------------------------------------------------------------------------------- 1 | require('../register')('vow') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var VowPromise = require('vow').Promise 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'vow') 10 | t.is(Promise, VowPromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | -------------------------------------------------------------------------------- /test/when-shortcut.js: -------------------------------------------------------------------------------- 1 | import '../register/when' 2 | 3 | var test = require('ava') 4 | var implementation = require('../implementation') 5 | var Promise = require('..') 6 | var WhenPromise = require('when').Promise 7 | var isPromise = require('is-promise') 8 | 9 | test(t => { 10 | t.is(implementation, 'when') 11 | t.is(Promise, WhenPromise) 12 | t.truthy(isPromise(new Promise(() => {}))) 13 | t.truthy(Promise.all) 14 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 15 | }) 16 | -------------------------------------------------------------------------------- /test/when.js: -------------------------------------------------------------------------------- 1 | require('../register')('when') 2 | var test = require('ava') 3 | var implementation = require('../implementation') 4 | var Promise = require('..') 5 | var WhenPromise = require('when').Promise 6 | var isPromise = require('is-promise') 7 | 8 | test(t => { 9 | t.is(implementation, 'when') 10 | t.is(Promise, WhenPromise) 11 | t.truthy(isPromise(new Promise(() => {}))) 12 | t.truthy(Promise.all) 13 | t.truthy(global['@@any-promise/REGISTRATION'].implementation) 14 | }) 15 | --------------------------------------------------------------------------------