Skip to content

Commit

Permalink
Improved API to make config optional
Browse files Browse the repository at this point in the history
Added tests for TestRunner
  • Loading branch information
marc-ed-raffalli committed Mar 21, 2018
1 parent 9fbbc9d commit fe3f38a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 7 deletions.
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
const TestRunner = require('./src/TestRunner');

module.exports = (app, config, testSuiteDefinition) => {
new TestRunner(config)
.run(app, testSuiteDefinition);
TestRunner.run(app, config, testSuiteDefinition);
};
4 changes: 4 additions & 0 deletions src/TestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ module.exports = class TestConfig {
return Object.assign({}, {url: '/api/users/login'}, this.config.auth);
}

static make(config) {
return new TestConfig(config);
}

};
13 changes: 8 additions & 5 deletions src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ const TestSuite = require('./TestSuite'),

class TestRunner {

constructor(config) {
this.config = new TestConfig(config);
}
static run(app, config, testSuiteDefinition = {}) {
if (arguments.length === 2) {
config = {};
testSuiteDefinition = arguments[1];
}

config = TestConfig.make(config);

run(app, testSuiteDefinition = {}) {
TestSuite.generate(testSuiteDefinition, this.config)
TestSuite.generate(testSuiteDefinition, config)
.forEach(testSuite => testSuite.run(app));
}

Expand Down
62 changes: 62 additions & 0 deletions src/TestRunner.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

const expect = require('chai').expect,
sinon = require('sinon');

const TestRunner = require('./TestRunner'),
TestConfig = require('./TestConfig'),
TestSuite = require('./TestSuite');

describe('TestRunner', () => {

describe('run', () => {

let testStubs,
config, def, configStub;

beforeEach(() => {
testStubs = [];
config = {config: 123};
def = {def: 123};
configStub = 'configStub';

sinon.stub(TestSuite, 'generate').callsFake(() => testStubs);
sinon.stub(TestConfig, 'make').returns(configStub);
});

afterEach(() => {
TestSuite.generate.restore();
TestConfig.make.restore();
});

it('calls generate with test suite and config', () => {
TestRunner.run('app', config, def);

expect(TestSuite.generate.calledOnce).to.be.true;
expect(TestSuite.generate.calledWithExactly(def, configStub)).to.be.true;
});

it('calls generate with test suite and default config', () => {
TestRunner.run('app', def);

expect(TestSuite.generate.calledOnce).to.be.true;
expect(TestSuite.generate.calledWithExactly(def, configStub)).to.be.true;
});

it('calls run(app) on every generated test suites', () => {
testStubs = [
{run: sinon.spy()},
{run: sinon.spy()}
];

TestRunner.run('app', config, def);

testStubs.forEach(stub => {
expect(stub.run.calledOnce).to.be.true;
expect(stub.run.calledWithExactly('app')).to.be.true;
});
});

});

});

0 comments on commit fe3f38a

Please sign in to comment.