Skip to content

Commit

Permalink
fix(sync): fix synchronous completion
Browse files Browse the repository at this point in the history
nah... mukla like to hide some tests some times - no errors, no completion and even not shown...
  • Loading branch information
tunnckoCore committed Nov 1, 2016
1 parent 1fd637c commit 58c704b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Expand Up @@ -68,15 +68,16 @@ function tryCatch (fn, opts, cb) {
if (typeof cb !== 'function') {
throw new TypeError('try-catch-core: expect `cb` to be a function')
}
cb = utils.isAsync(fn)
var isAsyncFn = utils.isAsync(fn)
cb = isAsyncFn
? utils.once(utils.dezalgo(cb))
: utils.once(cb)
opts = opts && typeof opts === 'object'
? opts
: {}
opts.passCallback = typeof opts.passCallback === 'boolean'
? opts.passCallback
: true
: isAsyncFn // if `fn` is async, pass callback automatically

utils.tryCatchCallback.call(this, fn, opts, cb)
}
10 changes: 10 additions & 0 deletions test.js
Expand Up @@ -94,6 +94,16 @@ test('should pass result from `fs.readFile` to the callback', function (done) {
})
})

test('should get result of `fs.readFileSync`', function (done) {
tryCatchCore(function () {
return fs.readFileSync('./README.md', 'utf8')
}, function (err, res) {
test.strictEqual(err, null)
test.strictEqual(res.indexOf('try-catch-core') !== -1, true)
done()
})
})

test('should be able to pass custom arguments through options', function (done) {
tryCatchCore(function (foo, bar, next) {
test.strictEqual(arguments.length, 3)
Expand Down

0 comments on commit 58c704b

Please sign in to comment.