diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index fb14136..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -repo_token: au19VxPf6y8bRZsc3yAupOzmIpEOr2Fly \ No newline at end of file diff --git a/.editorconfig b/.editorconfig index bd3863d..87bee69 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,34 +1,26 @@ # .editorconfig # -# Copyright (c) 2014 Charlike Mike Reagent, contributors. +# Copyright (c) 2015 Charlike Mike Reagent, contributors. # Released under the MIT license. # root = true [*] -indent_style = space charset = utf-8 end_of_line = lf -insert_final_newline = false -trim_trailing_whitespace = false - -[*.{json,cson,yml,yaml,md,jade,css,stylus}] indent_size = 2 +indent_style = space -[*.{js,php}] -indent_size = 2 +[*.js] insert_final_newline = true trim_trailing_whitespace = true -[*.{php,html}] +[*.php] indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true -[Makefile] -indent_size = 2 -indent_style = tab - -[.*rc] -indent_size = 2 -indent_style = space -trim_trailing_whitespace = true \ No newline at end of file +[*.md] +insert_final_newline = false +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index f5017db..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -# .gitattributes -# -# Copyright (c) 2014 Charlike Mike Reagent, contributors. -# Released under the MIT license. -# - -# These settings are for any web project - -# Handle line endings automatically for files detected as text -# and leave all files detected as binary untouched. - -* text=auto - -# -# The above will handle all files NOT found below -# These files are text and should be normalized (Convert crlf => lf) -# - -*.php text -*.css text -*.js text -*.htm text -*.html text -*.xml text -*.txt text -*.ini text -*.inc text -.htaccess text - -# -# These files are binary and should be left untouched -# (binary is a macro for -text -diff) -# - -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.mov binary -*.mp4 binary -*.mp3 binary -*.flv binary -*.fla binary -*.swf binary -*.gz binary -*.zip binary -*.7z binary -*.ttf binary diff --git a/.gitignore b/.gitignore index 1089e93..ca40c47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # .gitignore # -# Copyright (c) 2014 Charlike Mike Reagent, contributors. +# Copyright (c) 2015 Charlike Mike Reagent, contributors. # Released under the MIT license. # @@ -21,6 +21,7 @@ nbproject cache temp tmp +native-or-another # Packages # # ########## @@ -53,3 +54,4 @@ Desktop.ini npm-debug.log .directory ._* +lcov.info \ No newline at end of file diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index 3b623b2..0000000 --- a/.jscsrc +++ /dev/null @@ -1,116 +0,0 @@ -{ - "fileExtensions": [".js"], - "maxErrors": 10, - "esnext": true, - "safeContextKeyword": ["self", "_this", "that"], - - "maximumLineLength": { - "value": 80, - "allowUrlComments": true, - "allowComments": true, - "allowRegex": true - }, - - "validateQuoteMarks": "'", - "validateIndentation": 2, - - "requireCurlyBraces": [ - "if", - "else", - "for", - "while", - "do", - "try", - "catch" - ], - "requireSpaceAfterKeywords": [ - "if", - "else", - "for", - "while", - "do", - "switch", - "case", - "return", - "try", - "catch", - "typeof" - ], - - "requireCamelCaseOrUpperCaseIdentifiers": true, - "requireSpacesInConditionalExpression": true, - "requireSpaceBeforeBlockStatements": true, - "requireSpaceBeforeBinaryOperators": true, - "requireOperatorBeforeLineBreak": true, - "requireCapitalizedConstructors": true, - "requireParenthesesAroundIIFE": true, - "requireCommaBeforeLineBreak": true, - "requireLineFeedAtFileEnd": true, - "requireDotNotation": true, - - "disallowYodaConditions": true, - "disallowMultipleLineStrings": true, - "disallowMultipleLineBreaks": true, - "disallowMultipleVarDecl": true, - "disallowMixedSpacesAndTabs": true, - "disallowTrailingComma": true, - "disallowTrailingWhitespace": true, - "disallowSpaceAfterPrefixUnaryOperators": true, - "disallowSpacesInsideObjectBrackets": "all", - "disallowSpacesInsideParentheses": true, - "disallowSpacesInsideArrayBrackets": true, - "disallowNewlineBeforeBlockStatements": true, - "disallowSpaceBeforePostfixUnaryOperators": true, - "disallowImplicitTypeConversion": ["string"], - "disallowKeywords": ["with"], - "disallowKeywordsOnNewLine": ["else"], - "disallowSpacesInCallExpression": true, - - "requireSpacesInNamedFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - "requireSpacesInAnonymousFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - "disallowSpacesInAnonymousFunctionExpression": { - "beforeOpeningRoundBrace": true - }, - - "plugins": [ - "jscs-jsdoc" - ], - "jsDoc": { - "checkParamNames": true, - "requireParamTypes": true, - "checkRedundantParams": true, - "checkReturnTypes": true, - "checkRedundantReturns": true, - "requireReturnTypes": true, - "checkRedundantAccess": true, - "checkTypes": "capitalizedNativeCase", - "checkAnnotations": { - "preset": "jsdoc3", - "extra": { - "api": true - } - } - }, - - "excludeFiles": [ - "_gh_pages/**", - "node_modules/**", - "bower_components/**", - "components/**", - "vendor/**", - "build/**", - "dest/**", - "dist/**", - "src/**", - "lib-cov/**", - "coverage/**", - "nbproject/**", - "cache/**", - "temp/**", - "tmp/**" - ] -} \ No newline at end of file diff --git a/.jshintignore b/.jshintignore deleted file mode 100644 index 2524114..0000000 --- a/.jshintignore +++ /dev/null @@ -1,23 +0,0 @@ -# .jshintignore -# -# Copyright (c) 2014 Charlike Mike Reagent, contributors. -# Released under the MIT license. -# - -# Always-ignore dirs # -# #################### -_gh_pages -node_modules -bower_components -components -vendor -build -dest -dist -src -lib-cov -coverage -nbproject -cache -temp -tmp \ No newline at end of file diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index a3f48c9..0000000 --- a/.jshintrc +++ /dev/null @@ -1,37 +0,0 @@ -{ - "maxerr" : 10, - "indent" : 2, - - "maxparams" : 3, - "maxdepth" : 3, - "maxstatements" : 15, - "maxlen" : 120, - - "camelcase" : true, - "forin" : false, - "immed" : true, - "newcap" : true, - "quotmark" : "single", - - "asi" : true, - "eqnull" : true, - "esnext" : true, - "funcscope" : true, - "globalstrict" : true, - "lastsemic" : true, - "shadow" : true, - - "node" : true, - "nonstandard" : true, - - "globals": { - "it": true, - "describe": true, - "beforeEach": true, - "afterEach": true, - "before": true, - "after": true, - "define": true, - "should": true - } -} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 38bbe01..a245e25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,24 @@ -sudo: false language: "node_js" +sudo: false + node_js: - - "iojs" - "0.10" - - "0.11" - "0.12" -matrix: - allow_failures: - - node_js: "0.10" - fast_finish: true -script: "npm run-script test-travis" -after_script: "npm install coveralls && cat ./coverage/lcov.info | coveralls" \ No newline at end of file + - "4" + +notifications: + email: + on_success: never + on_failure: never + +before_script: + - npm install standard + - standard + +script: + - npm install istanbul-harmony + - node --harmony node_modules/.bin/istanbul cover test.js + +after_success: + - npm install coveralls + - cat coverage/lcov.info | coveralls \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a75370f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,13 @@ + + +## v2.0.0 - 2014-12-21 +- Release v2.0.0 / npm@v2.0.0 +- change the purpose of library +- now exports deferred object + +## v1.0.0 - 2015-10-28 +- Release v1.0.0 / npm@v1.0.0 +- initial release + +## 0.0.0 - 2014-10-28 +- Initial commit \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..5312165 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,32 @@ +# Contributing Guidelines + +Contributions are always welcome! + +**Before spending lots of time on something, ask for feedback on your idea first!** + +Please search issues and pull requests before adding something new to avoid duplicating efforts and conversations. + + +## Installing + +Fork and clone the repo, then `npm install` to install all dependencies and `npm test` to ensure all is okey before you start anything. + + +## Testing + +Tests are run with `npm test`. Please ensure all tests are passing before submitting a pull request (unless you're creating a failing test to increase test coverage or show a problem). + +## Code Style + +[![standard][standard-image]][standard-url] + +This repository uses [`standard`][standard-url] to maintain code style and consistency, and to avoid style arguments. You are encouraged to install it globally. `npm test` runs `standard` so you don't have to! + +``` +npm i standard -g +``` + +It is intentional to don't have `standard`, `istanbul` and `coveralls` in the devDependencies. Travis will handle all that stuffs. That approach will save bandwidth also installing and development time. + +[standard-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg +[standard-url]: https://github.com/feross/standard \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2a21d7a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014-2015 Charlike Mike Reagent + +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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4b54eeb --- /dev/null +++ b/README.md @@ -0,0 +1,111 @@ +# [native-or-another][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] + +> Always will expose native `Promise` if available, otherwise `Bluebird` but only if you don't give another promise module like `q` or `promise` or what you want. + +**Heads up: v3 is here! See the changelog.md** + +[![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url] + + +## Install +``` +npm i native-or-another --save +``` + + +## Usage +> For more use-cases see the [tests](./test.js) + +```js +const getPromise = require('native-or-another') +``` + +### [nativeOrAnother](./index.js#L44) +> Always will expose native `Promise` if available. Otherwise given promise module or Bluebird. + +- `[Prome]` **{Function}** custom promise module +- `returns` **{Function}** native Promise or another + +**Example** + +```js +const fs = require('fs') +const NativeOrBluebird = getPromise() +const NativeOrPromise = getPromise(require('promise')) +const NativeOrPinkie = getPromise(require('pinkie')) +const NativeOrQ = getPromise(require('q')) + +const promise = new NativeOrBluebird((resolve, reject) => { + fs.readFile('package.json', 'utf-8', (err, res) => { + if (err) return reject(err) + resolve(res) + }) +}) + +promise.then(data => { + console.log(JSON.parse(data).name) + //=> 'native-or-another' +}) +``` + + +## Related +- [always-done](https://github.com/tunnckoCore/always-done): Handles completion and errors of anything! +- [always-promise](https://github.com/tunnckoCore/always-promise): Promisify basically **everything**. +- [always-thunk](https://github.com/tunnckoCore/always-thunk): Create thunk from **anything**, works like `thunkify`. Transforms anything (callbacks, streams, promises, observables, child processes, sync and generator functions) to thunk. +- [redolent](https://github.com/tunnckoCore/redolent): Simple promisify a callback-style function with sane defaults. + + +## Contributing +Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/tunnckoCore/native-or-another/issues/new). +But before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines. + + +## [Charlike Make Reagent](http://j.mp/1stW47C) [![new message to charlike][new-message-img]][new-message-url] [![freenode #charlike][freenode-img]][freenode-url] + +[![tunnckocore.tk][author-www-img]][author-www-url] [![keybase tunnckoCore][keybase-img]][keybase-url] [![tunnckoCore npm][author-npm-img]][author-npm-url] [![tunnckoCore twitter][author-twitter-img]][author-twitter-url] [![tunnckoCore github][author-github-img]][author-github-url] + + +[npmjs-url]: https://www.npmjs.com/package/native-or-another +[npmjs-img]: https://img.shields.io/npm/v/native-or-another.svg?label=native-or-another + +[license-url]: https://github.com/tunnckoCore/native-or-another/blob/master/LICENSE.md +[license-img]: https://img.shields.io/badge/license-MIT-blue.svg + + +[codeclimate-url]: https://codeclimate.com/github/tunnckoCore/native-or-another +[codeclimate-img]: https://img.shields.io/codeclimate/github/tunnckoCore/native-or-another.svg + +[travis-url]: https://travis-ci.org/tunnckoCore/native-or-another +[travis-img]: https://img.shields.io/travis/tunnckoCore/native-or-another.svg + +[coveralls-url]: https://coveralls.io/r/tunnckoCore/native-or-another +[coveralls-img]: https://img.shields.io/coveralls/tunnckoCore/native-or-another.svg + +[david-url]: https://david-dm.org/tunnckoCore/native-or-another +[david-img]: https://img.shields.io/david/tunnckoCore/native-or-another.svg + +[standard-url]: https://github.com/feross/standard +[standard-img]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg + + +[author-www-url]: http://www.tunnckoCore.tk +[author-www-img]: https://img.shields.io/badge/www-tunnckoCore.tk-fe7d37.svg + +[keybase-url]: https://keybase.io/tunnckoCore +[keybase-img]: https://img.shields.io/badge/keybase-tunnckoCore-8a7967.svg + +[author-npm-url]: https://www.npmjs.com/~tunnckoCore +[author-npm-img]: https://img.shields.io/badge/npm-~tunnckoCore-cb3837.svg + +[author-twitter-url]: https://twitter.com/tunnckoCore +[author-twitter-img]: https://img.shields.io/badge/twitter-@tunnckoCore-55acee.svg + +[author-github-url]: https://github.com/tunnckoCore +[author-github-img]: https://img.shields.io/badge/github-@tunnckoCore-4183c4.svg + +[freenode-url]: http://webchat.freenode.net/?channels=charlike +[freenode-img]: https://img.shields.io/badge/freenode-%23charlike-5654a4.svg + +[new-message-url]: https://github.com/tunnckoCore/ama +[new-message-img]: https://img.shields.io/badge/ask%20me-anything-green.svg \ No newline at end of file diff --git a/history.md b/history.md deleted file mode 100644 index f55f9da..0000000 --- a/history.md +++ /dev/null @@ -1,6 +0,0 @@ -## v2.0.0 / December 21, 2014 -- change the purpose of library -- now exports deferred object - -## v1.0.0 / October 28, 2014 -- initial release \ No newline at end of file diff --git a/index.js b/index.js index 238d7eb..5ee4841 100644 --- a/index.js +++ b/index.js @@ -1,21 +1,53 @@ -/** +/*! * native-or-another * - * Copyright (c) 2014 Charlike Mike Reagent, contributors. + * Copyright (c) 2014-2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk) * Released under the MIT license. */ -'use strict'; - -var Promize = require('native-or-bluebird'); - -module.exports = function PromiseDeferred() { - var deferred = {}; +'use strict' - deferred.promise = new Promize(function(resolve, reject) { - deferred.resolve = resolve; - deferred.reject = reject; - }); +var NativePromise = require('native-promise') - return deferred; -}; +/** + * Always will expose native `Promise` if available. + * Otherwise given promise module or Bluebird. + * + * **Example** + * + * ```js + * const fs = require('fs') + * const getPromise = require('native-or-another') + * const NativeOrBluebird = getPromise() + * const NativeOrPromise = getPromise(require('promise')) + * const NativeOrPinkie = getPromise(require('pinkie')) + * const NativeOrQ = getPromise(require('q')) + * + * const promise = new NativeOrBluebird((resolve, reject) => { + * fs.readFile('package.json', 'utf-8', (err, res) => { + * if (err) return reject(err) + * resolve(res) + * }) + * }) + * + * promise.then(data => { + * console.log(JSON.parse(data).name) + * //=> 'native-or-another' + * }) + * ``` + * + * @name nativeOrAnother + * @param {Function} `[Prome]` custom promise module + * @return {Function} native Promise or another + * @api public + */ +module.exports = function nativeOrAnother (Prome) { + if (NativePromise) return NativePromise + if (typeof Prome === 'function') { + Prome.___customPromise = true + return Prome + } + Prome = require('bluebird') + Prome.___bluebirdPromise = true + return Prome +} diff --git a/license.md b/license.md deleted file mode 100644 index 48dd3b4..0000000 --- a/license.md +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2014 [Charlike Make Reagent](http://j.mp/1stW47C), contributors - -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. \ No newline at end of file diff --git a/package.json b/package.json index 7ab0a4f..40b60fb 100644 --- a/package.json +++ b/package.json @@ -1,45 +1,32 @@ { "name": "native-or-another", "version": "2.0.0", - "description": "Export either the native Promise or Bluebird (using native-or-bluebird) as deferred object.", + "description": "Always will expose native `Promise` if available, otherwise `Bluebird` but only if you don't give another promise module like `q` or `promise` or what you want.", + "repository": "tunnckoCore/native-or-another", + "author": "Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)", + "main": "index.js", + "license": "MIT", "scripts": { - "lint": "jshint . && jscs . --reporter inline", - "test": "mocha", - "test-cov": "istanbul cover _mocha", - "test-travis": "istanbul cover _mocha --report lcovonly" + "test": "standard && node test.js" }, - "author": { - "name": "Charlike Make Reagent", - "email": "mameto_100@mail.bg", - "url": "https://github.com/tunnckoCore" + "dependencies": { + "bluebird": "^2.10.1", + "native-promise": "^1.0.0" }, - "repository": { - "type": "git", - "url": "git://github.com/tunnckoCore/native-or-another.git" + "devDependencies": { + "assertit": "^0.1.0", + "pinkie": "^1.0.0" }, + "files": [ + "index.js" + ], "keywords": [ - "aplus", + "always", + "always-promise", "bluebird", - "deferred", - "export", - "exports", + "custom", "native", - "object", - "promise", - "promises", - "promises-aplus" - ], - "license": { - "type": "MIT", - "url": "https://github.com/tunnckoCore/native-or-another/blob/master/license.md" - }, - "dependencies": { - "native-or-bluebird": "^1.1.2" - }, - "devDependencies": { - "bluebird": "^2.4.1", - "istanbul-harmony": "^0.3.1", - "mocha": "^2.0.1", - "mocha-lcov-reporter": "^0.0.1" - } + "pinkie", + "promise" + ] } diff --git a/readme.md b/readme.md deleted file mode 100644 index 3e096be..0000000 --- a/readme.md +++ /dev/null @@ -1,80 +0,0 @@ -[![npm version][npmjs-img]][npmjs-url] -[![mit license][license-img]][license-url] -[![build status][travis-img]][travis-url] -[![coverage status][coveralls-img]][coveralls-url] -[![deps status][daviddm-img]][daviddm-url] - -> Export either the native Promise or Bluebird (using native-or-bluebird) as deferred object. - - -## Install -```bash -$ npm install native-or-another -$ npm test -``` - - -## Usage -> For more use-cases see the [tests](./test.js) - -```js -var assert = require('assert'); -var Deferred = require('native-or-another'); -var defer = new Deferred(); - -defer.resolve(1); -defer.promise.then(function fulfilled(val) { - assert.strictEqual(val, 1); - done(); -}); - -// catching errors -defer.reject(new Error('custom error')); -defer.promise.catch(function rejected(err) { - assert.ok(err instanceof Error); - assert.strictEqual(err.message, 'custom error'); - done(); -}); -``` - - -## Author -**Charlike Mike Reagent** -+ [gratipay/tunnckoCore][author-gratipay] -+ [twitter/tunnckoCore][author-twitter] -+ [github/tunnckoCore][author-github] -+ [npmjs/tunnckoCore][author-npmjs] -+ [more ...][contrib-more] - - -## License [![MIT license][license-img]][license-url] -Copyright (c) 2014 [Charlike Mike Reagent][contrib-more], [contributors][contrib-graf]. -Released under the [`MIT`][license-url] license. - - -[npmjs-url]: http://npm.im/native-or-another -[npmjs-img]: https://img.shields.io/npm/v/native-or-another.svg?style=flat&label=native-or-another - -[coveralls-url]: https://coveralls.io/r/tunnckoCore/native-or-another?branch=master -[coveralls-img]: https://img.shields.io/coveralls/tunnckoCore/native-or-another.svg?style=flat - -[license-url]: https://github.com/tunnckoCore/native-or-another/blob/master/license.md -[license-img]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat - -[travis-url]: https://travis-ci.org/tunnckoCore/native-or-another -[travis-img]: https://img.shields.io/travis/tunnckoCore/native-or-another.svg?style=flat - -[daviddm-url]: https://david-dm.org/tunnckoCore/native-or-another -[daviddm-img]: https://img.shields.io/david/tunnckoCore/native-or-another.svg?style=flat - -[author-gratipay]: https://gratipay.com/tunnckoCore -[author-twitter]: https://twitter.com/tunnckoCore -[author-github]: https://github.com/tunnckoCore -[author-npmjs]: https://npmjs.org/~tunnckocore - -[contrib-more]: http://j.mp/1stW47C -[contrib-graf]: https://github.com/tunnckoCore/native-or-another/graphs/contributors - -*** - -_Powered and automated by [readdirp + hogan.js](https://github.com/tunnckoCore), December 21, 2014_ \ No newline at end of file diff --git a/test.js b/test.js index 5e5a9e6..21ea3f6 100644 --- a/test.js +++ b/test.js @@ -1,34 +1,39 @@ -/** +/*! * native-or-another * - * Copyright (c) 2014 Charlike Mike Reagent, contributors. + * Copyright (c) 2014-2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk) * Released under the MIT license. */ -'use strict'; +/* jshint asi:true */ -var assert = require('assert'); -var Deferred = require('./index'); +'use strict' -describe('require("native-or-another")', function() { - it('should return deferred Promise implementation', function(done) { - var defer = new Deferred(); +var test = require('assertit') +var getPromise = require('./index') - defer.resolve(1); - defer.promise.then(function fulfilled(val) { - assert.strictEqual(val, 1); - done(); - }); - }); +test('should use native Promise if available, Bluebird otherwise', function (done) { + var Promize = getPromise() + var promise = new Promize(function (resolve, reject) { + resolve(123) + }) - it('should catch errors correctly', function(done) { - var defer = new Deferred(); + promise.then(function (res) { + test.strictEqual(res, 123) + done() + }) +}) - defer.reject(new Error('custom error')); - defer.promise.catch(function rejected(err) { - assert.ok(err instanceof Error); - assert.strictEqual(err.message, 'custom error'); - done(); - }); - }); -}); +test('should use given custom promise module', function (done) { + var Promize = getPromise(require('pinkie')) + var promise = new Promize(function (resolve, reject) { + resolve(123) + }) + + promise.then(function (res) { + test.strictEqual(res, 123) + test.strictEqual(Promize.___customPromise, true) + done() + }) + done() +})