@loopback/testlab 3.2.12 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -85,119 +85,6 @@ by Shot in your unit tests:
85
85
  - Code modifying core HTTP Response, including full request/response handlers
86
86
  - Code parsing Express HTTP Request or modifying Express HTTP Response
87
87
 
88
- ### `skipIf`
89
-
90
- Helper function for skipping tests when a certain condition is met. Use this
91
- helper together with `it` or `describe`.
92
-
93
- ```ts
94
- skipIf(someCondition, it, 'does something', async () => {
95
- // the test code
96
- });
97
- ```
98
-
99
- Unfortunately, type inference does not work well for `describe`, you have to
100
- help the compiler to figure out the correct types.
101
-
102
- ```ts
103
- skipIf<[(this: Suite) => void], void>(
104
- someCondition,
105
- describe,
106
- 'some suite name',
107
- () => {
108
- // define the test cases
109
- },
110
- );
111
- ```
112
-
113
- Under the hood, `skipIf` invokes the provided test verb by default (e.g. `it`).
114
- When the provided condition was true, then it calls `.skip` instead (e.g.
115
- `it.skip`).
116
-
117
- ### `skipOnTravis`
118
-
119
- Helper function for skipping tests on Travis environment. If you need to skip
120
- testing on Travis for any reason, use this helper together with `it` or
121
- `describe`.
122
-
123
- ```ts
124
- skipOnTravis(it, 'does something when some condition', async () => {
125
- // the test code
126
- });
127
- ```
128
-
129
- Under the hood, `skipOnTravis` invokes the provided test verb by default (e.g.
130
- `it`). When the helper detects Travis CI environment variables, then it calls
131
- `.skip` instead (e.g. `it.skip`).
132
-
133
- ### `createRestAppClient`
134
-
135
- Helper function to create a `supertest` client connected to a running
136
- RestApplication. It is the responsibility of the caller to ensure that the app
137
- is running and to stop the application after all tests are done.
138
-
139
- Example use:
140
-
141
- ```ts
142
- import {Client, createRestAppClient} from '@loopback/testlab';
143
-
144
- describe('My application', () => {
145
- app: MyApplication; // extends RestApplication
146
- client: Client;
147
-
148
- before(givenRunningApplication);
149
- before(() => {
150
- client = createRestAppClient(app);
151
- });
152
- after(() => app.stop());
153
-
154
- it('invokes GET /ping', async () => {
155
- await client.get('/ping?msg=world').expect(200);
156
- });
157
- });
158
- ```
159
-
160
- ### `givenHttpServerConfig`
161
-
162
- Helper function for generating Travis-friendly host (127.0.0.1). This is
163
- required because Travis is not able to handle IPv6 addresses.
164
-
165
- ### `httpGetAsync`
166
-
167
- Async wrapper for making HTTP GET requests.
168
-
169
- ```ts
170
- import {httpGetAsync} from '@loopback/testlab';
171
- const response = await httpGetAsync('http://example.com');
172
- ```
173
-
174
- ### `httpsGetAsync`
175
-
176
- Async wrapper for making HTTPS GET requests.
177
-
178
- ```ts
179
- import {httpsGetAsync} from '@loopback/testlab';
180
- const response = await httpsGetAsync('https://example.com');
181
- ```
182
-
183
- ### `toJSON`
184
-
185
- JSON encoding does not preserve properties that are undefined. As a result,
186
- `deepEqual` checks fail because the expected model value contains these
187
- undefined property values, while the actual result returned by REST API does
188
- not. Use this function to convert a model instance into a data object as
189
- returned by REST API.
190
-
191
- ```ts
192
- import {createClientForHandler, toJSON} from '@loopback/testlab';
193
-
194
- it('gets a todo by ID', () => {
195
- return client
196
- .get(`/todos/${persistedTodo.id}`)
197
- .expect(200, toJSON(persistedTodo));
198
- });
199
- ```
200
-
201
88
  #### Test request parsing
202
89
 
203
90
  Use the factory function `stubServerRequest` to create a stub request that can
@@ -315,6 +202,119 @@ describe('response writer', () => {
315
202
  });
316
203
  ```
317
204
 
205
+ ### `skipIf`
206
+
207
+ Helper function for skipping tests when a certain condition is met. Use this
208
+ helper together with `it` or `describe`.
209
+
210
+ ```ts
211
+ skipIf(someCondition, it, 'does something', async () => {
212
+ // the test code
213
+ });
214
+ ```
215
+
216
+ Unfortunately, type inference does not work well for `describe`, you have to
217
+ help the compiler to figure out the correct types.
218
+
219
+ ```ts
220
+ skipIf<[(this: Suite) => void], void>(
221
+ someCondition,
222
+ describe,
223
+ 'some suite name',
224
+ () => {
225
+ // define the test cases
226
+ },
227
+ );
228
+ ```
229
+
230
+ Under the hood, `skipIf` invokes the provided test verb by default (e.g. `it`).
231
+ When the provided condition was true, then it calls `.skip` instead (e.g.
232
+ `it.skip`).
233
+
234
+ ### `skipOnTravis`
235
+
236
+ Helper function for skipping tests on Travis environment. If you need to skip
237
+ testing on Travis for any reason, use this helper together with `it` or
238
+ `describe`.
239
+
240
+ ```ts
241
+ skipOnTravis(it, 'does something when some condition', async () => {
242
+ // the test code
243
+ });
244
+ ```
245
+
246
+ Under the hood, `skipOnTravis` invokes the provided test verb by default (e.g.
247
+ `it`). When the helper detects Travis CI environment variables, then it calls
248
+ `.skip` instead (e.g. `it.skip`).
249
+
250
+ ### `createRestAppClient`
251
+
252
+ Helper function to create a `supertest` client connected to a running
253
+ RestApplication. It is the responsibility of the caller to ensure that the app
254
+ is running and to stop the application after all tests are done.
255
+
256
+ Example use:
257
+
258
+ ```ts
259
+ import {Client, createRestAppClient} from '@loopback/testlab';
260
+
261
+ describe('My application', () => {
262
+ app: MyApplication; // extends RestApplication
263
+ client: Client;
264
+
265
+ before(givenRunningApplication);
266
+ before(() => {
267
+ client = createRestAppClient(app);
268
+ });
269
+ after(() => app.stop());
270
+
271
+ it('invokes GET /ping', async () => {
272
+ await client.get('/ping?msg=world').expect(200);
273
+ });
274
+ });
275
+ ```
276
+
277
+ ### `givenHttpServerConfig`
278
+
279
+ Helper function for generating Travis-friendly host (127.0.0.1). This is
280
+ required because Travis is not able to handle IPv6 addresses.
281
+
282
+ ### `httpGetAsync`
283
+
284
+ Async wrapper for making HTTP GET requests.
285
+
286
+ ```ts
287
+ import {httpGetAsync} from '@loopback/testlab';
288
+ const response = await httpGetAsync('http://example.com');
289
+ ```
290
+
291
+ ### `httpsGetAsync`
292
+
293
+ Async wrapper for making HTTPS GET requests.
294
+
295
+ ```ts
296
+ import {httpsGetAsync} from '@loopback/testlab';
297
+ const response = await httpsGetAsync('https://example.com');
298
+ ```
299
+
300
+ ### `toJSON`
301
+
302
+ JSON encoding does not preserve properties that are undefined. As a result,
303
+ `deepEqual` checks fail because the expected model value contains these
304
+ undefined property values, while the actual result returned by REST API does
305
+ not. Use this function to convert a model instance into a data object as
306
+ returned by REST API.
307
+
308
+ ```ts
309
+ import {createClientForHandler, toJSON} from '@loopback/testlab';
310
+
311
+ it('gets a todo by ID', () => {
312
+ return client
313
+ .get(`/todos/${persistedTodo.id}`)
314
+ .expect(200, toJSON(persistedTodo));
315
+ });
316
+ ```
317
+
318
318
  ### `validateApiSpec`
319
319
 
320
320
  Verify that your application API specification is a valid OpenAPI spec document.
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE;;GAEG;AAEH,wDAAwB;AACxB,uCAAwC;AAEhC,8BAAS;AAIjB;;;;GAIG;AACH,SAAgB,sBAAsB,CACpC,OAAsE;IAEtE,MAAM,MAAM,GAAG,cAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AALD,wDAKC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,GAAwB;;IAC1D,MAAM,GAAG,SAAG,GAAG,CAAC,UAAU,CAAC,OAAO,mCAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;IACzD,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,IAAI,KAAK,CACb,4BAA4B,GAAG,CAAC,WAAW,CAAC,IAAI,wBAAwB,CACzE,CAAC;KACH;IACD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AARD,kDAQC"}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE;;GAEG;AAEH,wDAAwB;AACxB,uCAAwC;AAEhC,8BAAS;AAIjB;;;;GAIG;AACH,SAAgB,sBAAsB,CACpC,OAAsE;IAEtE,MAAM,MAAM,GAAG,cAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AALD,wDAKC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,GAAwB;;IAC1D,MAAM,GAAG,GAAG,MAAA,GAAG,CAAC,UAAU,CAAC,OAAO,mCAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;IACzD,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,IAAI,KAAK,CACb,4BAA4B,GAAG,CAAC,WAAW,CAAC,IAAI,wBAAwB,CACzE,CAAC;KACH;IACD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AARD,kDAQC"}
@@ -1 +1 @@
1
- {"version":3,"file":"http-error-logger.js","sourceRoot":"","sources":["../src/http-error-logger.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAKhE;;;;GAIG;AACH,SAAgB,+BAA+B,CAC7C,kBAA2B;IAE3B,OAAO,SAAS,sBAAsB,CACpC,GAAU,EACV,UAAkB,EAClB,GAAoB;;QAEpB,IAAI,UAAU,KAAK,kBAAkB;YAAE,OAAO;QAE9C,0BAA0B;QAC1B,OAAO,CAAC,KAAK,CACX,iCAAiC,EACjC,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,GAAG,EACP,UAAU,QACV,GAAG,CAAC,KAAK,mCAAI,GAAG,CACjB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAnBD,0EAmBC"}
1
+ {"version":3,"file":"http-error-logger.js","sourceRoot":"","sources":["../src/http-error-logger.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAKhE;;;;GAIG;AACH,SAAgB,+BAA+B,CAC7C,kBAA2B;IAE3B,OAAO,SAAS,sBAAsB,CACpC,GAAU,EACV,UAAkB,EAClB,GAAoB;;QAEpB,IAAI,UAAU,KAAK,kBAAkB;YAAE,OAAO;QAE9C,0BAA0B;QAC1B,OAAO,CAAC,KAAK,CACX,iCAAiC,EACjC,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,GAAG,EACP,UAAU,EACV,MAAA,GAAG,CAAC,KAAK,mCAAI,GAAG,CACjB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAnBD,0EAmBC"}
package/dist/request.js CHANGED
@@ -26,9 +26,10 @@ exports.httpGetAsync = httpGetAsync;
26
26
  * @param urlString
27
27
  */
28
28
  function httpsGetAsync(urlString, agent) {
29
- agent = agent !== null && agent !== void 0 ? agent : new https_1.default.Agent({
30
- rejectUnauthorized: false,
31
- });
29
+ agent =
30
+ agent !== null && agent !== void 0 ? agent : new https_1.default.Agent({
31
+ rejectUnauthorized: false,
32
+ });
32
33
  const urlOptions = url_1.default.parse(urlString);
33
34
  const options = { agent, ...urlOptions };
34
35
  return new Promise((resolve, reject) => {
@@ -1 +1 @@
1
- {"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,wDAA2C;AAC3C,0DAA0B;AAC1B,sDAAsB;AAEtB;;;GAGG;AACH,SAAgB,YAAY,CAC1B,SAAiB,EACjB,KAAkB;IAElB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,UAAU,GAAG,aAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACxC,MAAM,OAAO,GAAG,EAAC,KAAK,EAAE,GAAG,UAAU,EAAC,CAAC;QACvC,cAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC;AATD,oCASC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,IAAI,eAAK,CAAC,KAAK,CAAC;YACd,kBAAkB,EAAE,KAAK;SAC1B,CAAC,CAAC;IAEL,MAAM,UAAU,GAAG,aAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,EAAC,KAAK,EAAE,GAAG,UAAU,EAAC,CAAC;IAEvC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,eAAK,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC;AAhBD,sCAgBC"}
package/package.json CHANGED
@@ -1,11 +1,19 @@
1
1
  {
2
2
  "name": "@loopback/testlab",
3
- "version": "3.2.12",
4
3
  "description": "A collection of test utilities we use to write LoopBack tests.",
4
+ "version": "3.4.1",
5
+ "license": "MIT",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
8
+ "author": "IBM Corp.",
9
+ "copyright.owner": "IBM Corp.",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/strongloop/loopback-next.git",
13
+ "directory": "packages/testlab"
14
+ },
7
15
  "engines": {
8
- "node": "^10.16 || 12 || 14 || 15"
16
+ "node": "^10.16 || 12 || 14 || 16"
9
17
  },
10
18
  "scripts": {
11
19
  "build": "lb-tsc",
@@ -14,32 +22,9 @@
14
22
  "test": "lb-mocha \"dist/__tests__/**/*.js\"",
15
23
  "verify": "npm pack && tar xf loopback-testlab*.tgz && tree package && npm run clean"
16
24
  },
17
- "author": "IBM Corp.",
18
- "copyright.owner": "IBM Corp.",
19
- "license": "MIT",
20
25
  "publishConfig": {
21
26
  "access": "public"
22
27
  },
23
- "dependencies": {
24
- "@hapi/shot": "^5.0.5",
25
- "@types/express": "^4.17.11",
26
- "@types/fs-extra": "^9.0.6",
27
- "@types/shot": "^4.0.0",
28
- "@types/sinon": "^9.0.10",
29
- "@types/supertest": "^2.0.10",
30
- "express": "^4.17.1",
31
- "fs-extra": "^9.1.0",
32
- "oas-validator": "^5.0.4",
33
- "should": "^13.2.3",
34
- "sinon": "^9.2.4",
35
- "supertest": "^6.0.1",
36
- "tslib": "^2.1.0"
37
- },
38
- "devDependencies": {
39
- "@loopback/build": "^6.2.9",
40
- "@loopback/eslint-config": "^10.0.5",
41
- "@types/node": "^10.17.35"
42
- },
43
28
  "files": [
44
29
  "README.md",
45
30
  "dist",
@@ -48,10 +33,25 @@
48
33
  "src",
49
34
  "!*/__tests__"
50
35
  ],
51
- "repository": {
52
- "type": "git",
53
- "url": "https://github.com/strongloop/loopback-next.git",
54
- "directory": "packages/testlab"
36
+ "dependencies": {
37
+ "@hapi/shot": "^5.0.5",
38
+ "@types/express": "^4.17.12",
39
+ "@types/fs-extra": "^9.0.11",
40
+ "@types/shot": "^4.0.0",
41
+ "@types/sinon": "^10.0.2",
42
+ "@types/supertest": "^2.0.11",
43
+ "express": "^4.17.1",
44
+ "fs-extra": "^10.0.0",
45
+ "oas-validator": "^5.0.6",
46
+ "should": "^13.2.3",
47
+ "sinon": "^11.1.1",
48
+ "supertest": "^6.1.3",
49
+ "tslib": "^2.2.0"
50
+ },
51
+ "devDependencies": {
52
+ "@loopback/build": "^6.4.1",
53
+ "@loopback/eslint-config": "^10.2.1",
54
+ "@types/node": "^10.17.60"
55
55
  },
56
- "gitHead": "0fcf97fa1e87457de85f8f1b6b5cbf9f4f0bd640"
56
+ "gitHead": "2a3b684ec76fa299d80b099abbf101358538cb75"
57
57
  }