refactor(facade): remove DateWrapper (#12027)
This commit is contained in:
parent
c3c9ecb302
commit
decd129a4d
|
@ -9,8 +9,6 @@
|
||||||
import {OpaqueToken} from '@angular/core';
|
import {OpaqueToken} from '@angular/core';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
|
||||||
import {DateWrapper} from './facade/lang';
|
|
||||||
|
|
||||||
export class Options {
|
export class Options {
|
||||||
static SAMPLE_ID = new OpaqueToken('Options.sampleId');
|
static SAMPLE_ID = new OpaqueToken('Options.sampleId');
|
||||||
static DEFAULT_DESCRIPTION = new OpaqueToken('Options.defaultDescription');
|
static DEFAULT_DESCRIPTION = new OpaqueToken('Options.defaultDescription');
|
||||||
|
@ -34,7 +32,7 @@ export class Options {
|
||||||
{provide: Options.FORCE_GC, useValue: false},
|
{provide: Options.FORCE_GC, useValue: false},
|
||||||
{provide: Options.PREPARE, useValue: Options.NO_PREPARE},
|
{provide: Options.PREPARE, useValue: Options.NO_PREPARE},
|
||||||
{provide: Options.MICRO_METRICS, useValue: {}}, {provide: Options.USER_METRICS, useValue: {}},
|
{provide: Options.MICRO_METRICS, useValue: {}}, {provide: Options.USER_METRICS, useValue: {}},
|
||||||
{provide: Options.NOW, useValue: () => DateWrapper.now()},
|
{provide: Options.NOW, useValue: () => new Date()},
|
||||||
{provide: Options.RECEIVED_DATA, useValue: false},
|
{provide: Options.RECEIVED_DATA, useValue: false},
|
||||||
{provide: Options.REQUEST_COUNT, useValue: false},
|
{provide: Options.REQUEST_COUNT, useValue: false},
|
||||||
{provide: Options.CAPTURE_FRAMES, useValue: false},
|
{provide: Options.CAPTURE_FRAMES, useValue: false},
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import {Inject, Injectable, OpaqueToken} from '@angular/core';
|
import {Inject, Injectable, OpaqueToken} from '@angular/core';
|
||||||
|
|
||||||
import {Options} from '../common_options';
|
import {Options} from '../common_options';
|
||||||
import {DateWrapper, Json} from '../facade/lang';
|
import {Json} from '../facade/lang';
|
||||||
import {MeasureValues} from '../measure_values';
|
import {MeasureValues} from '../measure_values';
|
||||||
import {Reporter} from '../reporter';
|
import {Reporter} from '../reporter';
|
||||||
import {SampleDescription} from '../sample_description';
|
import {SampleDescription} from '../sample_description';
|
||||||
|
@ -45,8 +45,7 @@ export class JsonFileReporter extends Reporter {
|
||||||
'completeSample': completeSample,
|
'completeSample': completeSample,
|
||||||
'validSample': validSample,
|
'validSample': validSample,
|
||||||
});
|
});
|
||||||
var filePath =
|
var filePath = `${this._path}/${this._description.id}_${this._now().getTime()}.json`;
|
||||||
`${this._path}/${this._description.id}_${DateWrapper.toMillis(this._now())}.json`;
|
|
||||||
return this._writeFile(filePath, content);
|
return this._writeFile(filePath, content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {Provider} from '@angular/core';
|
||||||
import {describe, expect, it} from '@angular/core/testing/testing_internal';
|
import {describe, expect, it} from '@angular/core/testing/testing_internal';
|
||||||
|
|
||||||
import {ConsoleReporter, MeasureValues, ReflectiveInjector, SampleDescription} from '../../index';
|
import {ConsoleReporter, MeasureValues, ReflectiveInjector, SampleDescription} from '../../index';
|
||||||
import {DateWrapper, isBlank, isPresent} from '../../src/facade/lang';
|
import {isBlank, isPresent} from '../../src/facade/lang';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('console reporter', () => {
|
describe('console reporter', () => {
|
||||||
|
@ -90,5 +90,5 @@ export function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
||||||
return new MeasureValues(runIndex, DateWrapper.fromMillis(time), values);
|
return new MeasureValues(runIndex, new Date(time), values);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
||||||
|
|
||||||
import {JsonFileReporter, MeasureValues, Options, ReflectiveInjector, SampleDescription} from '../../index';
|
import {JsonFileReporter, MeasureValues, Options, ReflectiveInjector, SampleDescription} from '../../index';
|
||||||
import {DateWrapper, Json, isPresent} from '../../src/facade/lang';
|
import {Json, isPresent} from '../../src/facade/lang';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('file reporter', () => {
|
describe('file reporter', () => {
|
||||||
|
@ -27,7 +27,7 @@ export function main() {
|
||||||
useValue: new SampleDescription(sampleId, descriptions, metrics)
|
useValue: new SampleDescription(sampleId, descriptions, metrics)
|
||||||
},
|
},
|
||||||
{provide: JsonFileReporter.PATH, useValue: path},
|
{provide: JsonFileReporter.PATH, useValue: path},
|
||||||
{provide: Options.NOW, useValue: () => DateWrapper.fromMillis(1234)}, {
|
{provide: Options.NOW, useValue: () => new Date(1234)}, {
|
||||||
provide: Options.WRITE_FILE,
|
provide: Options.WRITE_FILE,
|
||||||
useValue: (filename: string, content: string) => {
|
useValue: (filename: string, content: string) => {
|
||||||
loggedFile = {'filename': filename, 'content': content};
|
loggedFile = {'filename': filename, 'content': content};
|
||||||
|
@ -77,5 +77,5 @@ export function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
||||||
return new MeasureValues(runIndex, DateWrapper.fromMillis(time), values);
|
return new MeasureValues(runIndex, new Date(time), values);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
||||||
|
|
||||||
import {MeasureValues, MultiReporter, ReflectiveInjector, Reporter} from '../../index';
|
import {MeasureValues, MultiReporter, ReflectiveInjector, Reporter} from '../../index';
|
||||||
import {DateWrapper} from '../../src/facade/lang';
|
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
function createReporters(ids: any[]) {
|
function createReporters(ids: any[]) {
|
||||||
|
@ -26,7 +25,7 @@ export function main() {
|
||||||
|
|
||||||
it('should reportMeasureValues to all',
|
it('should reportMeasureValues to all',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
var mv = new MeasureValues(0, DateWrapper.now(), {});
|
var mv = new MeasureValues(0, new Date(), {});
|
||||||
createReporters(['m1', 'm2']).then((r) => r.reportMeasureValues(mv)).then((values) => {
|
createReporters(['m1', 'm2']).then((r) => r.reportMeasureValues(mv)).then((values) => {
|
||||||
|
|
||||||
expect(values).toEqual([{'id': 'm1', 'values': mv}, {'id': 'm2', 'values': mv}]);
|
expect(values).toEqual([{'id': 'm1', 'values': mv}, {'id': 'm2', 'values': mv}]);
|
||||||
|
@ -35,9 +34,8 @@ export function main() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should reportSample to call', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should reportSample to call', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
var completeSample = [
|
var completeSample =
|
||||||
new MeasureValues(0, DateWrapper.now(), {}), new MeasureValues(1, DateWrapper.now(), {})
|
[new MeasureValues(0, new Date(), {}), new MeasureValues(1, new Date(), {})];
|
||||||
];
|
|
||||||
var validSample = [completeSample[1]];
|
var validSample = [completeSample[1]];
|
||||||
|
|
||||||
createReporters(['m1', 'm2'])
|
createReporters(['m1', 'm2'])
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
||||||
|
|
||||||
import {MeasureValues, Metric, Options, ReflectiveInjector, Reporter, Sampler, Validator, WebDriverAdapter} from '../index';
|
import {MeasureValues, Metric, Options, ReflectiveInjector, Reporter, Sampler, Validator, WebDriverAdapter} from '../index';
|
||||||
import {DateWrapper, isBlank, isPresent} from '../src/facade/lang';
|
import {isBlank, isPresent} from '../src/facade/lang';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
var EMPTY_EXECUTE = () => {};
|
var EMPTY_EXECUTE = () => {};
|
||||||
|
@ -39,7 +39,7 @@ export function main() {
|
||||||
Options.DEFAULT_PROVIDERS, Sampler.PROVIDERS, {provide: Metric, useValue: metric},
|
Options.DEFAULT_PROVIDERS, Sampler.PROVIDERS, {provide: Metric, useValue: metric},
|
||||||
{provide: Reporter, useValue: reporter}, {provide: WebDriverAdapter, useValue: driver},
|
{provide: Reporter, useValue: reporter}, {provide: WebDriverAdapter, useValue: driver},
|
||||||
{provide: Options.EXECUTE, useValue: execute}, {provide: Validator, useValue: validator},
|
{provide: Options.EXECUTE, useValue: execute}, {provide: Validator, useValue: validator},
|
||||||
{provide: Options.NOW, useValue: () => DateWrapper.fromMillis(time++)}
|
{provide: Options.NOW, useValue: () => new Date(time++)}
|
||||||
];
|
];
|
||||||
if (isPresent(prepare)) {
|
if (isPresent(prepare)) {
|
||||||
providers.push({provide: Options.PREPARE, useValue: prepare});
|
providers.push({provide: Options.PREPARE, useValue: prepare});
|
||||||
|
@ -204,7 +204,7 @@ export function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
||||||
return new MeasureValues(runIndex, DateWrapper.fromMillis(time), values);
|
return new MeasureValues(runIndex, new Date(time), values);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCountingValidator(
|
function createCountingValidator(
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {describe, expect, it} from '@angular/core/testing/testing_internal';
|
||||||
|
|
||||||
import {MeasureValues, ReflectiveInjector, RegressionSlopeValidator} from '../../index';
|
import {MeasureValues, ReflectiveInjector, RegressionSlopeValidator} from '../../index';
|
||||||
import {ListWrapper} from '../../src/facade/collection';
|
import {ListWrapper} from '../../src/facade/collection';
|
||||||
import {DateWrapper} from '../../src/facade/lang';
|
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('regression slope validator', () => {
|
describe('regression slope validator', () => {
|
||||||
|
@ -62,5 +61,5 @@ export function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
||||||
return new MeasureValues(runIndex, DateWrapper.fromMillis(time), values);
|
return new MeasureValues(runIndex, new Date(time), values);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {describe, expect, it} from '@angular/core/testing/testing_internal';
|
||||||
|
|
||||||
import {MeasureValues, ReflectiveInjector, SizeValidator} from '../../index';
|
import {MeasureValues, ReflectiveInjector, SizeValidator} from '../../index';
|
||||||
import {ListWrapper} from '../../src/facade/collection';
|
import {ListWrapper} from '../../src/facade/collection';
|
||||||
import {DateWrapper} from '../../src/facade/lang';
|
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('size validator', () => {
|
describe('size validator', () => {
|
||||||
|
@ -47,5 +46,5 @@ export function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
function mv(runIndex: number, time: number, values: {[key: string]: number}) {
|
||||||
return new MeasureValues(runIndex, DateWrapper.fromMillis(time), values);
|
return new MeasureValues(runIndex, new Date(time), values);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,6 @@ import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
|
||||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_internal';
|
import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_internal';
|
||||||
import {browserDetection} from '@angular/platform-browser/testing/browser_util';
|
import {browserDetection} from '@angular/platform-browser/testing/browser_util';
|
||||||
|
|
||||||
import {DateWrapper} from '../../src/facade/lang';
|
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('DatePipe', () => {
|
describe('DatePipe', () => {
|
||||||
var date: Date;
|
var date: Date;
|
||||||
|
@ -27,7 +25,7 @@ export function main() {
|
||||||
// Tracking issue: https://github.com/angular/angular/issues/11187
|
// Tracking issue: https://github.com/angular/angular/issues/11187
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
date = DateWrapper.create(2015, 6, 15, 9, 3, 1);
|
date = new Date(2015, 5, 15, 9, 3, 1);
|
||||||
pipe = new DatePipe('en-US');
|
pipe = new DatePipe('en-US');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -301,19 +301,6 @@ export class Json {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DateWrapper {
|
|
||||||
static create(
|
|
||||||
year: number, month: number = 1, day: number = 1, hour: number = 0, minutes: number = 0,
|
|
||||||
seconds: number = 0, milliseconds: number = 0): Date {
|
|
||||||
return new Date(year, month - 1, day, hour, minutes, seconds, milliseconds);
|
|
||||||
}
|
|
||||||
static fromISOString(str: string): Date { return new Date(str); }
|
|
||||||
static fromMillis(ms: number): Date { return new Date(ms); }
|
|
||||||
static toMillis(date: Date): number { return date.getTime(); }
|
|
||||||
static now(): Date { return new Date(); }
|
|
||||||
static toJson(date: Date): string { return date.toJSON(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setValueOnPath(global: any, path: string, value: any) {
|
export function setValueOnPath(global: any, path: string, value: any) {
|
||||||
var parts = path.split('.');
|
var parts = path.split('.');
|
||||||
var obj: any = global;
|
var obj: any = global;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import {Injectable, Type} from '@angular/core';
|
import {Injectable, Type} from '@angular/core';
|
||||||
|
|
||||||
import {EventEmitter} from '../../facade/async';
|
import {EventEmitter} from '../../facade/async';
|
||||||
import {DateWrapper, StringWrapper, isPresent, print, stringify} from '../../facade/lang';
|
import {StringWrapper, isPresent, print, stringify} from '../../facade/lang';
|
||||||
|
|
||||||
import {MessageBus} from './message_bus';
|
import {MessageBus} from './message_bus';
|
||||||
import {Serializer} from './serializer';
|
import {Serializer} from './serializer';
|
||||||
|
@ -71,7 +71,7 @@ export class ClientMessageBroker_ extends ClientMessageBroker {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _generateMessageId(name: string): string {
|
private _generateMessageId(name: string): string {
|
||||||
var time: string = stringify(DateWrapper.toMillis(DateWrapper.now()));
|
var time: string = stringify(new Date().getTime());
|
||||||
var iteration: number = 0;
|
var iteration: number = 0;
|
||||||
var id: string = name + time + stringify(iteration);
|
var id: string = name + time + stringify(iteration);
|
||||||
while (isPresent((this as any /** TODO #9100 */)._pending[id])) {
|
while (isPresent((this as any /** TODO #9100 */)._pending[id])) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {PromiseWrapper} from '@angular/facade/src/async';
|
import {PromiseWrapper} from '@angular/facade/src/async';
|
||||||
import {ListWrapper, Map, MapWrapper} from '@angular/facade/src/collection';
|
import {ListWrapper, Map, MapWrapper} from '@angular/facade/src/collection';
|
||||||
import {DateWrapper, Type, isPresent, print} from '@angular/facade/src/lang';
|
import {Type, isPresent, print} from '@angular/facade/src/lang';
|
||||||
import {bootstrap} from '@angular/platform-browser';
|
import {bootstrap} from '@angular/platform-browser';
|
||||||
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
||||||
import {DOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
import {DOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||||
|
@ -44,10 +44,10 @@ export function main() {
|
||||||
|
|
||||||
function measureWrapper(func, desc) {
|
function measureWrapper(func, desc) {
|
||||||
return function() {
|
return function() {
|
||||||
var begin = DateWrapper.now();
|
var begin = new Date();
|
||||||
print(`[${desc}] Begin...`);
|
print(`[${desc}] Begin...`);
|
||||||
var onSuccess = function(_) {
|
var onSuccess = function(_) {
|
||||||
var elapsedMs = DateWrapper.toMillis(DateWrapper.now()) - DateWrapper.toMillis(begin);
|
var elapsedMs = new Date().getTime() - begin.getTime();
|
||||||
print(`[${desc}] ...done, took ${elapsedMs} ms`);
|
print(`[${desc}] ...done, took ${elapsedMs} ms`);
|
||||||
};
|
};
|
||||||
var onError = function(e) { DOM.logError(e); };
|
var onError = function(e) { DOM.logError(e); };
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
|
|
||||||
import {Component, Injectable} from '@angular/core';
|
import {Component, Injectable} from '@angular/core';
|
||||||
import {DateWrapper, isPresent} from '@angular/core/src/facade/lang';
|
import {isPresent} from '@angular/core/src/facade/lang';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
|
|
||||||
import * as db from './data';
|
import * as db from './data';
|
||||||
|
@ -102,10 +102,7 @@ export class InboxCmp {
|
||||||
if (sortEmailsByDate) {
|
if (sortEmailsByDate) {
|
||||||
this.items.sort(
|
this.items.sort(
|
||||||
(a: InboxRecord, b: InboxRecord) =>
|
(a: InboxRecord, b: InboxRecord) =>
|
||||||
DateWrapper.toMillis(DateWrapper.fromISOString(a.date)) <
|
new Date(a.date).getTime() < new Date(b.date).getTime() ? -1 : 1);
|
||||||
DateWrapper.toMillis(DateWrapper.fromISOString(b.date)) ?
|
|
||||||
-1 :
|
|
||||||
1);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue