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

Commit

Permalink
Merge pull request #645 from gemini-testing/plugins-loader
Browse files Browse the repository at this point in the history
refactor: use module 'plugins-loader'
  • Loading branch information
eGavr committed Oct 19, 2016
2 parents 627df70 + 6beef15 commit 4753c86
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 112 deletions.
5 changes: 4 additions & 1 deletion lib/gemini.js
Expand Up @@ -6,6 +6,7 @@ const _ = require('lodash');
const PassthroughEmitter = require('./passthrough-emitter');
const Promise = require('bluebird');
const q = require('bluebird-q');
const pluginsLoader = require('plugins-loader');

const Config = require('./config');
const GeminiError = require('./errors/gemini-error');
Expand All @@ -17,6 +18,8 @@ const StateProcessor = require('./state-processor');
const SuiteCollection = require('./suite-collection');
const temp = require('./temp');

const PREFIX = require('../package').name + '-';

// Hack for node@0.10 and lower
// Remove restriction for maximum open concurrent sockets
require('http').globalAgent.maxSockets = Infinity;
Expand Down Expand Up @@ -94,7 +97,7 @@ module.exports = class Gemini extends PassthroughEmitter {
}

_loadPlugins() {
require('./plugins').load(this);
pluginsLoader.load(this, this.config.system.plugins, PREFIX);
}

readTests(paths, options) {
Expand Down
20 changes: 0 additions & 20 deletions lib/plugins.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -31,6 +31,7 @@
"looks-same": "^3.0.0",
"micromatch": "^2.3.11",
"node-fetch": "^1.6.3",
"plugins-loader": "^1.0.1",
"png-img": "^2.1.0",
"polyfill-service": "~1.4.0",
"q-promise-utils": "^1.1.0",
Expand Down
46 changes: 37 additions & 9 deletions test/unit/gemini.js
Expand Up @@ -4,9 +4,9 @@ const EventEmitter = require('events').EventEmitter;
const _ = require('lodash');
const proxyquire = require('proxyquire');
const Promise = require('bluebird');
const pluginsLoader = require('plugins-loader');

const Config = require('lib/config');
const plugins = require('lib/plugins');
const Runner = require('lib/runner');
const Events = require('lib/constants/events');
const SuiteCollection = require('lib/suite-collection');
Expand All @@ -29,6 +29,8 @@ describe('gemini', () => {
};

const initGemini = (opts) => {
opts = opts || {};

opts.rootSuite = opts.rootSuite || mkSuiteStub();

testReaderStub = sandbox.stub().named('TestReader').returns(Promise.resolve(opts.rootSuite));
Expand All @@ -39,7 +41,8 @@ describe('gemini', () => {
rootUrl: 'http://localhost',
system: {
projectRoot: 'stub/project/root',
tempDir: opts.tempDir || 'stub/temp/dir'
tempDir: opts.tempDir || 'stub/temp/dir',
plugins: opts.plugins || {}
},
browsers: opts.browserIds ? stubBrowsers(opts.browserIds) : []
});
Expand All @@ -60,7 +63,7 @@ describe('gemini', () => {
sandbox.stub(Runner.prototype, 'on').returnsThis();
sandbox.stub(Runner.prototype, 'run').returns(Promise.resolve());
sandbox.stub(console, 'warn');
sandbox.stub(plugins, 'load');
sandbox.stub(pluginsLoader, 'load');
});

afterEach(() => sandbox.restore());
Expand Down Expand Up @@ -115,12 +118,37 @@ describe('gemini', () => {
});
});

it('should load plugins before reading tests', () => {
sandbox.stub(temp, 'init');
return runGeminiTest()
.then(() => {
assert.callOrder(plugins.load, testReaderStub);
});
describe('load plugins', () => {
beforeEach(() => sandbox.stub(temp, 'init'));

it('should load plugins', () => {
return runGeminiTest()
.then(() => assert.calledOnce(pluginsLoader.load));
});

it('should load plugins before reading tests', () => {
return runGeminiTest()
.then(() => assert.callOrder(pluginsLoader.load, testReaderStub));
});

it('should load plugins for gemini instance', () => {
const gemini = initGemini();

return gemini.test()
.then(() => assert.calledWith(pluginsLoader.load, gemini));
});

it('should load plugins from config', () => {
return runGeminiTest({plugins: {'some-plugin': true}})
.then(() => assert.calledWith(pluginsLoader.load, sinon.match.any, {'some-plugin': true}));
});

it('should load plugins with appropriate prefix', () => {
const prefix = require('../../package').name + '-';

return runGeminiTest()
.then(() => assert.calledWith(pluginsLoader.load, sinon.match.any, sinon.match.any, prefix));
});
});

describe('readTests', () => {
Expand Down
82 changes: 0 additions & 82 deletions test/unit/plugins.js

This file was deleted.

0 comments on commit 4753c86

Please sign in to comment.