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

Commit

Permalink
fix-metainfo-url
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Aug 29, 2016
1 parent eed63f8 commit a929d7e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
7 changes: 5 additions & 2 deletions lib/runner/suite-runner/decorator-suite-runner.js
Expand Up @@ -13,9 +13,12 @@ module.exports = class DecoratorSuiteRunner extends Runner {
this._suiteRunner = runner;
this._browserConfig = config.forBrowser(browserAgent.browserId);

[
this.passthroughEvent(this._suiteRunner, [
RunnerEvents.BEGIN_SUITE,
RunnerEvents.END_SUITE,
RunnerEvents.END_SUITE
]);

[
RunnerEvents.BEGIN_STATE,
RunnerEvents.SKIP_STATE,
RunnerEvents.END_STATE,
Expand Down
53 changes: 46 additions & 7 deletions test/unit/runner/suite-runner/decorator-suite-runner.js
Expand Up @@ -58,12 +58,39 @@ describe('runner/suite-runner/decorator-suite-runner', () => {
});
});

describe('pass events through', () => {
beforeEach(() => sandbox.spy(DecoratorSuiteRunner.prototype, 'emit'));

[RunnerEvents.BEGIN_SUITE, RunnerEvents.END_SUITE].forEach((event) => {
it(`should pass ${event} event through without changing`, () => {
const suiteRunner = new QEmitter();
const decorator = makeDecoratorRunner(suiteRunner);

const eventSpy = sinon.spy().named(event);
const suiteData = makeSuiteData();
const suiteDataClone = _.cloneDeep(suiteData);

decorator.on(event, eventSpy);
suiteRunner.emit(event, suiteData);

assert.deepEqual(eventSpy.firstCall.args[0], suiteDataClone);
});

it(`should emit ${event} event`, () => {
const suiteRunner = new QEmitter();
const decorator = makeDecoratorRunner(suiteRunner);

suiteRunner.emit(event, makeSuiteData());

assert.calledWith(decorator.emit, event);
});
});
});

describe('event decorator', () => {
beforeEach(() => sandbox.spy(DecoratorSuiteRunner.prototype, 'emitAndWait'));

[
RunnerEvents.BEGIN_SUITE,
RunnerEvents.END_SUITE,
RunnerEvents.BEGIN_STATE,
RunnerEvents.SKIP_STATE,
RunnerEvents.END_STATE,
Expand All @@ -82,7 +109,7 @@ describe('runner/suite-runner/decorator-suite-runner', () => {
const suiteDataClone = _.cloneDeep(suiteData);

decorator.on(event, eventSpy);
suiteRunner.emit(event, suiteDataClone);
suiteRunner.emit(event, suiteData);

assert.calledWithMatch(eventSpy, suiteDataClone);
assert.notDeepEqual(suiteData, suiteDataClone);
Expand All @@ -100,13 +127,25 @@ describe('runner/suite-runner/decorator-suite-runner', () => {
});

describe('add metaInfo url to suite field', () => {
it('should not modify a data suite multiple times', () => {
const suiteRunner = new QEmitter();
makeDecoratorRunner(suiteRunner, {rootUrl: 'http://localhost/foo/bar/'});

const suiteData = makeSuiteData({url: 'testUrl'});
suiteData.suite.metaInfo = {url: 'testUrl'};

suiteRunner.emit(RunnerEvents.BEGIN_STATE, suiteData);

assert.equal(suiteData.suite.metaInfo.url, 'testUrl');
});

it('should concatenate rootUrl and suiteUrl', () => {
const suiteRunner = new QEmitter();
makeDecoratorRunner(suiteRunner, {rootUrl: 'http://localhost/foo/bar/'});

const suiteData = makeSuiteData({url: 'testUrl'});

suiteRunner.emit(RunnerEvents.BEGIN_SUITE, suiteData);
suiteRunner.emit(RunnerEvents.BEGIN_STATE, suiteData);

assert.equal(suiteData.suite.metaInfo.url, '/foo/bar/testUrl');
});
Expand All @@ -117,7 +156,7 @@ describe('runner/suite-runner/decorator-suite-runner', () => {

const suiteData = makeSuiteData({url: 'testUrl//'});

suiteRunner.emit(RunnerEvents.BEGIN_SUITE, suiteData);
suiteRunner.emit(RunnerEvents.BEGIN_STATE, suiteData);

assert.equal(suiteData.suite.metaInfo.url, '/foo/baz/testUrl');
});
Expand All @@ -128,7 +167,7 @@ describe('runner/suite-runner/decorator-suite-runner', () => {

const suiteData = makeSuiteData({url: '/testUrl'});

suiteRunner.emit(RunnerEvents.BEGIN_SUITE, suiteData);
suiteRunner.emit(RunnerEvents.BEGIN_STATE, suiteData);

assert.equal(suiteData.suite.metaInfo.url, '/foo/qux/testUrl');
});
Expand All @@ -139,7 +178,7 @@ describe('runner/suite-runner/decorator-suite-runner', () => {

const suiteData = makeSuiteData({url: 'testUrl'});

suiteRunner.emit(RunnerEvents.BEGIN_SUITE, suiteData);
suiteRunner.emit(RunnerEvents.BEGIN_STATE, suiteData);

assert.equal(suiteData.suite.metaInfo.url, '/foo/bar/testUrl');
});
Expand Down

0 comments on commit a929d7e

Please sign in to comment.