Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.

Commit 3a80fcd

Browse files
a-tarasyukberickson1
authored andcommitted
Fix tests output. Update dependencies (#36)
1 parent c94a23f commit 3a80fcd

4 files changed

Lines changed: 50 additions & 34 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/Microsoft/SimpleRestClients/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/simplerestclients.svg?style=flat-square)](https://www.npmjs.com/package/simplerestclients) [![npm downloads](https://img.shields.io/npm/dm/simplerestclients.svg?style=flat-square)](https://www.npmjs.com/package/simplerestclients) [![Build Status](https://img.shields.io/travis/Microsoft/SimpleRestClients/master.svg?style=flat-square)](https://travis-ci.org/Microsoft/SimpleRestClients) [![David](https://img.shields.io/david/Microsoft/SimpleRestClients.svg?style=flat-square)](https://github.com/Microsoft/SimpleRestClients)
44
[![David](https://img.shields.io/david/dev/Microsoft/SimpleRestClients.svg?style=flat-square)](https://github.com/Microsoft/SimpleRestClients)
55

6-
A simple set of wrappers for RESTful calls. Consists of two modules:
6+
> A simple set of wrappers for RESTful calls. Consists of two modules:
7+
8+
## Installation
9+
10+
```shell
11+
npm install --save simplerestclients
12+
```
713

814
## SimpleWebRequest
915

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@
1919
"synctasks": "^0.3.3"
2020
},
2121
"devDependencies": {
22-
"@types/faker": "4.1.2",
22+
"@types/faker": "4.1.3",
2323
"@types/jasmine": "2.8.8",
2424
"@types/jasmine-ajax": "3.1.37",
25-
"@types/node": "10.5.1",
25+
"@types/node": "10.9.4",
2626
"faker": "4.1.0",
27-
"fork-ts-checker-webpack-plugin": "0.4.2",
28-
"jasmine": "3.1.0",
29-
"jasmine-core": "3.1.0",
30-
"karma": "2.0.4",
27+
"fork-ts-checker-webpack-plugin": "0.4.9",
28+
"jasmine": "3.2.0",
29+
"jasmine-core": "3.2.1",
30+
"karma": "3.0.0",
3131
"karma-chrome-launcher": "2.2.0",
3232
"karma-jasmine": "1.1.2",
3333
"karma-jasmine-ajax": "0.1.13",
34-
"karma-jasmine-html-reporter": "1.2.0",
34+
"karma-jasmine-html-reporter": "1.3.1",
3535
"karma-sourcemap-loader": "0.3.7",
3636
"karma-spec-reporter": "0.0.32",
3737
"karma-webpack": "4.0.0-beta.0",
3838
"rimraf": "2.6.2",
39-
"ts-loader": "4.4.2",
40-
"tslint": "5.10.0",
41-
"tslint-microsoft-contrib": "5.0.3",
42-
"typescript": "2.9.2",
43-
"webpack": "4.15.0"
39+
"ts-loader": "5.1.0",
40+
"tslint": "5.11.0",
41+
"tslint-microsoft-contrib": "5.2.1",
42+
"typescript": "3.0.3",
43+
"webpack": "4.19.0"
4444
},
4545
"repository": {
4646
"type": "git",

src/SimpleWebRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ export class SimpleWebRequest<TBody, TOptions extends WebRequestOptions = WebReq
693693
if (!body || !_.isObject(body)) {
694694
// Response can be null if the responseType does not match what the server actually sends
695695
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType
696-
696+
697697
// Only access responseText if responseType is "text" or "", otherwise it will throw
698698
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseText
699699
if ((this._xhr.responseType === 'text' || this._xhr.responseType === '') && this._xhr.responseText) {

test/SimpleWebRequest.spec.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as faker from 'faker';
2+
import * as SyncTasks from 'synctasks';
23
import { SimpleWebRequest, SimpleWebRequestOptions, WebErrorResponse, WebRequestPriority } from '../src/SimpleWebRequest';
34
import { DETAILED_RESPONSE } from './helpers';
4-
import * as SyncTasks from 'synctasks';
55

66
describe('SimpleWebRequest', () => {
77
let catchExceptions = false;
@@ -79,32 +79,38 @@ describe('SimpleWebRequest', () => {
7979

8080
expect(request.requestHeaders['X-Requested-With']).toEqual(headers['X-Requested-With']);
8181
expect(request.requestHeaders['Max-Forwards']).toEqual(headers['Max-Forwards']);
82-
82+
8383
request.respondWith({ status });
8484
});
8585

8686
it('forbids to set Accept header', () => {
87+
spyOn(console, 'error');
88+
8789
const headers = {
8890
'Accept': 'application/xml',
8991
};
9092
const method = 'GET';
9193
const url = faker.internet.url();
94+
const error = `Don't set Accept with options.headers -- use it with the options.acceptType property`;
95+
const request = new SimpleWebRequest<string>(url, method, {}, () => headers);
9296

93-
expect(
94-
() => new SimpleWebRequest<string>(url, method, {}, () => headers).start()
95-
).toThrowError(`Don't set Accept with options.headers -- use it with the options.acceptType property`);
96-
97+
expect(() => request.start()).toThrowError(error);
98+
expect(console.error).toHaveBeenCalledWith(error);
9799
});
98100

99101
it('forbids to set Content-Type header', () => {
102+
spyOn(console, 'error');
103+
100104
const headers = {
101105
'Content-Type': 'application/xml',
102106
};
103107
const method = 'GET';
104108
const url = faker.internet.url();
105-
expect(
106-
() => new SimpleWebRequest<string>(url, method, {}, () => headers).start()
107-
).toThrowError(`Don't set Content-Type with options.headers -- use it with the options.contentType property`);
109+
const error = `Don't set Content-Type with options.headers -- use it with the options.contentType property`;
110+
const request = new SimpleWebRequest<string>(url, method, {}, () => headers);
111+
112+
expect(() => request.start()).toThrowError(error);
113+
expect(console.error).toHaveBeenCalledWith(error);
108114
});
109115

110116
describe('blocking', () => {
@@ -115,8 +121,9 @@ describe('SimpleWebRequest', () => {
115121
SimpleWebRequestOptions.MaxSimultaneousRequests = 0;
116122
jasmine.clock().install();
117123
});
124+
118125
afterEach(() => {
119-
SimpleWebRequestOptions.MaxSimultaneousRequests = maxRequests;
126+
SimpleWebRequestOptions.MaxSimultaneousRequests = maxRequests;
120127
jasmine.clock().uninstall();
121128
});
122129

@@ -128,18 +135,20 @@ describe('SimpleWebRequest', () => {
128135
const onSuccessLow2 = jasmine.createSpy('onSuccessLow2');
129136
const onSuccessCritical2 = jasmine.createSpy('onSuccessCritical2');
130137
const status = 200;
131-
138+
132139
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Low }).start().then(onSuccessLow1);
133140
jasmine.clock().tick(10);
141+
134142
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Critical }).start().then(onSuccessCritical1);
135143
jasmine.clock().tick(10);
144+
136145
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Low }).start().then(onSuccessLow2);
137146
jasmine.clock().tick(10);
138-
147+
139148
SimpleWebRequestOptions.MaxSimultaneousRequests = 1;
140149
// add a new request to kick the queue
141150
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Critical }).start().then(onSuccessCritical2);
142-
151+
143152
// only one is executed
144153
expect(jasmine.Ajax.requests.count()).toBe(1);
145154
jasmine.Ajax.requests.mostRecent().respondWith({status});
@@ -155,7 +164,7 @@ describe('SimpleWebRequest', () => {
155164
jasmine.Ajax.requests.mostRecent().respondWith({status});
156165
expect(onSuccessLow2).toHaveBeenCalled();
157166
});
158-
167+
159168
it('blocks the request with custom promise', () => {
160169
SimpleWebRequestOptions.MaxSimultaneousRequests = 1;
161170
const url = faker.internet.url();
@@ -171,7 +180,7 @@ describe('SimpleWebRequest', () => {
171180
request.respondWith({ status: 200 });
172181
expect(onSuccess1).toHaveBeenCalled();
173182
});
174-
183+
175184
it('after the request is unblocked, it\'s returned to the queue with correct priority', () => {
176185
const url = faker.internet.url();
177186
const method = 'GET';
@@ -188,7 +197,7 @@ describe('SimpleWebRequest', () => {
188197
SimpleWebRequestOptions.MaxSimultaneousRequests = 1;
189198
// add a new request to kick the queue
190199
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Critical }).start().then(onSuccessCritical);
191-
200+
192201
// unblock the request
193202
blockDefer.resolve(void 0);
194203

@@ -200,11 +209,11 @@ describe('SimpleWebRequest', () => {
200209
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 });
201210
expect(onSuccessHigh).toHaveBeenCalled();
202211

203-
// and the low priority one gets sent last
212+
// and the low priority one gets sent last
204213
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 });
205214
expect(onSuccessLow).toHaveBeenCalled();
206215
});
207-
216+
208217
it('checks the blocked function again, once the request is on top of the queue', () => {
209218
const url = faker.internet.url();
210219
const method = 'GET';
@@ -216,13 +225,14 @@ describe('SimpleWebRequest', () => {
216225

217226
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.Critical }, undefined, blockSpy).start().then(onSuccessCritical);
218227
jasmine.clock().tick(10);
228+
219229
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.High }).start().then(onSuccessHigh);
220230
jasmine.clock().tick(10);
221231

222232
SimpleWebRequestOptions.MaxSimultaneousRequests = 1;
223233
// add a new request to kick the queue
224234
new SimpleWebRequest<string>(url, method, { priority: WebRequestPriority.High }).start().then(onSuccessHigh2);
225-
235+
226236
expect(blockSpy).toHaveBeenCalled();
227237

228238
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200 });
@@ -253,7 +263,7 @@ describe('SimpleWebRequest', () => {
253263
expect(err.statusText).toBe('_blockRequestUntil rejected: ' + errorString);
254264
done();
255265
});
256-
266+
257267
blockDefer.reject(errorString);
258268
});
259269
});

0 commit comments

Comments
 (0)