style(lint): re-format modules/@angular
This commit is contained in:
@ -1,11 +1,4 @@
|
||||
import {
|
||||
inject,
|
||||
describe,
|
||||
it,
|
||||
expect,
|
||||
beforeEach,
|
||||
beforeEachProviders,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {inject, describe, it, expect, beforeEach, beforeEachProviders,} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
import {ObservableWrapper, TimerWrapper} from '../../../src/facade/async';
|
||||
import {MessageBus} from '@angular/platform-browser/src/web_workers/shared/message_bus';
|
||||
@ -18,15 +11,15 @@ export function main() {
|
||||
/**
|
||||
* Tests the PostMessageBus in TypeScript and the IsolateMessageBus in Dart
|
||||
*/
|
||||
describe("MessageBus", () => {
|
||||
describe('MessageBus', () => {
|
||||
var bus: MessageBus;
|
||||
|
||||
beforeEach(() => { bus = createConnectedMessageBus(); });
|
||||
|
||||
it("should pass messages in the same channel from sink to source",
|
||||
it('should pass messages in the same channel from sink to source',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const CHANNEL = "CHANNEL 1";
|
||||
const MESSAGE = "Test message";
|
||||
const CHANNEL = 'CHANNEL 1';
|
||||
const MESSAGE = 'Test message';
|
||||
bus.initChannel(CHANNEL, false);
|
||||
|
||||
var fromEmitter = bus.from(CHANNEL);
|
||||
@ -38,9 +31,9 @@ export function main() {
|
||||
ObservableWrapper.callEmit(toEmitter, MESSAGE);
|
||||
}));
|
||||
|
||||
it("should broadcast", inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const CHANNEL = "CHANNEL 1";
|
||||
const MESSAGE = "TESTING";
|
||||
it('should broadcast', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const CHANNEL = 'CHANNEL 1';
|
||||
const MESSAGE = 'TESTING';
|
||||
const NUM_LISTENERS = 2;
|
||||
bus.initChannel(CHANNEL, false);
|
||||
|
||||
@ -62,11 +55,12 @@ export function main() {
|
||||
ObservableWrapper.callEmit(toEmitter, MESSAGE);
|
||||
}));
|
||||
|
||||
it("should keep channels independent", inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const CHANNEL_ONE = "CHANNEL 1";
|
||||
const CHANNEL_TWO = "CHANNEL 2";
|
||||
const MESSAGE_ONE = "This is a message on CHANNEL 1";
|
||||
const MESSAGE_TWO = "This is a message on CHANNEL 2";
|
||||
it('should keep channels independent',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const CHANNEL_ONE = 'CHANNEL 1';
|
||||
const CHANNEL_TWO = 'CHANNEL 2';
|
||||
const MESSAGE_ONE = 'This is a message on CHANNEL 1';
|
||||
const MESSAGE_TWO = 'This is a message on CHANNEL 2';
|
||||
var callCount = 0;
|
||||
bus.initChannel(CHANNEL_ONE, false);
|
||||
bus.initChannel(CHANNEL_TWO, false);
|
||||
@ -96,9 +90,9 @@ export function main() {
|
||||
}));
|
||||
});
|
||||
|
||||
describe("PostMessageBusSink", () => {
|
||||
describe('PostMessageBusSink', () => {
|
||||
var bus: MessageBus;
|
||||
const CHANNEL = "Test Channel";
|
||||
const CHANNEL = 'Test Channel';
|
||||
|
||||
function setup(runInZone: boolean, zone: NgZone) {
|
||||
bus.attachToZone(zone);
|
||||
@ -111,39 +105,39 @@ export function main() {
|
||||
// TODO(mlaval): timeout is fragile, test to be rewritten
|
||||
function flushMessages(fn: () => void) { TimerWrapper.setTimeout(fn, 50); }
|
||||
|
||||
it("should buffer messages and wait for the zone to exit before sending",
|
||||
it('should buffer messages and wait for the zone to exit before sending',
|
||||
withProviders(() => [{provide: NgZone, useClass: MockNgZone}])
|
||||
.inject([AsyncTestCompleter, NgZone],
|
||||
(async: AsyncTestCompleter, zone: MockNgZone) => {
|
||||
bus = createConnectedMessageBus();
|
||||
setup(true, zone);
|
||||
.inject(
|
||||
[AsyncTestCompleter, NgZone],
|
||||
(async: AsyncTestCompleter, zone: MockNgZone) => {
|
||||
bus = createConnectedMessageBus();
|
||||
setup(true, zone);
|
||||
|
||||
var wasCalled = false;
|
||||
ObservableWrapper.subscribe(bus.from(CHANNEL),
|
||||
(message) => { wasCalled = true; });
|
||||
ObservableWrapper.callEmit(bus.to(CHANNEL), "hi");
|
||||
var wasCalled = false;
|
||||
ObservableWrapper.subscribe(bus.from(CHANNEL), (message) => { wasCalled = true; });
|
||||
ObservableWrapper.callEmit(bus.to(CHANNEL), 'hi');
|
||||
|
||||
|
||||
flushMessages(() => {
|
||||
expect(wasCalled).toBeFalsy();
|
||||
flushMessages(() => {
|
||||
expect(wasCalled).toBeFalsy();
|
||||
|
||||
zone.simulateZoneExit();
|
||||
flushMessages(() => {
|
||||
expect(wasCalled).toBeTruthy();
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
}),
|
||||
zone.simulateZoneExit();
|
||||
flushMessages(() => {
|
||||
expect(wasCalled).toBeTruthy();
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
}),
|
||||
500);
|
||||
|
||||
it("should send messages immediatly when run outside the zone",
|
||||
it('should send messages immediatly when run outside the zone',
|
||||
inject([AsyncTestCompleter, NgZone], (async: AsyncTestCompleter, zone: MockNgZone) => {
|
||||
bus = createConnectedMessageBus();
|
||||
setup(false, zone);
|
||||
|
||||
var wasCalled = false;
|
||||
ObservableWrapper.subscribe(bus.from(CHANNEL), (message) => { wasCalled = true; });
|
||||
ObservableWrapper.callEmit(bus.to(CHANNEL), "hi");
|
||||
ObservableWrapper.callEmit(bus.to(CHANNEL), 'hi');
|
||||
|
||||
flushMessages(() => {
|
||||
expect(wasCalled).toBeTruthy();
|
||||
|
@ -1,9 +1,6 @@
|
||||
import {
|
||||
PostMessageBusSource,
|
||||
PostMessageBusSink,
|
||||
PostMessageBus
|
||||
} from '@angular/platform-browser/src/web_workers/shared/post_message_bus';
|
||||
import {MessageBus} from '@angular/platform-browser/src/web_workers/shared/message_bus';
|
||||
import {PostMessageBus, PostMessageBusSink, PostMessageBusSource} from '@angular/platform-browser/src/web_workers/shared/post_message_bus';
|
||||
|
||||
|
||||
/*
|
||||
* Returns a PostMessageBus thats sink is connected to its own source.
|
||||
@ -21,10 +18,10 @@ class MockPostMessage {
|
||||
private _listener: EventListener;
|
||||
|
||||
addEventListener(type: string, listener: EventListener, useCapture?: boolean): void {
|
||||
if (type === "message") {
|
||||
if (type === 'message') {
|
||||
this._listener = listener;
|
||||
}
|
||||
}
|
||||
|
||||
postMessage(data: any, transfer?:[ArrayBuffer]): void { this._listener(<any>{data: data}); }
|
||||
postMessage(data: any, transfer?: [ArrayBuffer]): void { this._listener(<any>{data: data}); }
|
||||
}
|
||||
|
@ -1,15 +1,8 @@
|
||||
import {
|
||||
inject,
|
||||
describe,
|
||||
ddescribe,
|
||||
beforeEach,
|
||||
it,
|
||||
expect
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {beforeEach, ddescribe, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
||||
import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/render_store';
|
||||
|
||||
export function main() {
|
||||
describe("RenderStoreSpec", () => {
|
||||
describe('RenderStoreSpec', () => {
|
||||
var store: RenderStore;
|
||||
beforeEach(() => { store = new RenderStore(); });
|
||||
|
||||
|
@ -1,35 +1,24 @@
|
||||
import {
|
||||
inject,
|
||||
describe,
|
||||
it,
|
||||
iit,
|
||||
expect,
|
||||
beforeEach,
|
||||
beforeEachProviders,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {inject, describe, it, iit, expect, beforeEach, beforeEachProviders,} from '@angular/core/testing/testing_internal';
|
||||
import {browserDetection} from '@angular/platform-browser/testing';
|
||||
import {createPairedMessageBuses} from './web_worker_test_util';
|
||||
import {Serializer, PRIMITIVE} from '@angular/platform-browser/src/web_workers/shared/serializer';
|
||||
import {
|
||||
ServiceMessageBroker,
|
||||
ServiceMessageBroker_
|
||||
} from '@angular/platform-browser/src/web_workers/shared/service_message_broker';
|
||||
import {ServiceMessageBroker, ServiceMessageBroker_} from '@angular/platform-browser/src/web_workers/shared/service_message_broker';
|
||||
import {ObservableWrapper, PromiseWrapper} from '../../../src/facade/async';
|
||||
import {provide} from '@angular/core';
|
||||
import {ON_WEB_WORKER} from '@angular/platform-browser/src/web_workers/shared/api';
|
||||
import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/render_store';
|
||||
|
||||
export function main() {
|
||||
const CHANNEL = "UIMessageBroker Test Channel";
|
||||
const TEST_METHOD = "TEST_METHOD";
|
||||
const CHANNEL = 'UIMessageBroker Test Channel';
|
||||
const TEST_METHOD = 'TEST_METHOD';
|
||||
const PASSED_ARG_1 = 5;
|
||||
const PASSED_ARG_2 = 'TEST';
|
||||
const RESULT = 20;
|
||||
const ID = "methodId";
|
||||
const ID = 'methodId';
|
||||
|
||||
beforeEachProviders(() => [Serializer, {provide: ON_WEB_WORKER, useValue: true}, RenderStore]);
|
||||
|
||||
describe("UIMessageBroker", () => {
|
||||
describe('UIMessageBroker', () => {
|
||||
var messageBuses: any /** TODO #9100 */;
|
||||
|
||||
beforeEach(() => {
|
||||
@ -37,30 +26,32 @@ export function main() {
|
||||
messageBuses.ui.initChannel(CHANNEL);
|
||||
messageBuses.worker.initChannel(CHANNEL);
|
||||
});
|
||||
it("should call registered method with correct arguments",
|
||||
it('should call registered method with correct arguments',
|
||||
inject([Serializer], (serializer: Serializer) => {
|
||||
var broker = new ServiceMessageBroker_(messageBuses.ui, serializer, CHANNEL);
|
||||
broker.registerMethod(TEST_METHOD, [PRIMITIVE, PRIMITIVE], (arg1, arg2) => {
|
||||
expect(arg1).toEqual(PASSED_ARG_1);
|
||||
expect(arg2).toEqual(PASSED_ARG_2);
|
||||
});
|
||||
ObservableWrapper.callEmit(messageBuses.worker.to(CHANNEL),
|
||||
{'method': TEST_METHOD, 'args': [PASSED_ARG_1, PASSED_ARG_2]});
|
||||
ObservableWrapper.callEmit(
|
||||
messageBuses.worker.to(CHANNEL),
|
||||
{'method': TEST_METHOD, 'args': [PASSED_ARG_1, PASSED_ARG_2]});
|
||||
}));
|
||||
|
||||
// TODO(pkozlowski): this fails only in Edge with
|
||||
// "No provider for RenderStore! (Serializer -> RenderStore)"
|
||||
if (!browserDetection.isEdge) {
|
||||
it("should return promises to the worker", inject([Serializer], (serializer: Serializer) => {
|
||||
it('should return promises to the worker', inject([Serializer], (serializer: Serializer) => {
|
||||
var broker = new ServiceMessageBroker_(messageBuses.ui, serializer, CHANNEL);
|
||||
broker.registerMethod(TEST_METHOD, [PRIMITIVE], (arg1) => {
|
||||
expect(arg1).toEqual(PASSED_ARG_1);
|
||||
return PromiseWrapper.wrap(() => { return RESULT; });
|
||||
});
|
||||
ObservableWrapper.callEmit(messageBuses.worker.to(CHANNEL),
|
||||
{'method': TEST_METHOD, 'id': ID, 'args': [PASSED_ARG_1]});
|
||||
ObservableWrapper.callEmit(
|
||||
messageBuses.worker.to(CHANNEL),
|
||||
{'method': TEST_METHOD, 'id': ID, 'args': [PASSED_ARG_1]});
|
||||
ObservableWrapper.subscribe(messageBuses.worker.from(CHANNEL), (data: any) => {
|
||||
expect(data.type).toEqual("result");
|
||||
expect(data.type).toEqual('result');
|
||||
expect(data.id).toEqual(ID);
|
||||
expect(data.value).toEqual(RESULT);
|
||||
});
|
||||
|
@ -1,21 +1,16 @@
|
||||
import {StringMapWrapper, ListWrapper} from '../../../src/facade/collection';
|
||||
import {PromiseWrapper} from '../../../src/facade/async';
|
||||
import {NgZone} from '@angular/core/src/zone/ng_zone';
|
||||
import {expect} from '@angular/core/testing';
|
||||
import {UiArguments} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
|
||||
import {ClientMessageBroker, ClientMessageBrokerFactory_} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
|
||||
import {MessageBus, MessageBusSink, MessageBusSource} from '@angular/platform-browser/src/web_workers/shared/message_bus';
|
||||
|
||||
import {PromiseWrapper} from '../../../src/facade/async';
|
||||
import {ListWrapper, StringMapWrapper} from '../../../src/facade/collection';
|
||||
import {BaseException, WrappedException} from '../../../src/facade/exceptions';
|
||||
import {Type, isPresent} from '../../../src/facade/lang';
|
||||
import {SpyMessageBroker} from '../worker/spies';
|
||||
import {expect} from '@angular/core/testing';
|
||||
import {
|
||||
MessageBusSink,
|
||||
MessageBusSource,
|
||||
MessageBus
|
||||
} from '@angular/platform-browser/src/web_workers/shared/message_bus';
|
||||
import {
|
||||
ClientMessageBroker,
|
||||
ClientMessageBrokerFactory_
|
||||
} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
|
||||
|
||||
import {MockEventEmitter} from './mock_event_emitter';
|
||||
import {BaseException, WrappedException} from '../../../src/facade/exceptions';
|
||||
import {NgZone} from '@angular/core/src/zone/ng_zone';
|
||||
|
||||
var __unused: Promise<any>; // avoid unused import when Promise union types are erased
|
||||
|
||||
@ -32,8 +27,9 @@ export function createPairedMessageBuses(): PairedMessageBuses {
|
||||
var uiMessageBusSink = new MockMessageBusSink(secondChannels);
|
||||
var workerMessageBusSource = new MockMessageBusSource(secondChannels);
|
||||
|
||||
return new PairedMessageBuses(new MockMessageBus(uiMessageBusSink, uiMessageBusSource),
|
||||
new MockMessageBus(workerMessageBusSink, workerMessageBusSource));
|
||||
return new PairedMessageBuses(
|
||||
new MockMessageBus(uiMessageBusSink, uiMessageBusSource),
|
||||
new MockMessageBus(workerMessageBusSink, workerMessageBusSource));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,29 +38,29 @@ export function createPairedMessageBuses(): PairedMessageBuses {
|
||||
* If a handler is provided it will be called to handle the request.
|
||||
* Only intended to be called on a given broker instance once.
|
||||
*/
|
||||
export function expectBrokerCall(broker: SpyMessageBroker, methodName: string, vals?: Array<any>,
|
||||
handler?: (..._: any[]) => Promise<any>| void): void {
|
||||
broker.spy("runOnService")
|
||||
.andCallFake((args: UiArguments, returnType: Type) => {
|
||||
expect(args.method).toEqual(methodName);
|
||||
if (isPresent(vals)) {
|
||||
expect(args.args.length).toEqual(vals.length);
|
||||
ListWrapper.forEachWithIndex(vals, (v, i) => {expect(v).toEqual(args.args[i].value)});
|
||||
}
|
||||
var promise: any /** TODO #9100 */ = null;
|
||||
if (isPresent(handler)) {
|
||||
let givenValues = args.args.map((arg) => {arg.value});
|
||||
if (givenValues.length > 0) {
|
||||
promise = handler(givenValues);
|
||||
} else {
|
||||
promise = handler();
|
||||
}
|
||||
}
|
||||
if (promise == null) {
|
||||
promise = PromiseWrapper.wrap(() => {});
|
||||
}
|
||||
return promise;
|
||||
});
|
||||
export function expectBrokerCall(
|
||||
broker: SpyMessageBroker, methodName: string, vals?: Array<any>,
|
||||
handler?: (..._: any[]) => Promise<any>| void): void {
|
||||
broker.spy('runOnService').andCallFake((args: UiArguments, returnType: Type) => {
|
||||
expect(args.method).toEqual(methodName);
|
||||
if (isPresent(vals)) {
|
||||
expect(args.args.length).toEqual(vals.length);
|
||||
ListWrapper.forEachWithIndex(vals, (v, i) => {expect(v).toEqual(args.args[i].value)});
|
||||
}
|
||||
var promise: any /** TODO #9100 */ = null;
|
||||
if (isPresent(handler)) {
|
||||
let givenValues = args.args.map((arg) => {arg.value});
|
||||
if (givenValues.length > 0) {
|
||||
promise = handler(givenValues);
|
||||
} else {
|
||||
promise = handler();
|
||||
}
|
||||
}
|
||||
if (promise == null) {
|
||||
promise = PromiseWrapper.wrap(() => {});
|
||||
}
|
||||
return promise;
|
||||
});
|
||||
}
|
||||
|
||||
export class PairedMessageBuses {
|
||||
|
Reference in New Issue
Block a user