Skip to content

Commit

Permalink
Create packages for util and page object files in functional tests.
Browse files Browse the repository at this point in the history
- Rename page_objects.js to page_objects/index.js.
- Create support/utils folder to contain bdd_wrapper, elastic_dump, es_client, log, and try, all exported by an index.js.
  • Loading branch information
cjcenizal committed Jun 23, 2016
1 parent 2c7394b commit 64828f1
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 48 deletions.
2 changes: 1 addition & 1 deletion test/functional/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ define(function (require) {
});

require([
'intern/dojo/node!../support/page_objects.js',
'intern/dojo/node!../support/page_objects',
'intern/dojo/node!../support',
'intern/dojo/node!./apps/discover',
'intern/dojo/node!./status_page',
Expand Down
9 changes: 6 additions & 3 deletions test/support/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

import url from 'url';
import EsClient from './es_client';
import ElasticDump from './elastic_dump';
import BddWrapper from './bdd_wrapper';

import {
BddWrapper,
ElasticDump,
EsClient,
} from './utils';
import ScenarioManager from '../fixtures/scenario_manager';
import PageObjects from './page_objects';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import {
shieldPage
} from '../index';

import Log from '../log.js';
import Try from '../try.js';
import {
Log,
Try,
} from '../utils';

const mkdirpAsync = promisify(mkdirp);
const writeFileAsync = promisify(fs.writeFile);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 28 additions & 21 deletions test/support/page_objects.js → test/support/page_objects/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

import Common from './pages/common.js';
import ConsolePage from './pages/console_page.js';
import DashboardPage from './pages/dashboard_page.js';
import DiscoverPage from './pages/discover_page.js';
import HeaderPage from './pages/header_page.js';
import SettingsPage from './pages/settings_page.js';
import ShieldPage from './pages/shield_page.js';
import VisualizePage from './pages/visualize_page.js';
import Common from './common';
import ConsolePage from './console_page';
import DashboardPage from './dashboard_page';
import DiscoverPage from './discover_page';
import HeaderPage from './header_page';
import SettingsPage from './settings_page';
import ShieldPage from './shield_page';
import VisualizePage from './visualize_page';

const common = new Common();
const consolePage = new ConsolePage();
Expand All @@ -17,8 +17,12 @@ const settingsPage = new SettingsPage();
const shieldPage = new ShieldPage();
const visualizePage = new VisualizePage();

export default {
isInitialized: false,
class PageObjects {

constructor() {
this.isInitialized = false;
this.remote = undefined;
}

init(remote) {
this.isInitialized = true;
Expand All @@ -31,44 +35,47 @@ export default {
settingsPage.init(remote);
shieldPage.init(remote);
visualizePage.init(remote);
},
}

assertInitialized() {
if (this.isInitialized) {
return true;
}
throw new TypeError('Please call init and provide a reference to `remote` before trying to access a page object.');
},
}

get common() {
return this.assertInitialized() && common;
},
}

get console() {
return this.assertInitialized() && consolePage;
},
}

get dashboard() {
return this.assertInitialized() && dashboardPage;
},
}

get discover() {
return this.assertInitialized() && discoverPage;
},
}

get header() {
return this.assertInitialized() && headerPage;
},
}

get settings() {
return this.assertInitialized() && settingsPage;
},
}

get shield() {
return this.assertInitialized() && shieldPage;
},
}

get visualize() {
return this.assertInitialized() && visualizePage;
},
};
}

}

export default new PageObjects();
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

import { attempt } from 'bluebird';

import PageObjects from './page_objects';
import PageObjects from '../page_objects';

export default class BddWrapper {
constructor(real) {
this.real = real;
constructor(bdd) {
this.bdd = bdd;
}

errorWrapper = fn => {
Expand All @@ -19,26 +19,26 @@ export default class BddWrapper {
}

describe = (name, fn) => {
this.real.describe(name, fn);
this.bdd.describe(name, fn);
}

before = (fn) => {
this.real.before(this.errorWrapper(fn));
this.bdd.before(this.errorWrapper(fn));
}

beforeEach = (fn) => {
this.real.beforeEach(this.errorWrapper(fn));
this.bdd.beforeEach(this.errorWrapper(fn));
}

it = (name, fn) => {
this.real.it(name, this.errorWrapper(fn));
this.bdd.it(name, this.errorWrapper(fn));
}

afterEach = (fn) => {
this.real.afterEach(this.errorWrapper(fn));
this.bdd.afterEach(this.errorWrapper(fn));
}

after = (fn) => {
this.real.after(this.errorWrapper(fn));
this.bdd.after(this.errorWrapper(fn));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { config } from './';
import Log from './log.js';
import { config } from '../';
import {
Log,
} from './';

export default (function () {
var util = require('util');
Expand Down
6 changes: 4 additions & 2 deletions test/support/es_client.js → test/support/utils/es_client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import Log from './log.js';
import Try from './try.js';
import {
Log,
Try,
} from './';

export default (function () {

Expand Down
20 changes: 20 additions & 0 deletions test/support/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

export {
default as BddWrapper
} from './bdd_wrapper';

export {
default as ElasticDump
} from './elastic_dump';

export {
default as EsClient
} from './es_client';

export {
default as Log
} from './log';

export {
default as Try
} from './try';
12 changes: 8 additions & 4 deletions test/support/log.js → test/support/utils/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import util from 'util';

import {
config
} from './index';
} from '../index';

class Log {

export default {
log(...args) {
console.log(moment().format('HH:mm:ss.SSS') + ':', util.format(...args));
},
}

debug(...args) {
if (config.debug) this.log(...args);
}
};

}

export default new Log();
12 changes: 8 additions & 4 deletions test/support/try.js → test/support/utils/try.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import bluebird from 'bluebird';

import {
defaultTryTimeout
} from './index';
} from '../index';

import Log from './log.js';

export default {
class Try {

tryForTime(timeout, block) {
var self = this;
var start = Date.now();
Expand All @@ -32,9 +33,12 @@ export default {
}

return bluebird.try(attempt);
},
}

try(block) {
return this.tryForTime(defaultTryTimeout, block);
}
};

}

export default new Try();

0 comments on commit 64828f1

Please sign in to comment.