Muthu Kumar
7 years ago
7 changed files with 127 additions and 4 deletions
@ -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); |
|||
``` |
After Width: | Height: | Size: 67 KiB |
@ -0,0 +1 @@ |
|||
module.exports = require('./gunner'); |
@ -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…
Reference in new issue