Skip to content

Commit

Permalink
feat(*): initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Mar 31, 2017
1 parent 5181e62 commit bae50c3
Show file tree
Hide file tree
Showing 10 changed files with 631 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
@@ -0,0 +1,17 @@
# editorconfig.org
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.edge]
insert_final_newline = false
trim_trailing_whitespace=false
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
coverage
node_modules
.DS_Store
npm-debug.log
.idea
dump.rdb
11 changes: 11 additions & 0 deletions .npmignore
@@ -0,0 +1,11 @@
coverage
node_modules
.DS_Store
npm-debug.log
test
dump.rdb
.travis.yml
.editorconfig
benchmarks
.idea
bin
15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
# Japa CLI

The CLI runner for [https://github.com/thetutlage/japa](Japa).

## Usage

```bash
npm i -g japa-cli

# Help
japa --help

# Run tests
japa
```
134 changes: 134 additions & 0 deletions index.js
@@ -0,0 +1,134 @@
'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._timeout = null
this._grep = null
this._bail = false

// public
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('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
}

/**
* 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(`japaCli.run excepts glob pattern to be a string. You passed ${typeof (glob)}`)
}

this.testsGlob = glob
}
}

module.exports = new JapaCli()
45 changes: 45 additions & 0 deletions package.json
@@ -0,0 +1,45 @@
{
"name": "japa-cli",
"version": "1.0.0",
"description": "const japaCli = require('japaCli')",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "amanvirk,adonisjs",
"license": "MIT",
"dependencies": {
"commander": "^2.9.0",
"globby": "^6.1.0"
},
"devDependencies": {
"clear-require": "^2.0.0",
"cz-conventional-changelog": "^2.0.0",
"japa": "^1.0.1",
"pify": "^2.3.0"
},
"directories": {
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/thetutlage/japa-cli.git"
},
"keywords": [
"japa",
"test-runner",
"tests"
],
"bugs": {
"url": "https://github.com/thetutlage/japa-cli/issues"
},
"bin": {
"japa": "./src/bin.js"
},
"homepage": "https://github.com/thetutlage/japa-cli#readme",
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}

0 comments on commit bae50c3

Please sign in to comment.