Skip to content

Commit

Permalink
add generators tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Oct 1, 2015
1 parent a9a822c commit ab2ffcf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"bluebird": "^2.10.1",
"mz": "^2.0.0",
"rx": "^4.0.0",
"semver": "^5.0.3",
"simple-get": "^1.4.3",
"through2": "^2.0.0"
},
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'use strict'

var test = require('assertit')
var semver = require('semver')

test('errors', function (done) {
require('./test/errors')
Expand Down Expand Up @@ -45,3 +46,10 @@ test('child processes', function (done) {
require('./test/child_processes')
done()
})

if (semver.gte(process.version, '0.11.13')) {
test('generators', function (done) {
require('./test/generators')
done()
})
}
41 changes: 41 additions & 0 deletions test/generators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*!
* coone <https://github.com/hybridables/coone>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/

/* jshint asi:true */

'use strict'

var mzfs = require('mz/fs')
var test = require('assertit')
var coone = require('../index')

function * success () {
return yield mzfs.readFile('package.json', 'utf8')
}

function * failure () {
return yield mzfs.readFile('foobar.json')
}

test('should handle successful generator function', function (done) {
coone(success)(function (err, res) {
test.ifError(err)
test.strictEqual(typeof res, 'string')
test.ok(res.indexOf('"license": "MIT"') !== -1)
done()
})
})

test('should handle generator function errors', function (done) {
coone(failure)(function (err, res) {
test.ifError(!err)
test.ok(err instanceof Error)
test.strictEqual(err.code, 'ENOENT')
test.strictEqual(res, undefined)
done()
})
})

0 comments on commit ab2ffcf

Please sign in to comment.