fix(benchpress): benchpress fixes and a smoke test for Dart

This commit is contained in:
Yegor Jbanov
2015-02-20 17:44:23 -08:00
parent 0a0c0d8302
commit d1f03e509b
18 changed files with 263 additions and 61 deletions
+8
View File
@@ -95,6 +95,14 @@ class StringJoiner {
}
class NumberWrapper {
static String toFixed(num n, int fractionDigits) {
return n.toStringAsFixed(fractionDigits);
}
static bool equal(num a, num b) {
return a == b;
}
static int parseIntAutoRadix(String text) {
return int.parse(text);
}
+8
View File
@@ -138,6 +138,14 @@ export class NumberParseError extends Error {
export class NumberWrapper {
static toFixed(n:number, fractionDigits:int):string {
return n.toFixed(fractionDigits);
}
static equal(a, b):boolean {
return a === b;
}
static parseIntAutoRadix(text:string):int {
var result:int = parseInt(text);
if (isNaN(result)) {
@@ -123,11 +123,11 @@ void _runTests() {
// Read in input & output files.
config.assetPathToInputPath.forEach((key, value) {
config.assetPathToInputPath[key] =
cache.putIfAbsent(value, () => new File(value).readAsStringSync());
cache.putIfAbsent(value, () => new File('test/transform/${value}').readAsStringSync());
});
config.assetPathToExpectedOutputPath.forEach((key, value) {
config.assetPathToExpectedOutputPath[key] = cache.putIfAbsent(value, () {
var code = new File(value).readAsStringSync();
var code = new File('test/transform/${value}').readAsStringSync();
return value.endsWith('dart') ? formatter.format(code) : code;
});
});
+1
View File
@@ -12,5 +12,6 @@ dependencies:
stack_trace: '>=1.1.1 <1.2.0'
angular2:
path: ../angular2
webdriver: ">=0.9.0 <0.10.0"
dev_dependencies:
guinness: ">=0.1.16 <0.2.0"
@@ -1,5 +1,5 @@
import { PromiseWrapper, Promise } from 'angular2/src/facade/async';
import { isPresent, isBlank, int, BaseException, StringWrapper } from 'angular2/src/facade/lang';
import { isPresent, isBlank, int, BaseException, StringWrapper, Math } from 'angular2/src/facade/lang';
import { ListWrapper, StringMap, StringMapWrapper } from 'angular2/src/facade/collection';
import { bind, OpaqueToken } from 'angular2/di';
@@ -95,7 +95,12 @@ export class PerflogMetric extends Metric {
if (needSort) {
// Need to sort because of the ph==='X' events
ListWrapper.sort(this._remainingEvents, (a,b) => {
return a['ts'] - b['ts'];
var diff = a['ts'] - b['ts'];
return diff > 0
? 1
: diff < 0
? -1
: 0;
});
}
}
@@ -1,4 +1,4 @@
import { print, isPresent, isBlank } from 'angular2/src/facade/lang';
import { print, isPresent, isBlank, NumberWrapper } from 'angular2/src/facade/lang';
import { StringMapWrapper, ListWrapper, List } from 'angular2/src/facade/collection';
import { Promise, PromiseWrapper } from 'angular2/src/facade/async';
import { Math } from 'angular2/src/facade/math';
@@ -28,14 +28,8 @@ export class ConsoleReporter extends Reporter {
return result + value;
}
static _formatNum(num) {
var result;
if (num === 0) {
result = '000';
} else {
result = `${Math.floor(num * 100)}`;
}
return result.substring(0, result.length - 2) + '.' + result.substring(result.length-2);
static _formatNum(n) {
return NumberWrapper.toFixed(n, 2);
}
static _sortedProps(obj) {
@@ -89,7 +83,8 @@ export class ConsoleReporter extends Reporter {
var sample = ListWrapper.map(validSample, (measureValues) => measureValues.values[metricName]);
var mean = Statistic.calculateMean(sample);
var cv = Statistic.calculateCoefficientOfVariation(sample, mean);
return `${ConsoleReporter._formatNum(mean)}\u00B1${Math.floor(cv)}%`;
var formattedCv = NumberWrapper.isNaN(cv) ? 'NaN' : Math.floor(cv);
return `${ConsoleReporter._formatNum(mean)}\u00B1${formattedCv}%`;
})
);
return PromiseWrapper.resolve(null);
@@ -1,23 +1,32 @@
library benchpress.src.webdriver.async_webdriver_adapter_dart;
import 'package:webdriver/webdriver.dart' show WebDriver, LogEntry;
import 'package:angular2/src/facade/async.dart' show Future;
import '../web_driver_adapter.dart' show WebDriverAdapter;
class AsyncWebDriverAdapter extends WebDriverAdapter {
dynamic _driver;
AsyncWebDriverAdapter(driver) {
this._driver = driver;
}
WebDriver _driver;
AsyncWebDriverAdapter(this._driver);
Future waitFor(Function callback) {
return callback();
}
Future executeScript(String script) {
return this._driver.execute(script);
return _driver.execute(script, const[]);
}
Future capabilities() {
return this._driver.capabilities;
Map capabilities() {
return _driver.capabilities;
}
Future logs(String type) {
return this._driver.logs.get(type);
Future<List<Map>> logs(String type) {
return _driver.logs.get(type)
.map((LogEntry entry) => {
'message': entry.message
})
.fold(<Map>[], (log, Map entry) {
return log..add(entry);
});
}
}
+2
View File
@@ -7,6 +7,8 @@ dependencies:
browser: '>=0.10.0 <0.11.0'
dev_dependencies:
guinness: ">=0.1.16 <0.2.0"
benchpress:
path: ../benchpress
transformers:
- angular2:
bootstrap_entry_point: web/src/hello_world/index_common.dart
@@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<title>Benchpress test</title>
</head>
<body>
<button onclick="pleaseLog()">Click me</button>
<div id="log"></div>
<script type="text/javascript">
function pleaseLog() {
document.getElementById("log").innerHTML = "hi";
}
</script>
</body>
</html>
@@ -0,0 +1,58 @@
import 'dart:async';
import 'dart:io' show Platform;
import 'package:guinness/guinness.dart';
import 'package:benchpress/benchpress.dart';
import 'package:benchpress/src/webdriver/async_webdriver_adapter.dart';
import 'package:webdriver/webdriver.dart' show WebDriver, Capabilities, LogType, LogLevel, By;
main() {
describe('benchpress', () {
WebDriver driver;
Runner runner;
beforeEach(() async {
driver = await createTestDriver();
await driver.get('http://localhost:8002/examples/src/benchpress/index.html');
var bindings = [
bind(WebDriverAdapter).toFactory(() => new AsyncWebDriverAdapter(driver), [])
];
runner = new Runner(bindings);
});
afterEach(() async {
await driver.close();
});
it('should work', () {
return runner.sample(
id: 'benchpress smoke test',
execute: () async {
var button = await driver.findElement(const By.tagName('button'));
await button.click();
var logText = await (await driver.findElement(const By.id('log'))).text;
expect(logText, 'hi');
}
);
});
});
}
Future<WebDriver> createTestDriver() {
Map env = Platform.environment;
return WebDriver.createDriver(desiredCapabilities: {
'name': 'Dartium',
'browserName': 'chrome',
'chromeOptions': {
'binary': env['DARTIUM_BIN'],
'args': ['--js-flags=--expose-gc'],
'perfLoggingPrefs': {
'traceCategories': 'blink.console,disabled-by-default-devtools.timeline'
},
},
'loggingPrefs': {
'performance': 'ALL',
'browser': 'ALL',
}
});
}