Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
add tests for gemini-facade and fix tests in plugins.js
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Sep 7, 2016
1 parent 1c1e195 commit 55e82aa
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 17 deletions.
72 changes: 72 additions & 0 deletions test/unit/gemini-facade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'use strict';

const EventEmitter = require('events').EventEmitter;

const _ = require('lodash');

const GeminiFacade = require('lib/gemini-facade');
const RunnerEvents = require('lib/constants/runner-events');

describe('gemini-facade', () => {
const sandbox = sinon.sandbox.create();

let facade;
let gemini;
let runner;

beforeEach(() => {
gemini = new EventEmitter();
runner = new EventEmitter();
});

afterEach(() => sandbox.restore());

it('should provide access to passed config', () => {
gemini.config = {rootUrl: 'http://localhost'};

facade = new GeminiFacade(gemini);

assert.equal(facade.config, gemini.config);
});

it('should provide access to events', () => {
facade = new GeminiFacade(gemini);

assert.deepEqual(facade.events, RunnerEvents);
});

it('should RUNNER_START event be listen by gemini inst', () => {
sandbox.spy(gemini, 'on');

facade = new GeminiFacade(gemini);

assert.calledWith(gemini.on, 'startRunner');
});

it('should emit RUNNER_START event by facade after it was emitted by gemini inst', () => {
facade = new GeminiFacade(gemini);

sandbox.spy(facade, 'emit');

gemini.emit('startRunner', runner);

assert.calledWithExactly(facade.emit, 'startRunner', runner);
});

it('should passthrough all runner events', () => {
let spy;

facade = new GeminiFacade(gemini);

gemini.emit('startRunner', runner);

_.forEach(RunnerEvents, (event, name) => {
spy = sinon.spy().named(name + ' handler');
facade.on(event, spy);

runner.emit(event);

assert.calledOnce(spy);
});
});
});
41 changes: 24 additions & 17 deletions test/unit/plugins.test.js → test/unit/plugins.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';
var plugins,
proxyquire = require('proxyquire');

const proxyquire = require('proxyquire');

let plugins;

describe('plugins', function() {
beforeEach(function() {
Expand All @@ -16,53 +18,58 @@ describe('plugins', function() {

describe('load', function() {
it('should load plugin without prefix', function() {
var options = {system: {plugins: {foobar: true}}};
plugins.load(this.gemini, options);
this.gemini.config = {system: {plugins: {foobar: true}}};

plugins.load(this.gemini);

assert.calledWith(this.foobarPlugin, this.gemini, {});
});

it('should load plugin with prefix', function() {
var options = {system: {plugins: {'gemini-foobar': true}}};
plugins.load(this.gemini, options);
this.gemini.config = {system: {plugins: {'gemini-foobar': true}}};

plugins.load(this.gemini);

assert.calledWith(this.foobarPlugin, this.gemini, {});
});

it('should throw error if plugin not found', function() {
var options = {system: {plugins: {'gemini-foo': true}}};
this.gemini.config = {system: {plugins: {'gemini-foo': true}}};

assert.throws(function() {
plugins.load(this.gemini, options);
plugins.load(this.gemini);
});
});

it('should not load disabled plugins', function() {
var options = {system: {plugins: {foobar: false}}};
plugins.load(this.gemini, options);
this.gemini.config = {system: {plugins: {foobar: false}}};

plugins.load(this.gemini);

assert.notCalled(this.foobarPlugin);
});

it('should load plugin with empty configuration', function() {
var options = {system: {plugins: {foobar: {}}}};
plugins.load(this.gemini, options);
this.gemini.config = {system: {plugins: {foobar: {}}}};

plugins.load(this.gemini);

assert.calledWith(this.foobarPlugin, this.gemini, {});
});

it('should handle empty plugins', function() {
var _this = this,
options = {system: {plugins: {}}};
var _this = this;
this.gemini.config = {system: {plugins: {}}};

assert.doesNotThrow(function() {
plugins.load(_this.gemini, options);
plugins.load(_this.gemini);
});
});

it('should pass plugin its configuration', function() {
var options = {system: {plugins: {foobar: {foo: 'bar'}}}};
plugins.load(this.gemini, options);
this.gemini.config = {system: {plugins: {foobar: {foo: 'bar'}}}};

plugins.load(this.gemini);

assert.calledWith(this.foobarPlugin, this.gemini, {foo: 'bar'});
});
Expand Down

0 comments on commit 55e82aa

Please sign in to comment.