From 658142adcb6a924fd0ff4e0c8c042443a9c72fc9 Mon Sep 17 00:00:00 2001 From: tunnckoCore Date: Fri, 15 Jan 2016 21:06:48 +0200 Subject: [PATCH] complexity reported by @codeclimate --- CHANGELOG.md | 48 ------------------------------------------------ test.js | 22 +++------------------- 2 files changed, 3 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 468815c..b2e4d80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,54 +32,6 @@ + or custom passed promise module constructor + or Bluebird constructor -**example** - -```js -'use strict' - -var fs = require('fs') -var redolent = require('redolent') -var readFile = redolent(fs.readFileSync, require('q')) -var promise = readFile('package.json', 'utf8') - -console.log(promise.Prome) -//=> `q` constructor (if native promise not available) -// or native promise constructor -console.log(promise.Prome.___customPromise) //=> true -console.log(promise.___customPromise) //=> true -``` - -- allow passing custom promise module through static properties - + till now it was able to do this only if you pass promise module as second argument - -**example** - -```js -'use strict' - -var fs = require('fs') -var redolent = require('redolent') - -// `pinkie` is promise module -// will use `pinkie` if not native promise is available -redolent.promise = require('pinkie') - -var readFile = redolent(fs.readFileSync) - -// will use `q` promise if native not available -// readFile.promise = require('q') - -var promise = readFile('package.json') -promise.then(function (res) { - console.log(res) //=> Buffer - console.log(promise.Prome) - //=> `pinkie` constructor (if native promise not available) - // or native promise constructor - console.log(promise.Prome.___customPromise) //=> true - console.log(promise.___customPromise) //=> true -}) -``` - ## 1.0.0 - 2015-09-28 - Release v1.0.0 / npm@v1.0.0 - implement :cat2: diff --git a/test.js b/test.js index 666922e..24d2a7c 100644 --- a/test.js +++ b/test.js @@ -33,10 +33,7 @@ function multipleArgs (one, two, three, cb) { test('should not throw TypeError if falsey value given', function (done) { redolent(false)().then(function (bool) { test.strictEqual(bool, false) - return redolent(null)().then(function (empty) { - test.strictEqual(empty, null) - done() - }) + done() }, done) }) @@ -139,7 +136,7 @@ test('should not skip last argument and work core api (fs.readFileSync)', functi }) test('should not skip if pass callback fn, e.g. fn(err, res) as last argument', function (done) { - function foo (_err, res) {} + function foo (_err, res) { return [_err, res] } redolent(function (one, fn, cb) { cb(null, one, fn) })(123, foo).then(function (res) { @@ -149,17 +146,6 @@ test('should not skip if pass callback fn, e.g. fn(err, res) as last argument', }) }) -test('should promisify sync function `fs.readFileSync` and handle utf8 result', function (done) { - var promise = redolent(fs.readFileSync)('package.json', 'utf8') - - promise - .then(JSON.parse) - .then(function (res) { - test.strictEqual(res.name, 'redolent') - done() - }, done) -}) - test('should promisify `fs.readFileSync` and handle buffer result', function (done) { var readFile = redolent(fs.readFileSync) readFile('package.json').then(function (buf) { @@ -169,9 +155,7 @@ test('should promisify `fs.readFileSync` and handle buffer result', function (do }) test('should catch errors from failing sync function', function (done) { - var promise = redolent(fs.readFileSync)('foobar.json', 'utf8') - - promise + redolent(fs.readFileSync)('foobar.json', 'utf8') .catch(function (err) { test.strictEqual(err.code, 'ENOENT') test.strictEqual(/no such file or directory/.test(err.message), true)