@opra/testing 0.22.0 → 0.23.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.
@@ -24,7 +24,7 @@ class ApiExpectCollection {
24
24
  toMatch(expected) {
25
25
  try {
26
26
  const v = (0, lodash_omitby_1.default)(expected, lodash_isnil_1.default);
27
- for (const item of this.response.body) {
27
+ for (const item of this.response.body.data) {
28
28
  this._expect(item).toMatchObject(v);
29
29
  }
30
30
  }
@@ -36,7 +36,7 @@ class ApiExpectCollection {
36
36
  }
37
37
  toHaveFields(keys) {
38
38
  try {
39
- for (const item of this.response.body) {
39
+ for (const item of this.response.body.data) {
40
40
  this._expect(item).toHaveFields(keys);
41
41
  }
42
42
  }
@@ -48,7 +48,7 @@ class ApiExpectCollection {
48
48
  }
49
49
  toHaveFieldsOnly(keys) {
50
50
  try {
51
- for (const item of this.response.body) {
51
+ for (const item of this.response.body.data) {
52
52
  this._expect(item).toHaveFieldsOnly(keys);
53
53
  }
54
54
  }
@@ -73,7 +73,7 @@ class ApiExpectCollection {
73
73
  // }
74
74
  toBeSortedBy(...fields) {
75
75
  try {
76
- this._expect(this.response.body).toBeSortedBy(fields);
76
+ this._expect(this.response.body.data).toBeSortedBy(fields);
77
77
  }
78
78
  catch (e) {
79
79
  Error.captureStackTrace(e, this.toBeSortedBy);
@@ -85,9 +85,9 @@ class ApiExpectCollection {
85
85
  const f = convertFilter(filter);
86
86
  if (f) {
87
87
  const j = ruleJudgment(f);
88
- const filtered = this.response.body.filter(j);
88
+ const filtered = this.response.body.data.filter(j);
89
89
  try {
90
- this._expect(this.response.body).toStrictEqual(filtered);
90
+ this._expect(this.response.body.data).toStrictEqual(filtered);
91
91
  }
92
92
  catch (e) {
93
93
  Error.captureStackTrace(e, this.toBeFilteredBy);
@@ -98,7 +98,7 @@ class ApiExpectCollection {
98
98
  }
99
99
  toHaveExactItems(expected) {
100
100
  try {
101
- this._expect(this.response.body).toHaveLength(expected);
101
+ this._expect(this.response.body.data).toHaveLength(expected);
102
102
  }
103
103
  catch (e) {
104
104
  Error.captureStackTrace(e, this.toHaveExactItems);
@@ -108,7 +108,7 @@ class ApiExpectCollection {
108
108
  }
109
109
  toHaveMaxItems(expected) {
110
110
  try {
111
- this._expect(this.response.body.length).toBeLessThanOrEqual(expected);
111
+ this._expect(this.response.body.data.length).toBeLessThanOrEqual(expected);
112
112
  }
113
113
  catch (e) {
114
114
  Error.captureStackTrace(e, this.toHaveMaxItems);
@@ -118,7 +118,7 @@ class ApiExpectCollection {
118
118
  }
119
119
  toHaveMinItems(expected) {
120
120
  try {
121
- this._expect(this.response.body.length).toBeGreaterThanOrEqual(expected);
121
+ this._expect(this.response.body.data.length).toBeGreaterThanOrEqual(expected);
122
122
  }
123
123
  catch (e) {
124
124
  Error.captureStackTrace(e, this.toHaveMinItems);
@@ -16,7 +16,7 @@ class ApiExpectObject {
16
16
  toMatch(expected) {
17
17
  try {
18
18
  const v = (0, lodash_omitby_1.default)(expected, lodash_isnil_1.default);
19
- this._expect(this.response.body).toMatchObject(v);
19
+ this._expect(this.response.body.data).toMatchObject(v);
20
20
  }
21
21
  catch (e) {
22
22
  Error.captureStackTrace(e, this.toMatch);
@@ -26,7 +26,7 @@ class ApiExpectObject {
26
26
  }
27
27
  toHaveFields(fields) {
28
28
  try {
29
- this._expect(this.response.body).toHaveFields(fields);
29
+ this._expect(this.response.body.data).toHaveFields(fields);
30
30
  }
31
31
  catch (e) {
32
32
  Error.captureStackTrace(e, this.toHaveFields);
@@ -36,7 +36,7 @@ class ApiExpectObject {
36
36
  }
37
37
  toHaveFieldsOnly(fields) {
38
38
  try {
39
- this._expect(this.response.body).toHaveFieldsOnly(fields);
39
+ this._expect(this.response.body.data).toHaveFieldsOnly(fields);
40
40
  }
41
41
  catch (e) {
42
42
  Error.captureStackTrace(e, this.toHaveFieldsOnly);
@@ -75,6 +75,8 @@ class ApiExpect {
75
75
  msg = '"body" is empty';
76
76
  expect(this.response.body).toBeDefined();
77
77
  expect(typeof this.response.body).toStrictEqual('object');
78
+ msg = `"body.data" is ${typeof typeof this.response.body.data}`;
79
+ expect(typeof this.response.body.data).toStrictEqual('object');
78
80
  }
79
81
  catch (e) {
80
82
  if (msg)
@@ -89,8 +91,9 @@ class ApiExpect {
89
91
  try {
90
92
  msg = '"body" is empty';
91
93
  expect(this.response.body).toBeDefined();
94
+ expect(this.response.body.data).toBeDefined();
92
95
  msg = '"body" is not an array';
93
- expect(this.response.body).toBeArray();
96
+ expect(this.response.body.data).toBeArray();
94
97
  }
95
98
  catch (e) {
96
99
  if (msg)
@@ -2,11 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpraTestClient = void 0;
4
4
  const http_1 = require("http");
5
- const url_1 = require("url");
6
5
  const client_1 = require("@opra/client");
7
6
  const common_1 = require("@opra/common");
8
7
  const api_expect_js_1 = require("./api-expect/api-expect.js");
9
- const is_absolute_url_util_js_1 = require("./utils/is-absolute-url.util.js");
10
8
  class OpraTestClient extends client_1.OpraHttpClient {
11
9
  constructor(app, options) {
12
10
  super('/', options);
@@ -20,8 +18,7 @@ class OpraTestClient extends client_1.OpraHttpClient {
20
18
  }
21
19
  async _fetch(urlString, req = {}) {
22
20
  return new Promise((resolve, reject) => {
23
- urlString = (0, is_absolute_url_util_js_1.isAbsoluteUrl)(urlString) ? urlString : (0, common_1.joinPath)('http://opra.test', urlString);
24
- const url = new url_1.URL(urlString);
21
+ const url = new common_1.OpraURL(urlString, 'http://opra.test');
25
22
  // Set protocol to HTTP
26
23
  url.protocol = 'http';
27
24
  // Apply original host to request header
@@ -20,7 +20,7 @@ export class ApiExpectCollection {
20
20
  toMatch(expected) {
21
21
  try {
22
22
  const v = omitBy(expected, isNil);
23
- for (const item of this.response.body) {
23
+ for (const item of this.response.body.data) {
24
24
  this._expect(item).toMatchObject(v);
25
25
  }
26
26
  }
@@ -32,7 +32,7 @@ export class ApiExpectCollection {
32
32
  }
33
33
  toHaveFields(keys) {
34
34
  try {
35
- for (const item of this.response.body) {
35
+ for (const item of this.response.body.data) {
36
36
  this._expect(item).toHaveFields(keys);
37
37
  }
38
38
  }
@@ -44,7 +44,7 @@ export class ApiExpectCollection {
44
44
  }
45
45
  toHaveFieldsOnly(keys) {
46
46
  try {
47
- for (const item of this.response.body) {
47
+ for (const item of this.response.body.data) {
48
48
  this._expect(item).toHaveFieldsOnly(keys);
49
49
  }
50
50
  }
@@ -69,7 +69,7 @@ export class ApiExpectCollection {
69
69
  // }
70
70
  toBeSortedBy(...fields) {
71
71
  try {
72
- this._expect(this.response.body).toBeSortedBy(fields);
72
+ this._expect(this.response.body.data).toBeSortedBy(fields);
73
73
  }
74
74
  catch (e) {
75
75
  Error.captureStackTrace(e, this.toBeSortedBy);
@@ -81,9 +81,9 @@ export class ApiExpectCollection {
81
81
  const f = convertFilter(filter);
82
82
  if (f) {
83
83
  const j = ruleJudgment(f);
84
- const filtered = this.response.body.filter(j);
84
+ const filtered = this.response.body.data.filter(j);
85
85
  try {
86
- this._expect(this.response.body).toStrictEqual(filtered);
86
+ this._expect(this.response.body.data).toStrictEqual(filtered);
87
87
  }
88
88
  catch (e) {
89
89
  Error.captureStackTrace(e, this.toBeFilteredBy);
@@ -94,7 +94,7 @@ export class ApiExpectCollection {
94
94
  }
95
95
  toHaveExactItems(expected) {
96
96
  try {
97
- this._expect(this.response.body).toHaveLength(expected);
97
+ this._expect(this.response.body.data).toHaveLength(expected);
98
98
  }
99
99
  catch (e) {
100
100
  Error.captureStackTrace(e, this.toHaveExactItems);
@@ -104,7 +104,7 @@ export class ApiExpectCollection {
104
104
  }
105
105
  toHaveMaxItems(expected) {
106
106
  try {
107
- this._expect(this.response.body.length).toBeLessThanOrEqual(expected);
107
+ this._expect(this.response.body.data.length).toBeLessThanOrEqual(expected);
108
108
  }
109
109
  catch (e) {
110
110
  Error.captureStackTrace(e, this.toHaveMaxItems);
@@ -114,7 +114,7 @@ export class ApiExpectCollection {
114
114
  }
115
115
  toHaveMinItems(expected) {
116
116
  try {
117
- this._expect(this.response.body.length).toBeGreaterThanOrEqual(expected);
117
+ this._expect(this.response.body.data.length).toBeGreaterThanOrEqual(expected);
118
118
  }
119
119
  catch (e) {
120
120
  Error.captureStackTrace(e, this.toHaveMinItems);
@@ -12,7 +12,7 @@ export class ApiExpectObject {
12
12
  toMatch(expected) {
13
13
  try {
14
14
  const v = omitBy(expected, isNil);
15
- this._expect(this.response.body).toMatchObject(v);
15
+ this._expect(this.response.body.data).toMatchObject(v);
16
16
  }
17
17
  catch (e) {
18
18
  Error.captureStackTrace(e, this.toMatch);
@@ -22,7 +22,7 @@ export class ApiExpectObject {
22
22
  }
23
23
  toHaveFields(fields) {
24
24
  try {
25
- this._expect(this.response.body).toHaveFields(fields);
25
+ this._expect(this.response.body.data).toHaveFields(fields);
26
26
  }
27
27
  catch (e) {
28
28
  Error.captureStackTrace(e, this.toHaveFields);
@@ -32,7 +32,7 @@ export class ApiExpectObject {
32
32
  }
33
33
  toHaveFieldsOnly(fields) {
34
34
  try {
35
- this._expect(this.response.body).toHaveFieldsOnly(fields);
35
+ this._expect(this.response.body.data).toHaveFieldsOnly(fields);
36
36
  }
37
37
  catch (e) {
38
38
  Error.captureStackTrace(e, this.toHaveFieldsOnly);
@@ -72,6 +72,8 @@ export class ApiExpect {
72
72
  msg = '"body" is empty';
73
73
  expect(this.response.body).toBeDefined();
74
74
  expect(typeof this.response.body).toStrictEqual('object');
75
+ msg = `"body.data" is ${typeof typeof this.response.body.data}`;
76
+ expect(typeof this.response.body.data).toStrictEqual('object');
75
77
  }
76
78
  catch (e) {
77
79
  if (msg)
@@ -86,8 +88,9 @@ export class ApiExpect {
86
88
  try {
87
89
  msg = '"body" is empty';
88
90
  expect(this.response.body).toBeDefined();
91
+ expect(this.response.body.data).toBeDefined();
89
92
  msg = '"body" is not an array';
90
- expect(this.response.body).toBeArray();
93
+ expect(this.response.body.data).toBeArray();
91
94
  }
92
95
  catch (e) {
93
96
  if (msg)
@@ -1,11 +1,9 @@
1
1
  import { createServer, Server } from 'http';
2
- import { URL } from 'url';
3
2
  import {
4
3
  // BatchRequest,
5
4
  OpraHttpClient, } from '@opra/client';
6
- import { joinPath } from '@opra/common';
5
+ import { OpraURL } from '@opra/common';
7
6
  import { ApiExpect } from './api-expect/api-expect.js';
8
- import { isAbsoluteUrl } from './utils/is-absolute-url.util.js';
9
7
  export class OpraTestClient extends OpraHttpClient {
10
8
  constructor(app, options) {
11
9
  super('/', options);
@@ -19,8 +17,7 @@ export class OpraTestClient extends OpraHttpClient {
19
17
  }
20
18
  async _fetch(urlString, req = {}) {
21
19
  return new Promise((resolve, reject) => {
22
- urlString = isAbsoluteUrl(urlString) ? urlString : joinPath('http://opra.test', urlString);
23
- const url = new URL(urlString);
20
+ const url = new OpraURL(urlString, 'http://opra.test');
24
21
  // Set protocol to HTTP
25
22
  url.protocol = 'http';
26
23
  // Apply original host to request header
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/testing",
3
- "version": "0.22.0",
3
+ "version": "0.23.1",
4
4
  "description": "Opra testing package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -25,8 +25,8 @@
25
25
  "clean:cover": "rimraf ../../coverage/testing"
26
26
  },
27
27
  "dependencies": {
28
- "@opra/client": "^0.22.0",
29
- "@opra/common": "^0.22.0",
28
+ "@opra/client": "^0.23.1",
29
+ "@opra/common": "^0.23.1",
30
30
  "ansi-colors": "^4.1.3",
31
31
  "lodash.isnil": "^4.0.0",
32
32
  "lodash.omitby": "^4.6.0",
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAbsoluteUrl = void 0;
4
- const url_1 = require("url");
5
- const isAbsoluteUrl = (urlString) => {
6
- const url = new url_1.URL(urlString, 'http://opra.test/');
7
- return url.host !== 'opra.test';
8
- };
9
- exports.isAbsoluteUrl = isAbsoluteUrl;
@@ -1,5 +0,0 @@
1
- import { URL } from 'url';
2
- export const isAbsoluteUrl = (urlString) => {
3
- const url = new URL(urlString, 'http://opra.test/');
4
- return url.host !== 'opra.test';
5
- };
@@ -1 +0,0 @@
1
- export declare const isAbsoluteUrl: (urlString: string) => boolean;