Skip to content

Commit

Permalink
test(cli): add cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Apr 1, 2017
1 parent 3b47016 commit f9db00b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 51 deletions.
53 changes: 2 additions & 51 deletions cli.js
Expand Up @@ -24,11 +24,6 @@ class JapaCli {
* @private
*/
_initiate () {
this._timeout = null
this._grep = null
this._bail = false

// public
this.filterCallback = null
this.ignorePattern = []
this.testsGlob = 'test/*.spec.js'
Expand Down Expand Up @@ -61,51 +56,7 @@ class JapaCli {
return this
}

throw new Error('japaCli.filter only excepts a glob string, array or a callback function')
}

/**
* Set global timeout on each test
*
* @method timeout
*
* @param {Number} timeout
*
* @chainable
*/
timeout (timeout) {
this._timeout = Number(timeout)
return this
}

/**
* Whether or not to exist tests earlier. Passed
* to japa runner
*
* @method bail
*
* @param {Boolean} status
*
* @chainable
*/
bail (status) {
this._bail = !!status
return this
}

/**
* The pattern to be used for grepping over
* tests. Passed to japa runner
*
* @method grep
*
* @param {String} pattern
*
* @chainable
*/
grep (pattern) {
this._grep = pattern
return this
throw new Error('cli.filter only excepts a glob string, array or a callback function')
}

/**
Expand All @@ -124,7 +75,7 @@ class JapaCli {
}

if (typeof (glob) !== 'string') {
throw new Error(`japaCli.run excepts glob pattern to be a string. You passed ${typeof (glob)}`)
throw new Error(`cli.run excepts glob pattern to be a string. You passed ${typeof (glob)}`)
}

this.testsGlob = glob
Expand Down
54 changes: 54 additions & 0 deletions test/cli.spec.js
@@ -0,0 +1,54 @@
'use strict'

const test = require('tape')
const cli = require('../cli')

test('allow a string to be ignored', (assert) => {
assert.plan(1)
cli.filter('foo.js')
assert.deepEqual(cli.ignorePattern, ['foo.js'])
cli._initiate()
})

test('allow an array of globs to be ignored', (assert) => {
assert.plan(1)
cli.filter(['foo.js', 'bar.js'])
assert.deepEqual(cli.ignorePattern, ['foo.js', 'bar.js'])
cli._initiate()
})

test('allow a callback to be passed to filter fn', (assert) => {
assert.plan(2)
cli.filter(function () {})
assert.equal(typeof (cli.filterCallback), 'function')
assert.equal(cli.ignorePattern.length, 0)
cli._initiate()
})

test('throw exception when filter param is not an array,string of fn', (assert) => {
assert.plan(1)
try {
cli.filter({})
} catch (error) {
assert.equal(error.message, 'cli.filter only excepts a glob string, array or a callback function')
cli._initiate()
}
})

test('set glob pattern for test files', (assert) => {
assert.plan(2)
assert.equal(cli.testsGlob, 'test/*.spec.js')
cli.run('test/**/*.js')
assert.equal(cli.testsGlob, 'test/**/*.js')
cli._initiate()
})

test('throw exception when pattern is not a string', (assert) => {
assert.plan(1)
try {
cli.run(['test/**/*.js'])
} catch (error) {
assert.equal(error.message, 'cli.run excepts glob pattern to be a string. You passed object')
cli._initiate()
}
})

0 comments on commit f9db00b

Please sign in to comment.