refactor: change provide(...) for {provide: ...}
- provide() is deprecated, - {} syntax is required by the offline compiler
This commit is contained in:
@ -10,12 +10,12 @@ import {
|
||||
xit,
|
||||
} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
import {Metric, MultiMetric, bind, provide, ReflectiveInjector} from 'benchpress/common';
|
||||
import {Metric, MultiMetric, ReflectiveInjector} from 'benchpress/common';
|
||||
|
||||
export function main() {
|
||||
function createMetric(ids: any[]) {
|
||||
var m = ReflectiveInjector.resolveAndCreate([
|
||||
ids.map(id => provide(id, {useValue: new MockMetric(id)})),
|
||||
ids.map(id => {return {provide: id, useValue: new MockMetric(id)}}),
|
||||
MultiMetric.createBindings(ids)
|
||||
])
|
||||
.get(MultiMetric);
|
||||
|
@ -20,8 +20,6 @@ import {
|
||||
PerflogMetric,
|
||||
WebDriverExtension,
|
||||
PerfLogFeatures,
|
||||
bind,
|
||||
provide,
|
||||
ReflectiveInjector,
|
||||
Options
|
||||
} from 'benchpress/common';
|
||||
@ -51,26 +49,30 @@ export function main() {
|
||||
var providers = [
|
||||
Options.DEFAULT_PROVIDERS,
|
||||
PerflogMetric.PROVIDERS,
|
||||
bind(Options.MICRO_METRICS).toValue(microMetrics),
|
||||
bind(PerflogMetric.SET_TIMEOUT)
|
||||
.toValue((fn, millis) => {
|
||||
commandLog.push(['setTimeout', millis]);
|
||||
fn();
|
||||
}),
|
||||
bind(WebDriverExtension)
|
||||
.toValue(new MockDriverExtension(perfLogs, commandLog, perfLogFeatures))
|
||||
{provide: Options.MICRO_METRICS, useValue: microMetrics},
|
||||
{
|
||||
provide: PerflogMetric.SET_TIMEOUT,
|
||||
useValue: (fn, millis) => {
|
||||
commandLog.push(['setTimeout', millis]);
|
||||
fn();
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: WebDriverExtension,
|
||||
useValue: new MockDriverExtension(perfLogs, commandLog, perfLogFeatures)
|
||||
}
|
||||
];
|
||||
if (isPresent(forceGc)) {
|
||||
providers.push(bind(Options.FORCE_GC).toValue(forceGc));
|
||||
providers.push({provide: Options.FORCE_GC, useValue(forceGc)};
|
||||
}
|
||||
if (isPresent(captureFrames)) {
|
||||
providers.push(bind(Options.CAPTURE_FRAMES).toValue(captureFrames));
|
||||
providers.push({provide: Options.CAPTURE_FRAMES, useValue: captureFrames});
|
||||
}
|
||||
if (isPresent(receivedData)) {
|
||||
providers.push(bind(Options.RECEIVED_DATA).toValue(receivedData));
|
||||
providers.push({provide: Options.RECEIVED_DATA, useValue: receivedData});
|
||||
}
|
||||
if (isPresent(requestCount)) {
|
||||
providers.push(bind(Options.REQUEST_COUNT).toValue(requestCount));
|
||||
providers.push({provide: Options.REQUEST_COUNT, useValue: requestCount});
|
||||
}
|
||||
return ReflectiveInjector.resolveAndCreate(providers).get(PerflogMetric);
|
||||
}
|
||||
|
@ -14,8 +14,6 @@ import {isBlank, isPresent, Date, DateWrapper} from '@angular/facade';
|
||||
import {
|
||||
SampleState,
|
||||
Reporter,
|
||||
bind,
|
||||
provide,
|
||||
ReflectiveInjector,
|
||||
ConsoleReporter,
|
||||
SampleDescription,
|
||||
@ -38,12 +36,11 @@ export function main() {
|
||||
}
|
||||
var bindings = [
|
||||
ConsoleReporter.PROVIDERS,
|
||||
provide(SampleDescription,
|
||||
{useValue: new SampleDescription(sampleId, descriptions, metrics)}),
|
||||
bind(ConsoleReporter.PRINT).toValue((line) => log.push(line))
|
||||
{provide: SampleDescription, useValue: new SampleDescription(sampleId, descriptions, metrics)},
|
||||
{provide: ConsoleReporter.PRINT, useValue: (line) => log.push(line)}
|
||||
];
|
||||
if (isPresent(columnWidth)) {
|
||||
bindings.push(bind(ConsoleReporter.COLUMN_WIDTH).toValue(columnWidth));
|
||||
bindings.push({provide: ConsoleReporter.COLUMN_WIDTH, useValue(columnWidth)};
|
||||
}
|
||||
reporter = ReflectiveInjector.resolveAndCreate(bindings).get(ConsoleReporter);
|
||||
}
|
||||
|
@ -15,8 +15,6 @@ import {DateWrapper, Json, RegExpWrapper, isPresent} from '@angular/facade';
|
||||
import {PromiseWrapper} from '@angular/facade';
|
||||
|
||||
import {
|
||||
bind,
|
||||
provide,
|
||||
ReflectiveInjector,
|
||||
SampleDescription,
|
||||
MeasureValues,
|
||||
@ -33,15 +31,16 @@ export function main() {
|
||||
function createReporter({sampleId, descriptions, metrics, path}) {
|
||||
var bindings = [
|
||||
JsonFileReporter.PROVIDERS,
|
||||
provide(SampleDescription,
|
||||
{useValue: new SampleDescription(sampleId, descriptions, metrics)}),
|
||||
bind(JsonFileReporter.PATH).toValue(path),
|
||||
bind(Options.NOW).toValue(() => DateWrapper.fromMillis(1234)),
|
||||
bind(Options.WRITE_FILE)
|
||||
.toValue((filename, content) => {
|
||||
loggedFile = {'filename': filename, 'content': content};
|
||||
return PromiseWrapper.resolve(null);
|
||||
})
|
||||
{provide: SampleDescription, useValue: new SampleDescription(sampleId, descriptions, metrics)},
|
||||
{provide: JsonFileReporter.PATH, useValue(path)},
|
||||
{provide: Options.NOW, useValue: () => DateWrapper.fromMillis(1234)},
|
||||
{
|
||||
provide: Options.WRITE_FILE,
|
||||
useValue: (filename, content) => {
|
||||
loggedFile = {'filename': filename, 'content': content};
|
||||
return PromiseWrapper.resolve(null);
|
||||
}
|
||||
}
|
||||
];
|
||||
return ReflectiveInjector.resolveAndCreate(bindings).get(JsonFileReporter);
|
||||
}
|
||||
|
@ -17,8 +17,6 @@ import {DateWrapper} from '@angular/facade';
|
||||
import {
|
||||
Reporter,
|
||||
MultiReporter,
|
||||
bind,
|
||||
provide,
|
||||
ReflectiveInjector,
|
||||
MeasureValues
|
||||
} from 'benchpress/common';
|
||||
@ -26,7 +24,7 @@ import {
|
||||
export function main() {
|
||||
function createReporters(ids: any[]) {
|
||||
var r = ReflectiveInjector.resolveAndCreate([
|
||||
ids.map(id => provide(id, {useValue: new MockReporter(id)})),
|
||||
ids.map(id => { return {provide: id, useValue: new MockReporter(id)}}),
|
||||
MultiReporter.createBindings(ids)
|
||||
])
|
||||
.get(MultiReporter);
|
||||
|
@ -15,8 +15,6 @@ import {
|
||||
Sampler,
|
||||
SampleDescription,
|
||||
Validator,
|
||||
bind,
|
||||
provide,
|
||||
ReflectiveInjector,
|
||||
Injector,
|
||||
Metric,
|
||||
@ -38,15 +36,17 @@ export function main() {
|
||||
}
|
||||
runner = new Runner([
|
||||
defaultBindings,
|
||||
bind(Sampler).toFactory(
|
||||
(_injector) => {
|
||||
injector = _injector;
|
||||
return new MockSampler();
|
||||
},
|
||||
[Injector]),
|
||||
bind(Metric).toFactory(() => new MockMetric(), []),
|
||||
bind(Validator).toFactory(() => new MockValidator(), []),
|
||||
bind(WebDriverAdapter).toFactory(() => new MockWebDriverAdapter(), [])
|
||||
{
|
||||
provide: Sampler,
|
||||
useFactory: (_injector) => {
|
||||
injector = _injector;
|
||||
return new MockSampler();
|
||||
},
|
||||
deps: [Injector]
|
||||
},
|
||||
{ provide: Metric, useFactory: () => new MockMetric(), deps: []},
|
||||
{ provide: Validator, useFactory: () => new MockValidator(), deps: []},
|
||||
{ provide: WebDriverAdapter, useFactory: () => new MockWebDriverAdapter(), deps: []}
|
||||
]);
|
||||
return runner;
|
||||
}
|
||||
@ -62,8 +62,8 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should merge SampleDescription.description', inject([AsyncTestCompleter], (async) => {
|
||||
createRunner([bind(Options.DEFAULT_DESCRIPTION).toValue({'a': 1})])
|
||||
.sample({id: 'someId', providers: [bind(Options.SAMPLE_DESCRIPTION).toValue({'b': 2})]})
|
||||
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
||||
.sample({id: 'someId', providers: [{provide: Options.SAMPLE_DESCRIPTION, useValue: {'b': 2}}]})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.description)
|
||||
@ -115,16 +115,10 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should overwrite bindings per sample call', inject([AsyncTestCompleter], (async) => {
|
||||
createRunner([
|
||||
bind(Options.DEFAULT_DESCRIPTION)
|
||||
.toValue({'a': 1}),
|
||||
])
|
||||
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
||||
.sample({
|
||||
id: 'someId',
|
||||
providers: [
|
||||
bind(Options.DEFAULT_DESCRIPTION)
|
||||
.toValue({'a': 2}),
|
||||
]
|
||||
providers: [{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 2}}]
|
||||
})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
|
@ -20,8 +20,6 @@ import {
|
||||
Validator,
|
||||
Metric,
|
||||
Reporter,
|
||||
bind,
|
||||
provide,
|
||||
ReflectiveInjector,
|
||||
Options,
|
||||
MeasureValues
|
||||
@ -54,15 +52,15 @@ export function main() {
|
||||
var providers = [
|
||||
Options.DEFAULT_PROVIDERS,
|
||||
Sampler.PROVIDERS,
|
||||
provide(Metric, {useValue: metric}),
|
||||
provide(Reporter, {useValue: reporter}),
|
||||
provide(WebDriverAdapter, {useValue: driver}),
|
||||
bind(Options.EXECUTE).toValue(execute),
|
||||
provide(Validator, {useValue: validator}),
|
||||
bind(Options.NOW).toValue(() => DateWrapper.fromMillis(time++))
|
||||
{provide: Metric, useValue: metric},
|
||||
{provide: Reporter, useValue: reporter},
|
||||
{provide: WebDriverAdapter, useValue: driver},
|
||||
{provide: Options.EXECUTE, useValue: execute},
|
||||
{provide: Validator, useValue: validator},
|
||||
{provide: Options.NOW, useValue: () => DateWrapper.fromMillis(time++)}
|
||||
];
|
||||
if (isPresent(prepare)) {
|
||||
providers.push(bind(Options.PREPARE).toValue(prepare));
|
||||
providers.push({provide: Options.PREPARE, useValue: prepare});
|
||||
}
|
||||
|
||||
sampler = ReflectiveInjector.resolveAndCreate(providers).get(Sampler);
|
||||
|
@ -12,11 +12,8 @@ import {Date, DateWrapper} from '@angular/facade';
|
||||
import {ListWrapper} from '@angular/facade';
|
||||
|
||||
import {
|
||||
Validator,
|
||||
RegressionSlopeValidator,
|
||||
ReflectiveInjector,
|
||||
bind,
|
||||
provide,
|
||||
MeasureValues
|
||||
} from 'benchpress/common';
|
||||
|
||||
@ -27,8 +24,8 @@ export function main() {
|
||||
function createValidator({size, metric}) {
|
||||
validator = ReflectiveInjector.resolveAndCreate([
|
||||
RegressionSlopeValidator.PROVIDERS,
|
||||
provide(RegressionSlopeValidator.METRIC).toValue(metric),
|
||||
provide(RegressionSlopeValidator.SAMPLE_SIZE).toValue(size)
|
||||
{provide: RegressionSlopeValidator.METRIC, useValue(metric)},
|
||||
{provide: RegressionSlopeValidator.SAMPLE_SIZE, useValue(size)}
|
||||
])
|
||||
.get(RegressionSlopeValidator);
|
||||
}
|
||||
|
@ -15,8 +15,6 @@ import {
|
||||
Validator,
|
||||
SizeValidator,
|
||||
ReflectiveInjector,
|
||||
bind,
|
||||
provide,
|
||||
MeasureValues
|
||||
} from 'benchpress/common';
|
||||
|
||||
@ -27,7 +25,7 @@ export function main() {
|
||||
function createValidator(size) {
|
||||
validator = ReflectiveInjector.resolveAndCreate([
|
||||
SizeValidator.PROVIDERS,
|
||||
provide(SizeValidator.SAMPLE_SIZE).toValue(size)
|
||||
{provide: SizeValidator.SAMPLE_SIZE, useValue: size}
|
||||
])
|
||||
.get(SizeValidator);
|
||||
}
|
||||
|
@ -14,14 +14,14 @@ import {
|
||||
import {isPresent, StringWrapper} from '@angular/facade';
|
||||
import {PromiseWrapper} from '@angular/facade';
|
||||
|
||||
import {WebDriverExtension, bind, provide, ReflectiveInjector, Options} from 'benchpress/common';
|
||||
import {WebDriverExtension, ReflectiveInjector, Options} from 'benchpress/common';
|
||||
|
||||
export function main() {
|
||||
function createExtension(ids: any[], caps) {
|
||||
return PromiseWrapper.wrap(() => {
|
||||
return ReflectiveInjector.resolveAndCreate([
|
||||
ids.map(id => provide(id, {useValue: new MockExtension(id)})),
|
||||
bind(Options.CAPABILITIES).toValue(caps),
|
||||
ids.map((id) => { return {provide: id, useValue: new MockExtension(id)}}),
|
||||
{provide: Options.CAPABILITIES, useValue: caps},
|
||||
WebDriverExtension.bindTo(ids)
|
||||
])
|
||||
.get(WebDriverExtension);
|
||||
|
@ -19,8 +19,6 @@ import {
|
||||
ChromeDriverExtension,
|
||||
WebDriverAdapter,
|
||||
ReflectiveInjector,
|
||||
bind,
|
||||
provide,
|
||||
Options
|
||||
} from 'benchpress/common';
|
||||
|
||||
@ -60,9 +58,8 @@ export function main() {
|
||||
extension =
|
||||
ReflectiveInjector.resolveAndCreate([
|
||||
ChromeDriverExtension.PROVIDERS,
|
||||
provide(WebDriverAdapter)
|
||||
.toValue(new MockDriverAdapter(log, perfRecords, messageMethod)),
|
||||
provide(Options.USER_AGENT).toValue(userAgent)
|
||||
{provide: WebDriverAdapter, useValue: new MockDriverAdapter(log, perfRecords, messageMethod)},
|
||||
{provide: Options.USER_AGENT, useValue(userAgent)}
|
||||
])
|
||||
.get(ChromeDriverExtension);
|
||||
return extension;
|
||||
|
@ -19,8 +19,6 @@ import {
|
||||
IOsDriverExtension,
|
||||
WebDriverAdapter,
|
||||
ReflectiveInjector,
|
||||
bind,
|
||||
provide
|
||||
} from 'benchpress/common';
|
||||
|
||||
import {TraceEventFactory} from '../trace_event_factory';
|
||||
@ -39,8 +37,7 @@ export function main() {
|
||||
log = [];
|
||||
extension = ReflectiveInjector.resolveAndCreate([
|
||||
IOsDriverExtension.PROVIDERS,
|
||||
provide(WebDriverAdapter,
|
||||
{useValue: new MockDriverAdapter(log, perfRecords)})
|
||||
{provide: WebDriverAdapter, useValue: new MockDriverAdapter(log, perfRecords)}
|
||||
])
|
||||
.get(IOsDriverExtension);
|
||||
return extension;
|
||||
|
Reference in New Issue
Block a user