Browse Source

[docs] Added basic README & utility helpers

0.7.0-breaking-rewrite
Muthu Kumar 6 years ago
parent
commit
43f12a7ec9
  1. 6
      .eslintrc.js
  2. 62
      README.md
  3. BIN
      assets/gun.jpeg
  4. 2
      gunner/index.js
  5. 1
      index.js
  6. 5
      package.json
  7. 55
      util/helpers.js

6
.eslintrc.js

@ -1,8 +1,11 @@
module.exports = { module.exports = {
"parserOptions": {
"ecmaVersion": 2018,
},
"env": { "env": {
"commonjs": true, "commonjs": true,
"es6": true, "es6": true,
"node": true "node": true,
}, },
"extends": "eslint:recommended", "extends": "eslint:recommended",
"rules": { "rules": {
@ -13,6 +16,7 @@ module.exports = {
"no-unneeded-ternary": "error", "no-unneeded-ternary": "error",
"no-console": "off", "no-console": "off",
"no-undef": "off", "no-undef": "off",
'comma-dangle': [ 'error', 'only-multiline' ],
"indent": [ "indent": [
"error", "error",
"tab", "tab",

62
README.md

@ -0,0 +1,62 @@
# Gunner
<img alt="Django Unchained" src="assets/gun.jpeg" height="350" />
#### _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);
```

BIN
assets/gun.jpeg

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

2
gunner/index.js

@ -38,4 +38,4 @@ class Gunner {
} }
module.exports = Gunner; module.exports = Gunner;
module.exports.assert = _expect; module.exports.expect = _expect;

1
index.js

@ -0,0 +1 @@
module.exports = require('./gunner');

5
package.json

@ -13,10 +13,11 @@
"keywords": [ "keywords": [
"klenty", "klenty",
"test", "test",
"mocha" "tdd",
"unit testing"
], ],
"author": "Muthu Kumar <@MKRhere> (https://mkr.pw)", "author": "Muthu Kumar <@MKRhere> (https://mkr.pw)",
"license": "ISC", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/vengatkrishnaraj/testsuite/issues" "url": "https://github.com/vengatkrishnaraj/testsuite/issues"
}, },

55
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),
};
Loading…
Cancel
Save