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.
This commit is contained in:
parent
2c7394b033
commit
64828f12ec
17 changed files with 92 additions and 48 deletions
|
@ -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',
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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);
|
|
@ -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();
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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');
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
import Log from './log.js';
|
||||
import Try from './try.js';
|
||||
import {
|
||||
Log,
|
||||
Try,
|
||||
} from './';
|
||||
|
||||
export default (function () {
|
||||
|
20
test/support/utils/index.js
Normal file
20
test/support/utils/index.js
Normal file
|
@ -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';
|
|
@ -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();
|
|
@ -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();
|
Loading…
Reference in a new issue