Skip to content

Commit

Permalink
Merge branch 'release-1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Apr 1, 2017
2 parents f1eed67 + e51248a commit be74183
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 5 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,13 @@
<a name="1.0.2"></a>
## [1.0.2](https://github.com/thetutlage/japa/compare/v1.0.1...v1.0.2) (2017-04-01)


### Features

* **cli:** add cli file to be used for configuring test files ([3b47016](https://github.com/thetutlage/japa/commit/3b47016))



<a name="1.0.1"></a>
## [1.0.1](https://github.com/thetutlage/japa/compare/v1.0.0...v1.0.1) (2017-02-23)

Expand Down
4 changes: 0 additions & 4 deletions caller.js

This file was deleted.

85 changes: 85 additions & 0 deletions cli.js
@@ -0,0 +1,85 @@
'use strict'

/*
* japa-cli
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

class JapaCli {
constructor () {
this._initiate()
}

/**
* Initiate private and public properties
*
* @method _initiate
*
* @return {void}
*
* @private
*/
_initiate () {
this.filterCallback = null
this.ignorePattern = []
this.testsGlob = 'test/*.spec.js'
}

/**
* Filter files to be used for running the tests. You can
* return a string, an array of globs or a function
* which is called for each file.
*
* @method filter
*
* @param {String|Array|Function} patternOrCallback
*
* @chainable
*/
filter (patternOrCallback) {
if (typeof (patternOrCallback) === 'function') {
this.filterCallback = patternOrCallback
return this
}

if (typeof (patternOrCallback) === 'string') {
this.ignorePattern = [patternOrCallback]
return this
}

if (patternOrCallback instanceof Array === true) {
this.ignorePattern = patternOrCallback
return this
}

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

/**
* Set the glob to be used for picking tests
* files and then running the tests.
*
* @method run
*
* @param {String} glob
*
* @return {void}
*/
run (glob) {
if (!glob) {
return
}

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

this.testsGlob = glob
}
}

module.exports = new JapaCli()
4 changes: 4 additions & 0 deletions examples/caller.js
@@ -0,0 +1,4 @@
'use strict'

require('./string.spec.js')
require('./fizzbuzz.spec.js')
2 changes: 2 additions & 0 deletions index.js
Expand Up @@ -10,6 +10,7 @@
*/

const runner = new (require('./src/Runner'))()
const cli = require('./cli')

const nextTick = typeof (setImmediate) !== 'undefined' ? setImmediate : process.nextTick

Expand All @@ -32,3 +33,4 @@ exports.timeout = runner.timeout.bind(runner)
exports.use = runner.use.bind(runner)
exports.bail = runner.bail.bind(runner)
exports.grep = runner.grep.bind(runner)
exports.cli = cli
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "japa",
"version": "1.0.1",
"version": "1.0.2",
"description": "Japa is a batteries included minimal testing framework for Node.Js. Japa does not have any cli to run your tests, infact running the test file as a node script will execute the tests for you (quite similar to tape)",
"main": "index.js",
"directories": {
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 be74183

Please sign in to comment.