Skip to content

Commit

Permalink
Fixing Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryDodzin committed May 7, 2019
1 parent e79f395 commit 18360ac
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 249 deletions.
14 changes: 9 additions & 5 deletions lib/common/runner.js
Expand Up @@ -9,11 +9,15 @@ const mRunnable = Symbol('runable');
*/
class Runner {

constructor(argument) {
if (typeof argument === 'function'){
this[mRunnable] = new Runable(argument)
} else if (argument instanceof Runable) {
this[mRunnable] = argument
constructor(...params) {
if (!params[0]) {
throw new Error('Runner Must be Inintialized with Runnable or a function')
}

if (typeof params[0] === 'function'){
this[mRunnable] = new Runable(...params)
} else if (params[0] instanceof Runable) {
this[mRunnable] = params[0]
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"clean": "rm -rf dist docs",
"prebuild": "yarn clean",
"test": "mocha --require babel-core/register",
"test": "mocha --require @babel/register",
"build": "yarn build-babel && yarn build-docs",
"build-babel": "babel lib --out-dir dist",
"build-docs": "jsdoc --readme DOCS.md -c .jsdocrc -d ./docs/ -r",
Expand Down
8 changes: 4 additions & 4 deletions test/creators.test.js
Expand Up @@ -6,8 +6,8 @@ import { expect, assert } from 'chai';
import Joker from '../lib/common/joker';
import Runner from '../lib/common/runner';

import ApiFactoryGenerator from '../lib/creators/api.factory.creator';
import JokerFactoryGenerator from '../lib/creators/joker.factory.creator';
import RunnerFactoryGenerator from '../lib/creators/runner.factory.creator';

const Randomizer = new Chance();

Expand Down Expand Up @@ -47,15 +47,15 @@ describe('Creators', () => {

it('Init', () => {

expect(() => new RunnerFactoryGenerator()).to.not.throw();
expect(() => new RunnerFactoryGenerator(Randomizer)).to.not.throw();
expect(() => new ApiFactoryGenerator()).to.not.throw();
expect(() => new ApiFactoryGenerator(Randomizer)).to.not.throw();

});

it('Create will fill Runners', () => {

let factory = {};
let jfg = new RunnerFactoryGenerator(Randomizer);
let jfg = new ApiFactoryGenerator(Randomizer);

jfg.create(factory);

Expand Down
88 changes: 0 additions & 88 deletions test/function.runner.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/monkey.test.js
Expand Up @@ -20,8 +20,8 @@ describe('Monkey', () => {
const monkey = __requireUncached('../lib/monkey');

expect(monkey).to.have.property('randomiser');
expect(monkey).to.have.property('ApiCreator');
expect(monkey).to.have.property('JokerCreator');
expect(monkey).to.have.property('RunnerCreator');
});

it('Random Seed for Randmosizer', () => {
Expand Down
91 changes: 0 additions & 91 deletions test/piped.runner.test.js

This file was deleted.

63 changes: 4 additions & 59 deletions test/runnable.test.js
Expand Up @@ -18,32 +18,28 @@ describe('Runnable', () => {

it('Calling', () => {
let fn = sinon.spy();
let params = [1, 2, 3];
let runable = new Runable(fn, params);
let runable = new Runable(fn);

runable.call().should.eventually.be.fulfilled
.then(() => assert(fn.calledOnce));
});

it('Sync', () => {
let params = [11];
let returnValue = "Working";
let fn = (value) => {
expect(value).to.equal(params[0]);
let fn = () => {
return returnValue;
};

let runable = new Runable(fn, params);
let runable = new Runable(fn);
return runable.call().should.eventually.have.property('value', returnValue);
});

it('Sync fail', () => {
let params = [11];
let fn = (value) => {
expect(value).to.equal("something else");
};

let runable = new Runable(fn, params);
let runable = new Runable(fn);
return runable.call().should.eventually.be.rejected;
});

Expand Down Expand Up @@ -105,55 +101,4 @@ describe('Runnable', () => {
.should.eventually.have.property('value', someValue);
});

it('Extract Joker Params', () => {
let fakeChance = { bool: () => false };
let joker_value = 'Some Value';
let joker = new Joker(fakeChance);
sinon.stub(joker, 'getValue').returns(joker_value);

let params = [joker];
let fn = sinon.spy();

let runable = new Runable(fn, params);
return runable.call()
.should.eventually.be.fulfilled
.then(() => assert(fn.calledWith(joker_value), 'Joker value wasn\'t called'));
});

it('Extract Joker Params With Args', () => {
let jokerValue = 'Some Value';
let someValue = 'Some Value 2';
let fakeChance = { bool: () => false };
let joker = new Joker(fakeChance);
sinon.stub(joker, 'getValue').returns(jokerValue);

let params = [joker];
let fn = sinon.spy();

let runable = new Runable(fn, params);
return runable.call(someValue)
.should.eventually.be.fulfilled
.then(() => assert(fn.calledWith(someValue, jokerValue), 'Joker value wasn\'t called with the right params'));
});

it('Internal Error', () => {
let fakeChance = { bool: () => false };
let joker_value = 'Some Value';
let joker = new Joker(fakeChance);
sinon.stub(joker, 'getValue').throws(new Error('Hey'));

let params = [joker];

let runable = new Runable(() => {}, params);

let extend = { hey: 'ho' };

return runable.call(null, extend)
.should.eventually.be.rejected
.then(res => {
expect(res).to.nested.include({'err.message': 'Hey'});
expect(res.extend).to.deep.equal(extend);
});
});

});

0 comments on commit 18360ac

Please sign in to comment.