This commit is contained in:
Alexander T 2019-05-13 13:02:19 +03:00
Родитель c09f2dd1d7
Коммит 6c18e8fd12
13 изменённых файлов: 1866 добавлений и 1018 удалений

11
.eslintrc Normal file
Просмотреть файл

@ -0,0 +1,11 @@
{
"extends": ["skype"],
"env": {
"jasmine": true
},
"rules": {
"@typescript-eslint/interface-name-prefix": "off",
"no-console": ["error", { "allow": ["error", "warn"] }]
}
}

Просмотреть файл

@ -15,6 +15,7 @@ install:
- npm i
script:
- npm run lint
- npm run test
- npm run build

2569
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -6,8 +6,9 @@
"scripts": {
"prepare": "tsc",
"clean": "rimraf dist",
"build": "npm run tslint && tsc",
"tslint": "tslint --project tsconfig.json -r tslint.json --fix || true",
"build": "npm run lint && tsc",
"lint": "eslint --config .eslintrc src/* test/*",
"lint:fix": "npm run lint -- --fix",
"test": "npm run clean && karma start --singleRun",
"test:watch": "npm run clean && karma start",
"test:browser": "npm run clean && karma start --browsers=Chrome --single-run=false --auto-watch"
@ -18,27 +19,29 @@
"synctasks": "^0.3.3"
},
"devDependencies": {
"@types/faker": "4.1.4",
"@types/jasmine": "3.3.5",
"@types/faker": "4.1.5",
"@types/jasmine": "3.3.12",
"@types/jasmine-ajax": "3.1.39",
"@typescript-eslint/eslint-plugin": "1.9.0",
"@typescript-eslint/parser": "1.9.0",
"eslint": "5.16.0",
"eslint-config-skype": "0.0.3",
"faker": "4.1.0",
"fork-ts-checker-webpack-plugin": "0.5.2",
"jasmine": "3.3.1",
"jasmine-core": "3.3.0",
"karma": "3.1.4",
"fork-ts-checker-webpack-plugin": "1.3.3",
"jasmine": "3.4.0",
"jasmine-core": "3.4.0",
"karma": "4.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-jasmine": "2.0.1",
"karma-jasmine-ajax": "0.1.13",
"karma-jasmine-html-reporter": "1.4.0",
"karma-jasmine-html-reporter": "1.4.2",
"karma-sourcemap-loader": "0.3.7",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "4.0.0-beta.0",
"rimraf": "2.6.3",
"ts-loader": "5.3.3",
"tslint": "5.12.1",
"tslint-microsoft-contrib": "6.0.0",
"typescript": "3.2.4",
"webpack": "4.28.4"
"ts-loader": "6.0.1",
"typescript": "3.4.5",
"webpack": "4.31.0"
},
"repository": {
"type": "git",

Просмотреть файл

@ -22,9 +22,9 @@ export class ExponentialTime {
* @param jitterFactor
*/
constructor(private _initialTime: number,
private _maxTime: number,
private _growFactor = DEFAULT_TIME_GROW_FACTOR,
private _jitterFactor = DEFAULT_TIME_JITTER) {
private _maxTime: number,
private _growFactor = DEFAULT_TIME_GROW_FACTOR,
private _jitterFactor = DEFAULT_TIME_JITTER) {
assert(this._initialTime > 0, 'Initial delay must be positive');
assert(this._maxTime > 0, 'Delay upper bound must be positive');

Просмотреть файл

@ -10,7 +10,7 @@ import * as SyncTasks from 'synctasks';
import { defaults, isString } from 'lodash';
import { WebRequestOptions, SimpleWebRequest, WebResponse, Headers } from './SimpleWebRequest';
export type HttpAction = 'POST'|'GET'|'PUT'|'DELETE'|'PATCH';
export type HttpAction = 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH';
export interface ApiCallOptions extends WebRequestOptions {
backendUrl?: string;
@ -36,21 +36,23 @@ export class GenericRestClient {
protected _defaultOptions: ApiCallOptions = {
excludeEndpointUrl: false,
withCredentials: false,
retries: 0,
retries: 0
};
constructor(endpointUrl: string) {
this._endpointUrl = endpointUrl;
}
protected _performApiCall<T>(apiPath: string, action: HttpAction, objToPost: any, givenOptions?: ApiCallOptions)
: SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
protected _performApiCall<T>(apiPath: string,
action: HttpAction,
objToPost: any,
givenOptions?: ApiCallOptions): SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
let options = defaults<ApiCallOptions, ApiCallOptions, ApiCallOptions>({}, givenOptions || {}, this._defaultOptions);
if (objToPost) {
options.sendData = objToPost;
}
if (options.eTag) {
if (!options.augmentHeaders) {
options.augmentHeaders = {};
@ -64,8 +66,13 @@ export class GenericRestClient {
const finalUrl = options.excludeEndpointUrl ? apiPath : this._endpointUrl + apiPath;
return new SimpleWebRequest<T, ApiCallOptions>(action, finalUrl, options, () => this._getHeaders(options),
() => this._blockRequestUntil(options))
return new SimpleWebRequest<T, ApiCallOptions>(
action,
finalUrl,
options,
() => this._getHeaders(options),
() => this._blockRequestUntil(options)
)
.start()
.then(response => {
this._processSuccessResponse<T>(response);
@ -80,7 +87,7 @@ export class GenericRestClient {
// Override (but make sure to call super and chain appropriately) this function if you want to add more blocking criteria.
// Also, this might be called multiple times to check if the conditions changed
protected _blockRequestUntil(options: ApiCallOptions): SyncTasks.Promise<void>|undefined {
protected _blockRequestUntil(options: ApiCallOptions): SyncTasks.Promise<void> | undefined {
// No-op by default
return undefined;
}
@ -96,8 +103,7 @@ export class GenericRestClient {
.then(resp => resp.body);
}
performApiGetDetailed<T>(apiPath: string, options?: ApiCallOptions)
: SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
performApiGetDetailed<T>(apiPath: string, options?: ApiCallOptions): SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
return this._performApiCall<T>(apiPath, 'GET', undefined, options);
}
@ -107,8 +113,9 @@ export class GenericRestClient {
.then(resp => resp.body);
}
performApiPostDetailed<T>(apiPath: string, objToPost: any, options?: ApiCallOptions)
: SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
performApiPostDetailed<T>(apiPath: string,
objToPost: any,
options?: ApiCallOptions): SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
return this._performApiCall<T>(apiPath, 'POST', objToPost, options);
}
@ -118,8 +125,9 @@ export class GenericRestClient {
.then(resp => resp.body);
}
performApiPatchDetailed<T>(apiPath: string, objToPatch: any, options?: ApiCallOptions)
: SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
performApiPatchDetailed<T>(apiPath: string,
objToPatch: any,
options?: ApiCallOptions): SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
return this._performApiCall<T>(apiPath, 'PATCH', objToPatch, options);
}
@ -129,8 +137,7 @@ export class GenericRestClient {
.then(resp => resp.body);
}
performApiPutDetailed<T>(apiPath: string, objToPut: any, options?: ApiCallOptions)
: SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
performApiPutDetailed<T>(apiPath: string, objToPut: any, options?: ApiCallOptions): SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
return this._performApiCall<T>(apiPath, 'PUT', objToPut, options);
}
@ -140,8 +147,9 @@ export class GenericRestClient {
.then(resp => resp.body);
}
performApiDeleteDetailed<T>(apiPath: string, objToDelete: any, options?: ApiCallOptions)
: SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
performApiDeleteDetailed<T>(apiPath: string,
objToDelete: any,
options?: ApiCallOptions): SyncTasks.Promise<WebResponse<T, ApiCallOptions>> {
return this._performApiCall<T>(apiPath, 'DELETE', objToDelete, options);
}
}

Просмотреть файл

@ -84,7 +84,7 @@ export interface NativeBlobFileData {
}
export interface NativeFileData {
file: NativeBlobFileData|File;
file: NativeBlobFileData | File;
}
export interface XMLHttpRequestProgressEvent extends ProgressEvent {
@ -123,16 +123,16 @@ export interface WebRequestOptions {
augmentErrorResponse?: (resp: WebErrorResponse) => void;
}
function isJsonContentType(ct: string) {
return ct && ct.indexOf('application/json') === 0;
function isJsonContentType(ct: string): boolean {
return !!ct && ct.indexOf('application/json') === 0;
}
function isFormContentType(ct: string) {
return ct && ct.indexOf('application/x-www-form-urlencoded') === 0;
function isFormContentType(ct: string): boolean {
return !!ct && ct.indexOf('application/x-www-form-urlencoded') === 0;
}
function isFormDataContentType(ct: string) {
return ct && ct.indexOf('multipart/form-data') === 0;
function isFormDataContentType(ct: string): boolean {
return !!ct && ct.indexOf('multipart/form-data') === 0;
}
export const DefaultOptions: WebRequestOptions = {
@ -140,7 +140,7 @@ export const DefaultOptions: WebRequestOptions = {
};
export interface ISimpleWebRequestOptions {
// Maximum executing requests allowed. Other requests will be queued until free spots become available.
// Maximum executing requests allowed. Other requests will be queued until free spots become available.
MaxSimultaneousRequests: number;
// We've seen cases where requests have reached completion but callbacks haven't been called (typically during failed
@ -160,7 +160,7 @@ export let SimpleWebRequestOptions: ISimpleWebRequestOptions = {
clearTimeout: (id: number) => window.clearTimeout(id)
};
export function DefaultErrorHandler(webRequest: SimpleWebRequestBase, errResp: WebTransportErrorResponse) {
export function DefaultErrorHandler(webRequest: SimpleWebRequestBase, errResp: WebTransportErrorResponse): ErrorHandlingType {
if (errResp.canceled || !errResp.statusCode || errResp.statusCode >= 400 && errResp.statusCode < 600) {
// Fail canceled/0/4xx/5xx requests immediately.
// These are permenent failures, and shouldn't have retry logic applied to them.
@ -210,13 +210,13 @@ export abstract class SimpleWebRequestBase<TOptions extends WebRequestOptions =
// 2. Safari seems to have a bug where sometimes it double-resolves happily-completed xmlhttprequests
protected _finishHandled = false;
protected _retryTimer: number|undefined;
protected _retryTimer: number | undefined;
protected _retryExponentialTime = new ExponentialTime(1000, 300000);
constructor(protected _action: string,
protected _url: string, options: TOptions,
protected _getHeaders?: () => Headers,
protected _blockRequestUntil?: () => SyncTasks.Promise<void>|undefined) {
protected _url: string, options: TOptions,
protected _getHeaders?: () => Headers,
protected _blockRequestUntil?: () => SyncTasks.Promise<void> | undefined) {
this._options = _.defaults(options, DefaultOptions);
}
@ -226,7 +226,7 @@ export abstract class SimpleWebRequestBase<TOptions extends WebRequestOptions =
abstract abort(): void;
protected static checkQueueProcessing() {
protected static checkQueueProcessing(): void {
while (requestQueue.length > 0 && executingList.length < SimpleWebRequestOptions.MaxSimultaneousRequests) {
const req = requestQueue.shift()!!!;
blockedList.push(req);
@ -248,7 +248,7 @@ export abstract class SimpleWebRequestBase<TOptions extends WebRequestOptions =
}
}
private static _scheduleHungRequestCleanupIfNeeded() {
private static _scheduleHungRequestCleanupIfNeeded(): void {
// Schedule a cleanup timer if needed
if (executingList.length > 0 && hungRequestCleanupTimer === undefined) {
hungRequestCleanupTimer = SimpleWebRequestOptions.setTimeout(this._hungRequestCleanupTimerCallback,
@ -273,7 +273,7 @@ export abstract class SimpleWebRequestBase<TOptions extends WebRequestOptions =
});
SimpleWebRequest._scheduleHungRequestCleanupIfNeeded();
}
};
protected _removeFromQueue(): void {
// Only pull from request queue and executing queue here - pulling from the blocked queue can result in requests
@ -310,7 +310,7 @@ export abstract class SimpleWebRequestBase<TOptions extends WebRequestOptions =
if (this._options.timeout) {
const timeoutSupported = timeoutSupportStatus;
// Use manual timer if we don't know about timeout support
// Use manual timer if we don't know about timeout support
if (timeoutSupported !== FeatureSupportStatus.Supported) {
this._assertAndClean(!this._requestTimeoutTimer, 'Double-fired requestTimeoutTimer');
this._requestTimeoutTimer = SimpleWebRequestOptions.setTimeout(() => {
@ -347,7 +347,7 @@ export abstract class SimpleWebRequestBase<TOptions extends WebRequestOptions =
// Set global status to detecting, leave local state so we can set a timer on finish
onLoadErrorSupportStatus = FeatureSupportStatus.Detecting;
}
this._xhr.onreadystatechange = (e) => {
this._xhr.onreadystatechange = () => {
if (!this._xhr) {
return;
}
@ -380,7 +380,7 @@ export abstract class SimpleWebRequestBase<TOptions extends WebRequestOptions =
};
} else if (this._options.streamingDownloadProgress) {
// If we support onload and such, but have a streaming download handler, still trap the oRSC.
this._xhr.onreadystatechange = (e) => {
this._xhr.onreadystatechange = () => {
if (!this._xhr) {
return;
}
@ -414,11 +414,10 @@ export abstract class SimpleWebRequestBase<TOptions extends WebRequestOptions =
};
}
this._xhr.onabort = (e) => {
this._xhr.onabort = () => {
// If the browser cancels us (page navigation or whatever), it sometimes calls both the readystatechange and this,
// so make sure we know that this is an abort.
this._aborted = true;
this._respond('Aborted');
};
@ -663,8 +662,11 @@ export class SimpleWebRequest<TBody, TOptions extends WebRequestOptions = WebReq
private _deferred: SyncTasks.Deferred<WebResponse<TBody, TOptions>>;
constructor(action: string, url: string, options: TOptions, getHeaders?: () => Headers,
blockRequestUntil?: () => SyncTasks.Promise<void>|undefined) {
constructor(action: string,
url: string,
options: TOptions,
getHeaders?: () => Headers,
blockRequestUntil?: () => SyncTasks.Promise<void> | undefined) {
super(action, url, options, getHeaders, blockRequestUntil);
}
@ -717,7 +719,7 @@ export class SimpleWebRequest<TBody, TOptions extends WebRequestOptions = WebReq
return this._deferred.promise();
}
protected _respond(errorStatusText?: string) {
protected _respond(errorStatusText?: string): void {
if (this._finishHandled) {
// Aborted web requests often double-finish due to odd browser behavior, but non-aborted requests shouldn't...
// Unfortunately, this assertion fires frequently in the Safari browser, presumably due to a non-standard
@ -813,7 +815,7 @@ export class SimpleWebRequest<TBody, TOptions extends WebRequestOptions = WebReq
statusCode: statusCode,
statusText: statusText,
headers: headers,
body: body as TBody,
body: body as TBody
};
this._deferred.resolve(resp);
@ -828,7 +830,7 @@ export class SimpleWebRequest<TBody, TOptions extends WebRequestOptions = WebReq
headers: headers,
body: body,
canceled: this._aborted,
timedOut: this._timedOut,
timedOut: this._timedOut
};
if (this._options.augmentErrorResponse) {

Просмотреть файл

@ -3,7 +3,7 @@
* Copyright: Microsoft 2019
*/
export const assert = (cond: boolean, message: string) => {
export const assert = (cond: boolean, message: string): void => {
if (!cond) {
throw new Error(message);
}

Просмотреть файл

@ -25,7 +25,7 @@ const calculateExponentialTime = (currentTime: number, growFactor: number, jitte
const calculateDefaultExponentialTime = (initialTime: number, jitterFactor: number): number => (
Math.round(initialTime * (1 + RANDOM_VALUE * jitterFactor))
)
);
describe('ExponentialTime', () => {
beforeAll(() => {

Просмотреть файл

@ -36,7 +36,7 @@ describe('GenericRestClient', () => {
const body = {
title: faker.name.title(),
text: faker.lorem.text(),
id,
id
};
const path = `/get/${id}`;
const url = BASE_URL + path;
@ -47,7 +47,7 @@ describe('GenericRestClient', () => {
const request = jasmine.Ajax.requests.mostRecent();
request.respondWith({
responseText: JSON.stringify(body),
status: statusCode,
status: statusCode
});
expect(request.url).toEqual(url);
@ -64,7 +64,7 @@ describe('GenericRestClient', () => {
const body = {
title: faker.name.title(),
text: faker.lorem.text(),
id,
id
};
const path = `/get/${id}`;
const url = BASE_URL + path;
@ -83,7 +83,7 @@ describe('GenericRestClient', () => {
const request = jasmine.Ajax.requests.mostRecent();
request.respondWith({
responseText: JSON.stringify(body),
status: statusCode,
status: statusCode
});
expect(request.url).toEqual(url);
@ -97,7 +97,7 @@ describe('GenericRestClient', () => {
const method = 'POST';
const sendData = {
title: faker.name.title(),
text: faker.lorem.text(),
text: faker.lorem.text()
};
const body = { ...sendData, id: faker.random.uuid() };
const path = '/post';
@ -109,7 +109,7 @@ describe('GenericRestClient', () => {
const request = jasmine.Ajax.requests.mostRecent();
request.respondWith({
responseText: JSON.stringify(body),
status: statusCode,
status: statusCode
});
expect(request.url).toEqual(url);
@ -124,7 +124,7 @@ describe('GenericRestClient', () => {
const onSuccess = jasmine.createSpy('onSuccess');
const sendData = {
title: faker.name.title(),
text: faker.lorem.text(),
text: faker.lorem.text()
};
const method = 'POST';
const body = { ...sendData, id: faker.random.uuid() };
@ -145,7 +145,7 @@ describe('GenericRestClient', () => {
const request = jasmine.Ajax.requests.mostRecent();
request.respondWith({
responseText: JSON.stringify(body),
status: statusCode,
status: statusCode
});
expect(request.url).toEqual(url);
@ -170,7 +170,7 @@ describe('GenericRestClient', () => {
const request = jasmine.Ajax.requests.mostRecent();
request.respondWith({
responseText: JSON.stringify(body),
status: statusCode,
status: statusCode
});
expect(request.url).toEqual(url);
@ -204,7 +204,7 @@ describe('GenericRestClient', () => {
const request = jasmine.Ajax.requests.mostRecent();
request.respondWith({
responseText: JSON.stringify(body),
status: statusCode,
status: statusCode
});
expect(request.url).toEqual(url);
@ -221,7 +221,7 @@ describe('GenericRestClient', () => {
const method = 'PATCH';
const sendData = {
title: faker.name.title(),
text: faker.lorem.text(),
text: faker.lorem.text()
};
const body = { ...sendData, text: faker.lorem.text(), id };
const path = '/patch' + id;
@ -233,7 +233,7 @@ describe('GenericRestClient', () => {
const request = jasmine.Ajax.requests.mostRecent();
request.respondWith({
responseText: JSON.stringify(body),
status: statusCode,
status: statusCode
});
expect(request.url).toEqual(url);
@ -249,7 +249,7 @@ describe('GenericRestClient', () => {
const onSuccess = jasmine.createSpy('onSuccess');
const sendData = {
title: faker.name.title(),
text: faker.lorem.text(),
text: faker.lorem.text()
};
const method = 'PATCH';
const body = { ...sendData, id: faker.random.uuid() };
@ -270,7 +270,7 @@ describe('GenericRestClient', () => {
const request = jasmine.Ajax.requests.mostRecent();
request.respondWith({
responseText: JSON.stringify(body),
status: statusCode,
status: statusCode
});
expect(request.url).toEqual(url);
@ -294,7 +294,7 @@ describe('GenericRestClient', () => {
const request = jasmine.Ajax.requests.mostRecent();
request.respondWith({
responseText: JSON.stringify(body),
status: statusCode,
status: statusCode
});
expect(request.url).toEqual(url);
@ -317,7 +317,7 @@ describe('GenericRestClient', () => {
statusCode,
method,
body,
url,
url
};
http.performApiDeleteDetailed(path, sendData, { contentType: 'json' })
@ -326,7 +326,7 @@ describe('GenericRestClient', () => {
const request = jasmine.Ajax.requests.mostRecent();
request.respondWith({
responseText: JSON.stringify(body),
status: statusCode,
status: statusCode
});
expect(request.url).toEqual(url);
@ -337,7 +337,7 @@ describe('GenericRestClient', () => {
it('performs request with custom headers', () => {
const headers = {
'Authorization': `Barrier ${faker.random.uuid()}`,
'Authorization': `Barrier ${faker.random.uuid()}`
};
class Http extends GenericRestClient {
@ -380,7 +380,7 @@ describe('GenericRestClient', () => {
const request = jasmine.Ajax.requests.mostRecent();
request.respondWith({
responseText: JSON.stringify(body),
status: statusCode,
status: statusCode
});
expect(request.url).toEqual(url);
@ -393,7 +393,7 @@ describe('GenericRestClient', () => {
const blockDefer = SyncTasks.Defer<void>();
class Http extends GenericRestClient {
protected _blockRequestUntil() {
protected _blockRequestUntil(): SyncTasks.Promise<void> {
return blockDefer.promise();
}
}
@ -407,7 +407,7 @@ describe('GenericRestClient', () => {
.then(onSuccess);
let request = jasmine.Ajax.requests.mostRecent();
expect(request).toBeUndefined();
blockDefer.resolve(void 0);
@ -425,7 +425,7 @@ describe('GenericRestClient', () => {
this._defaultOptions.customErrorHandler = this._customErrorHandler;
this._defaultOptions.timeout = 1;
}
protected _blockRequestUntil() {
protected _blockRequestUntil(): SyncTasks.Promise<void> {
return blockDefer.promise();
}
@ -434,7 +434,7 @@ describe('GenericRestClient', () => {
return ErrorHandlingType.DoNotRetry;
}
return ErrorHandlingType.RetryUncountedImmediately;
}
};
}
const statusCode = 400;
@ -449,7 +449,7 @@ describe('GenericRestClient', () => {
blockDefer.resolve(void 0);
const request1 = jasmine.Ajax.requests.mostRecent();
// Reset blockuntil so retries may block
blockDefer = SyncTasks.Defer<void>();
@ -482,13 +482,13 @@ describe('GenericRestClient', () => {
this._defaultOptions.customErrorHandler = this._customErrorHandler;
this._defaultOptions.timeout = 1;
}
protected _blockRequestUntil() {
protected _blockRequestUntil(): SyncTasks.Promise<void> {
return blockDefer.promise();
}
protected _customErrorHandler = () => {
return ErrorHandlingType.RetryUncountedImmediately;
}
};
}
const statusCode = 400;
@ -501,7 +501,7 @@ describe('GenericRestClient', () => {
blockDefer.resolve(void 0);
const request1 = jasmine.Ajax.requests.mostRecent();
// Reset blockuntil so retries may block
blockDefer = SyncTasks.Defer<void>();

Просмотреть файл

@ -42,7 +42,7 @@ describe('SimpleWebRequest', () => {
it('sends json POST request', () => {
const sendData = {
title: faker.name.title(),
text: faker.lorem.text(),
text: faker.lorem.text()
};
const requestOptions = { sendData };
const statusCode = 201;
@ -87,7 +87,7 @@ describe('SimpleWebRequest', () => {
spyOn(console, 'error');
const headers = {
'Accept': 'application/xml',
'Accept': 'application/xml'
};
const method = 'GET';
const url = faker.internet.url();
@ -102,7 +102,7 @@ describe('SimpleWebRequest', () => {
spyOn(console, 'error');
const headers = {
'Content-Type': 'application/xml',
'Content-Type': 'application/xml'
};
const method = 'GET';
const url = faker.internet.url();
@ -189,7 +189,9 @@ describe('SimpleWebRequest', () => {
const onSuccessLow = jasmine.createSpy('onSuccessLow');
const onSuccessCritical = jasmine.createSpy('onSuccessCritical');
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.High }, undefined, () => blockDefer.promise()).start().then(onSuccessHigh);
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.High }, undefined, () => blockDefer.promise())
.start()
.then(onSuccessHigh);
jasmine.clock().tick(10);
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Low }).start().then(onSuccessLow);
jasmine.clock().tick(10);
@ -223,7 +225,9 @@ describe('SimpleWebRequest', () => {
const onSuccessHigh2 = jasmine.createSpy('onSuccessHigh2');
const blockSpy = jasmine.createSpy('blockSpy').and.callFake(() => blockDefer.promise());
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Critical }, undefined, blockSpy).start().then(onSuccessCritical);
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Critical }, undefined, blockSpy)
.start()
.then(onSuccessCritical);
jasmine.clock().tick(10);
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.High }).start().then(onSuccessHigh);
@ -257,12 +261,13 @@ describe('SimpleWebRequest', () => {
const method = 'GET';
const blockDefer = SyncTasks.Defer<void>();
const errorString = 'Terrible error';
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Critical }, undefined, () => blockDefer.promise()).start()
.then(() => fail(), (err: WebErrorResponse) => {
expect(err.statusCode).toBe(0);
expect(err.statusText).toBe('_blockRequestUntil rejected: ' + errorString);
done();
});
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Critical }, undefined, () => blockDefer.promise())
.start()
.then(() => fail(), (err: WebErrorResponse) => {
expect(err.statusCode).toBe(0);
expect(err.statusText).toBe('_blockRequestUntil rejected: ' + errorString);
done();
});
blockDefer.reject(errorString);
});
@ -272,8 +277,9 @@ describe('SimpleWebRequest', () => {
const url = faker.internet.url();
const method = 'GET';
const blockDefer = SyncTasks.Defer<void>();
const requestPromise = new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Critical }, undefined, () => blockDefer.promise()).start();
requestPromise.cancel();
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Critical }, undefined, () => blockDefer.promise())
.start()
.cancel();
blockDefer.resolve(void 0);
expect(jasmine.Ajax.requests.count()).toBe(0);

Просмотреть файл

@ -1,24 +1,22 @@
export const REQUEST_OPTIONS = {
excludeEndpointUrl: false,
withCredentials: false,
contentType: 'json',
priority: 2,
retries: 0,
excludeEndpointUrl: false,
withCredentials: false,
contentType: 'json',
priority: 2,
retries: 0
};
export const REQUEST_HEADERS = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Content-Type': 'application/json',
'Accept': 'application/json'
};
export const DETAILED_RESPONSE = {
requestOptions: REQUEST_OPTIONS,
requestHeaders: REQUEST_HEADERS,
statusCode: 200,
statusText: undefined,
headers: {
'content-type': 'application/json',
},
body: '',
url: '',
requestOptions: REQUEST_OPTIONS,
requestHeaders: REQUEST_HEADERS,
statusCode: 200,
statusText: undefined,
headers: { 'content-type': 'application/json' },
body: '',
url: ''
};

Просмотреть файл

@ -1,48 +0,0 @@
{
"rules": {
"align": [true, "statements"],
"class-name": true,
"curly": true,
"eofline": true,
"forin": true,
"indent": [true, "spaces"],
"label-position": true,
"max-line-length": [true, 140],
"no-arg": true,
"no-bitwise": false,
"no-console": [true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-consecutive-blank-lines": true,
"no-construct": true,
"no-debugger": true,
"no-duplicate-variable": true,
"no-empty": true,
"no-eval": true,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": false,
"no-unused-expression": true,
"one-line": [true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"quotemark": [true, "single", "jsx-single"],
"radix": true,
"semicolon": true,
"triple-equals": [true, "allow-null-check"],
"variable-name": false,
"whitespace": [true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
}
}