diff --git a/.eslintrc.js b/.eslintrc.js index 115ae27..4750fac 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,8 +1,11 @@ module.exports = { + "parserOptions": { + "ecmaVersion": 2018, + }, "env": { "commonjs": true, "es6": true, - "node": true + "node": true, }, "extends": "eslint:recommended", "rules": { @@ -13,6 +16,7 @@ module.exports = { "no-unneeded-ternary": "error", "no-console": "off", "no-undef": "off", + 'comma-dangle': [ 'error', 'only-multiline' ], "indent": [ "error", "tab", diff --git a/README.md b/README.md new file mode 100644 index 0000000..d939d6d --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# Gunner + +Django Unchained + +#### _Tiny, but fully loaded._ + +> Gunner is a zero magic, fast test-runner and assertion framework. There are no magic globals or CLI specific interface. + +## Usage + +Create a new `Gunner` instance and simply write your tests. The assertion methods are passed in as the callback to the test function. + +```JavaScript +const gunner = new Gunner(); + +gunner.test('arrays are equal', expect => { + return expect([1, 2,]).deepEqual([1 ,2]); +}); + +gunner.run(); +``` + +## API + +--- +### [new Gunner(options)](#gunner-constructor) +### [Gunner#test(title, implementation)](#gunnertest) +### [Gunner#run(options)](#gunnerrun) +--- + +### Gunner constructor + +Creates a new Gunner instance. + +#### Usage + +```JavaScript +const gunner = new Gunner(options); +``` + +### Gunner#test + +Registers a new test. + +#### Usage + +```JavaScript +gunner.test('sum should equal 3', expect => { + const sum = 1 + 2; + return expect(sum).equal(3); +}); +``` + +### Gunner#run + +Starts running Gunner tests. + +#### Usage + +```JavaScript +gunner.run(options); +``` diff --git a/assets/gun.jpeg b/assets/gun.jpeg new file mode 100644 index 0000000..7b60ac8 Binary files /dev/null and b/assets/gun.jpeg differ diff --git a/gunner/index.js b/gunner/index.js index 4c7d67c..b52dc5a 100644 --- a/gunner/index.js +++ b/gunner/index.js @@ -38,4 +38,4 @@ class Gunner { } module.exports = Gunner; -module.exports.assert = _expect; +module.exports.expect = _expect; diff --git a/index.js b/index.js new file mode 100644 index 0000000..cca91cd --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +module.exports = require('./gunner'); \ No newline at end of file diff --git a/package.json b/package.json index f6848b5..a8263fa 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,11 @@ "keywords": [ "klenty", "test", - "mocha" + "tdd", + "unit testing" ], "author": "Muthu Kumar <@MKRhere> (https://mkr.pw)", - "license": "ISC", + "license": "MIT", "bugs": { "url": "https://github.com/vengatkrishnaraj/testsuite/issues" }, diff --git a/util/helpers.js b/util/helpers.js new file mode 100644 index 0000000..37ab55b --- /dev/null +++ b/util/helpers.js @@ -0,0 +1,55 @@ +module.exports = { + + /* Flattens an array of arrays to an array */ + flatten : arrData => [].concat.apply([], arrData), + + /* Maps a function over an array */ + map : fn => x => x.map(fn), + + /* Returns identity */ + identity : x => x, + + /* Wraps a value in an object with given key */ + wrapWith : x => y => ({ [x] : y }), + + /* Unwraps a value from an object with given key */ + unwrapFrom : x => y => y[x], + + /* Resolves an array of Promises */ + promiseAll : x => Promise.all(x), + + /* Pipe a value or promise through any number of unary functions */ + pipe: (...fns) => + arg => fns.reduce((acc, fn) => + typeof acc.then === 'function' + ? acc.then(fn) + : fn(acc), arg), + + /* Pass partial arguments and return a function that accepts the rest */ + partial: (fn, ...args) => (...rest) => fn(...args, ...rest), + + /* Item is in collection */ + isIn : (collection, item) => collection.indexOf(item) !== -1, + + /* Collection contains given path */ + containsPath : (collection, path) => collection.some( + x => path.match(new RegExp(`/${x}/?$`)) + ), + + /* Lift promises into a function */ + liftPromise : (fn, thing) => + typeof thing.then === 'function' + ? thing.then(fn) + : fn(thing), + + /* Stringifies object or coerces to string */ + stringify : obj => + typeof obj === 'object' + ? (obj.stack || JSON.stringify(obj)) + : obj, + + /* Short circuits with given value on pred. Else calls function */ + short : (pred, shorter) => + fn => value => pred(value) ? shorter(value) : fn(value), + +};