refactor(tests): move files from angular2/e2e_test
to angular2/src/test_lib
The `e2e_test` folder in `angular2` never contained e2e tests but was used to store utilities for writing e2e/perf tests. A better place for them is `angular2/src/test_lib`. Closes #855
This commit is contained in:

committed by
Misko Hevery

parent
ba0a1ec459
commit
7ddfbf8bea
26
modules/angular2/src/test_lib/e2e_util.es6
Normal file
26
modules/angular2/src/test_lib/e2e_util.es6
Normal file
@ -0,0 +1,26 @@
|
||||
var webdriver = require('selenium-webdriver');
|
||||
|
||||
module.exports = {
|
||||
verifyNoBrowserErrors: verifyNoBrowserErrors,
|
||||
clickAll: clickAll
|
||||
};
|
||||
|
||||
function clickAll(buttonSelectors) {
|
||||
buttonSelectors.forEach(function(selector) {
|
||||
$(selector).click();
|
||||
});
|
||||
}
|
||||
|
||||
function verifyNoBrowserErrors() {
|
||||
// TODO(tbosch): Bug in ChromeDriver: Need to execute at least one command
|
||||
// so that the browser logs can be read out!
|
||||
browser.executeScript('1+1');
|
||||
browser.manage().logs().get('browser').then(function(browserLog) {
|
||||
var filteredLog = browserLog.filter(function(logEntry) {
|
||||
console.log('>> ' + require('util').inspect(logEntry));
|
||||
return logEntry.level.value > webdriver.logging.Level.WARNING.value;
|
||||
});
|
||||
expect(filteredLog.length).toEqual(0);
|
||||
});
|
||||
}
|
||||
|
67
modules/angular2/src/test_lib/perf_util.es6
Normal file
67
modules/angular2/src/test_lib/perf_util.es6
Normal file
@ -0,0 +1,67 @@
|
||||
var testUtil = require('./e2e_util');
|
||||
var benchpress = require('benchpress/benchpress');
|
||||
|
||||
module.exports = {
|
||||
runClickBenchmark: runClickBenchmark,
|
||||
runBenchmark: runBenchmark,
|
||||
verifyNoBrowserErrors: testUtil.verifyNoBrowserErrors
|
||||
};
|
||||
|
||||
function runClickBenchmark(config) {
|
||||
var buttons = config.buttons.map(function(selector) {
|
||||
return $(selector);
|
||||
});
|
||||
config.work = function() {
|
||||
buttons.forEach(function(button) {
|
||||
button.click();
|
||||
});
|
||||
}
|
||||
return runBenchmark(config);
|
||||
}
|
||||
|
||||
function runBenchmark(config) {
|
||||
return getScaleFactor(browser.params.benchmark.scaling).then(function(scaleFactor) {
|
||||
var description = {};
|
||||
var urlParams = [];
|
||||
config.params.forEach(function(param) {
|
||||
var name = param.name;
|
||||
var value = applyScaleFactor(param.value, scaleFactor, param.scale);
|
||||
urlParams.push(name + '=' + value);
|
||||
description[name] = value;
|
||||
});
|
||||
var url = encodeURI(config.url + '?' + urlParams.join('&'));
|
||||
browser.get(url);
|
||||
return benchpressRunner.sample({
|
||||
id: config.id,
|
||||
execute: config.work,
|
||||
prepare: config.prepare,
|
||||
bindings: [
|
||||
benchpress.bind(benchpress.Options.SAMPLE_DESCRIPTION).toValue(description)
|
||||
]
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getScaleFactor(possibleScalings) {
|
||||
return browser.executeScript('return navigator.userAgent').then(function(userAgent) {
|
||||
var scaleFactor = 1;
|
||||
possibleScalings.forEach(function(entry) {
|
||||
if (userAgent.match(entry.userAgent)) {
|
||||
scaleFactor = entry.value;
|
||||
}
|
||||
});
|
||||
return scaleFactor;
|
||||
});
|
||||
}
|
||||
|
||||
function applyScaleFactor(value, scaleFactor, method) {
|
||||
if (method === 'log2') {
|
||||
return value + Math.log2(scaleFactor);
|
||||
} else if (method === 'sqrt') {
|
||||
return value * Math.sqrt(scaleFactor);
|
||||
} else if (method === 'linear') {
|
||||
return value * scaleFactor;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user