Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
const _ = require('lodash'),
AsyncEmitter = require('gemini-core').events.AsyncEmitter;
module.exports = class PassthroughEmitter extends AsyncEmitter {
// Allow to pass only one argument with event
emit(type, data) {
return super.emit(type, data);
}
emitAndWait(type, data) {
return super.emitAndWait(type, data, {shouldWait: true});
}
/**
* Emit event emitted by emitter
* @param {EventEmitter} emitter
* @param {String|String[]} event or array of events to passthrough
*/
beforeEach(() => {
ipc = new AsyncEmitter();
HermioneFacade = proxyquire('lib/worker/hermione-facade', {
// TODO: think about how to make it easier
'../utils/ipc': {on: ipc.on.bind(ipc), emit: ipc.emit.bind(ipc)}
});
config = makeConfigStub();
hermione = Object.assign(new AsyncEmitter(), {
init: sandbox.spy().named('hermioneInit'),
config
});
sandbox.stub(Hermione, 'create').returns(hermione);
ipc.on('worker.init', () => {
process.nextTick(() => ipc.emit('master.init'));
});
beforeEach(() => {
ipc = new AsyncEmitter();
HermioneFacade = proxyquire('lib/worker/hermione-facade', {
// TODO: think about how to make it easier
'../utils/ipc': {on: ipc.on.bind(ipc), emit: ipc.emit.bind(ipc)}
});
config = makeConfigStub();
hermione = Object.assign(new AsyncEmitter(), {
init: sandbox.spy().named('hermioneInit'),
config
});
sandbox.stub(Hermione, 'create').returns(hermione);
ipc.on('worker.init', () => {
process.nextTick(() => ipc.emit('master.init'));
});
ipc.on('worker.syncConfig', () => {
process.nextTick(() => ipc.emit('master.syncConfig', {config}));
});
});
'use strict';
const proxyquire = require('proxyquire');
const {AsyncEmitter} = require('gemini-core').events;
const Hermione = require('lib/worker/hermione');
const {makeConfigStub} = require('../../utils');
describe('worker/hermione-facade', () => {
const sandbox = sinon.createSandbox();
let HermioneFacade;
let hermione;
let config;
let ipc;
beforeEach(() => {
ipc = new AsyncEmitter();
HermioneFacade = proxyquire('lib/worker/hermione-facade', {
// TODO: think about how to make it easier
'../utils/ipc': {on: ipc.on.bind(ipc), emit: ipc.emit.bind(ipc)}
});
it('should pass to suite runner browser agent associated with current browser', () => {
const browserAgent = new BrowserAgent('browser');
const suiteCollection = new SuiteCollection([makeSuiteStub({browsers: ['browser']})]);
sandbox.stub(BrowserAgent, 'create');
BrowserAgent.create.returns(browserAgent);
const runner = mkRunner_('browser');
return runner.run(suiteCollection)
.then(() => assert.calledWith(suiteRunnerFabric.create, sinon.match.any, browserAgent));
});
it('should create browser agent instance for each suite', () => {
const suiteCollection = new SuiteCollection([
makeSuiteStub({browsers: ['bro']}),
makeSuiteStub({browsers: ['bro']})
]);
sandbox.spy(BrowserAgent, 'create');
return mkRunner_('bro')
.run(suiteCollection)
.then(() => {
assert.calledTwice(BrowserAgent.create);
assert.notEqual(
suiteRunnerFabric.create.firstCall.args[1],
suiteRunnerFabric.create.secondCall.args[1]
);
});
});
it('should pass to suite runner browser agent associated with current browser', () => {
const browserAgent = new BrowserAgent('browser');
const suiteCollection = new SuiteCollection([makeSuiteStub({browsers: ['browser']})]);
sandbox.stub(BrowserAgent, 'create');
BrowserAgent.create.returns(browserAgent);
const runner = mkRunner_('browser');
return runner.run(suiteCollection)
.then(() => assert.calledWith(suiteRunnerFabric.create, sinon.match.any, browserAgent));
});
it('should be emitted even on browser get fail', async () => {
const onTestBegin = sinon.stub().named('onTestBegin');
const runner = mkRunner_()
.on(Events.TEST_BEGIN, onTestBegin);
BrowserAgent.prototype.getBrowser.rejects();
await run_({runner});
assert.calledOnce(onTestBegin);
});
});
it('should create test runner with high priority browser agent', async () => {
onFirstTestRun_((innerRunner) => innerRunner.emit(Events.TEST_FAIL, makeFailedTest_()));
const browserAgent = Object.create(BrowserAgent.prototype);
const highPriorityBrowserAgent = Object.create(HighPriorityBrowserAgent.prototype);
HighPriorityBrowserAgent.create
.withArgs(browserAgent).returns(highPriorityBrowserAgent);
const runner = mkRunnerWithRetries_({browserAgent});
await run_({runner});
assert.calledWith(RegularTestRunner.create, sinon.match.any, highPriorityBrowserAgent);
});
describe('runner/suite-runner/stateless-suite-runner', () => {
const sandbox = sinon.sandbox.create();
const suite = util.makeSuiteStub();
const browserAgent = BrowserAgent.create('default-browser');
const runner = new StatelessSuiteRunner(suite, browserAgent);
beforeEach(() => {
sandbox.stub(BrowserAgent.prototype, 'getBrowser');
sandbox.stub(BrowserAgent.prototype, 'freeBrowser');
});
afterEach(() => sandbox.restore());
it('should emit `beginSuite` event', () => {
const onBeginSuite = sinon.spy().named('onBeginSuite');
runner.on('beginSuite', onBeginSuite);
return runner.run()
.then(() => assert.calledOnce(onBeginSuite));