From 64828f12ec807415f4052c87f505d9b712b8c2ec Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Thu, 23 Jun 2016 10:20:34 -0700 Subject: [PATCH] Create packages for util and page object files in functional tests. - 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. --- test/functional/index.js | 2 +- test/support/index.js | 9 ++-- .../support/{pages => page_objects}/common.js | 6 ++- .../{pages => page_objects}/console_page.js | 0 .../{pages => page_objects}/dashboard_page.js | 0 .../{pages => page_objects}/discover_page.js | 0 .../{pages => page_objects}/header_page.js | 0 .../index.js} | 49 +++++++++++-------- .../{pages => page_objects}/settings_page.js | 0 .../{pages => page_objects}/shield_page.js | 0 .../{pages => page_objects}/visualize_page.js | 0 test/support/{ => utils}/bdd_wrapper.js | 18 +++---- test/support/{ => utils}/elastic_dump.js | 6 ++- test/support/{ => utils}/es_client.js | 6 ++- test/support/utils/index.js | 20 ++++++++ test/support/{ => utils}/log.js | 12 +++-- test/support/{ => utils}/try.js | 12 +++-- 17 files changed, 92 insertions(+), 48 deletions(-) rename test/support/{pages => page_objects}/common.js (99%) rename test/support/{pages => page_objects}/console_page.js (100%) rename test/support/{pages => page_objects}/dashboard_page.js (100%) rename test/support/{pages => page_objects}/discover_page.js (100%) rename test/support/{pages => page_objects}/header_page.js (100%) rename test/support/{page_objects.js => page_objects/index.js} (73%) rename test/support/{pages => page_objects}/settings_page.js (100%) rename test/support/{pages => page_objects}/shield_page.js (100%) rename test/support/{pages => page_objects}/visualize_page.js (100%) rename test/support/{ => utils}/bdd_wrapper.js (62%) rename test/support/{ => utils}/elastic_dump.js (98%) rename test/support/{ => utils}/es_client.js (98%) create mode 100644 test/support/utils/index.js rename test/support/{ => utils}/log.js (78%) rename test/support/{ => utils}/try.js (91%) diff --git a/test/functional/index.js b/test/functional/index.js index 6a2be6dafbba3..9aa610fd99672 100644 --- a/test/functional/index.js +++ b/test/functional/index.js @@ -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', diff --git a/test/support/index.js b/test/support/index.js index 66df62f91efb4..77d1afa2bd1c5 100644 --- a/test/support/index.js +++ b/test/support/index.js @@ -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'; diff --git a/test/support/pages/common.js b/test/support/page_objects/common.js similarity index 99% rename from test/support/pages/common.js rename to test/support/page_objects/common.js index 1635ca43c715f..ecec20ae168b6 100644 --- a/test/support/pages/common.js +++ b/test/support/page_objects/common.js @@ -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); diff --git a/test/support/pages/console_page.js b/test/support/page_objects/console_page.js similarity index 100% rename from test/support/pages/console_page.js rename to test/support/page_objects/console_page.js diff --git a/test/support/pages/dashboard_page.js b/test/support/page_objects/dashboard_page.js similarity index 100% rename from test/support/pages/dashboard_page.js rename to test/support/page_objects/dashboard_page.js diff --git a/test/support/pages/discover_page.js b/test/support/page_objects/discover_page.js similarity index 100% rename from test/support/pages/discover_page.js rename to test/support/page_objects/discover_page.js diff --git a/test/support/pages/header_page.js b/test/support/page_objects/header_page.js similarity index 100% rename from test/support/pages/header_page.js rename to test/support/page_objects/header_page.js diff --git a/test/support/page_objects.js b/test/support/page_objects/index.js similarity index 73% rename from test/support/page_objects.js rename to test/support/page_objects/index.js index d81706ad9607e..09ec8b689f47a 100644 --- a/test/support/page_objects.js +++ b/test/support/page_objects/index.js @@ -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(); @@ -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; @@ -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(); diff --git a/test/support/pages/settings_page.js b/test/support/page_objects/settings_page.js similarity index 100% rename from test/support/pages/settings_page.js rename to test/support/page_objects/settings_page.js diff --git a/test/support/pages/shield_page.js b/test/support/page_objects/shield_page.js similarity index 100% rename from test/support/pages/shield_page.js rename to test/support/page_objects/shield_page.js diff --git a/test/support/pages/visualize_page.js b/test/support/page_objects/visualize_page.js similarity index 100% rename from test/support/pages/visualize_page.js rename to test/support/page_objects/visualize_page.js diff --git a/test/support/bdd_wrapper.js b/test/support/utils/bdd_wrapper.js similarity index 62% rename from test/support/bdd_wrapper.js rename to test/support/utils/bdd_wrapper.js index 08c3815155436..bc4fe370f9e5b 100644 --- a/test/support/bdd_wrapper.js +++ b/test/support/utils/bdd_wrapper.js @@ -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 => { @@ -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)); } } diff --git a/test/support/elastic_dump.js b/test/support/utils/elastic_dump.js similarity index 98% rename from test/support/elastic_dump.js rename to test/support/utils/elastic_dump.js index 188c352f936d3..e019a4497e717 100644 --- a/test/support/elastic_dump.js +++ b/test/support/utils/elastic_dump.js @@ -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'); diff --git a/test/support/es_client.js b/test/support/utils/es_client.js similarity index 98% rename from test/support/es_client.js rename to test/support/utils/es_client.js index 58624518765fd..10a85f9fcec39 100644 --- a/test/support/es_client.js +++ b/test/support/utils/es_client.js @@ -1,6 +1,8 @@ -import Log from './log.js'; -import Try from './try.js'; +import { + Log, + Try, +} from './'; export default (function () { diff --git a/test/support/utils/index.js b/test/support/utils/index.js new file mode 100644 index 0000000000000..d76588ea903a0 --- /dev/null +++ b/test/support/utils/index.js @@ -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'; diff --git a/test/support/log.js b/test/support/utils/log.js similarity index 78% rename from test/support/log.js rename to test/support/utils/log.js index abf0572fd2c99..9259b18e6a129 100644 --- a/test/support/log.js +++ b/test/support/utils/log.js @@ -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(); diff --git a/test/support/try.js b/test/support/utils/try.js similarity index 91% rename from test/support/try.js rename to test/support/utils/try.js index 0af9acaad28ab..1735e3e7f82d3 100644 --- a/test/support/try.js +++ b/test/support/utils/try.js @@ -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(); @@ -32,9 +33,12 @@ export default { } return bluebird.try(attempt); - }, + } try(block) { return this.tryForTime(defaultTryTimeout, block); } -}; + +} + +export default new Try();