@opra/testing 1.4.2 → 1.4.4
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/cjs/api-expect/api-expect-collection.js +22 -9
- package/cjs/api-expect/api-expect-error.js +3 -1
- package/cjs/api-expect/api-expect-object.js +9 -3
- package/cjs/api-expect/api-expect.js +20 -8
- package/cjs/test-backend.js +3 -1
- package/esm/api-expect/api-expect-collection.js +22 -9
- package/esm/api-expect/api-expect-error.js +3 -1
- package/esm/api-expect/api-expect-object.js +9 -3
- package/esm/api-expect/api-expect.js +20 -8
- package/esm/jest-extend/common.extend.js +1 -1
- package/esm/test-backend.js +4 -2
- package/package.json +3 -3
|
@@ -8,8 +8,9 @@ const objects_1 = require("@jsopen/objects");
|
|
|
8
8
|
const common_1 = require("@opra/common");
|
|
9
9
|
const rule_judgment_1 = tslib_1.__importDefault(require("rule-judgment"));
|
|
10
10
|
const api_expect_base_js_1 = require("./api-expect-base.js");
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const ruleJudgment = typeof rule_judgment_1.default === 'object'
|
|
12
|
+
? rule_judgment_1.default.default
|
|
13
|
+
: rule_judgment_1.default;
|
|
13
14
|
class ApiExpectCollection extends api_expect_base_js_1.ApiExpectBase {
|
|
14
15
|
get not() {
|
|
15
16
|
return new ApiExpectCollection(this.response, !this.isNot);
|
|
@@ -22,7 +23,9 @@ class ApiExpectCollection extends api_expect_base_js_1.ApiExpectBase {
|
|
|
22
23
|
toReturnItems(min, max) {
|
|
23
24
|
let msg = '';
|
|
24
25
|
try {
|
|
25
|
-
const data = type_is_1.default.is(this.response.contentType, [
|
|
26
|
+
const data = type_is_1.default.is(this.response.contentType, [
|
|
27
|
+
common_1.MimeTypes.opra_response_json,
|
|
28
|
+
])
|
|
26
29
|
? this.response.body.payload
|
|
27
30
|
: this.response.body;
|
|
28
31
|
msg += `Payload should be array.`;
|
|
@@ -65,7 +68,9 @@ class ApiExpectCollection extends api_expect_base_js_1.ApiExpectBase {
|
|
|
65
68
|
toMatch(expected) {
|
|
66
69
|
try {
|
|
67
70
|
expected = (0, objects_1.omitNullish)(expected);
|
|
68
|
-
const data = type_is_1.default.is(this.response.contentType, [
|
|
71
|
+
const data = type_is_1.default.is(this.response.contentType, [
|
|
72
|
+
common_1.MimeTypes.opra_response_json,
|
|
73
|
+
])
|
|
69
74
|
? this.response.body.payload
|
|
70
75
|
: this.response.body;
|
|
71
76
|
for (const x of data) {
|
|
@@ -85,7 +90,9 @@ class ApiExpectCollection extends api_expect_base_js_1.ApiExpectBase {
|
|
|
85
90
|
toContainFields(fields) {
|
|
86
91
|
try {
|
|
87
92
|
fields = Array.isArray(fields) ? fields : [fields];
|
|
88
|
-
const data = type_is_1.default.is(this.response.contentType, [
|
|
93
|
+
const data = type_is_1.default.is(this.response.contentType, [
|
|
94
|
+
common_1.MimeTypes.opra_response_json,
|
|
95
|
+
])
|
|
89
96
|
? this.response.body.payload
|
|
90
97
|
: this.response.body;
|
|
91
98
|
for (const item of data) {
|
|
@@ -105,7 +112,9 @@ class ApiExpectCollection extends api_expect_base_js_1.ApiExpectBase {
|
|
|
105
112
|
toContainAllFields(fields) {
|
|
106
113
|
try {
|
|
107
114
|
fields = Array.isArray(fields) ? fields : [fields];
|
|
108
|
-
const data = type_is_1.default.is(this.response.contentType, [
|
|
115
|
+
const data = type_is_1.default.is(this.response.contentType, [
|
|
116
|
+
common_1.MimeTypes.opra_response_json,
|
|
117
|
+
])
|
|
109
118
|
? this.response.body.payload
|
|
110
119
|
: this.response.body;
|
|
111
120
|
for (const item of data) {
|
|
@@ -125,7 +134,9 @@ class ApiExpectCollection extends api_expect_base_js_1.ApiExpectBase {
|
|
|
125
134
|
toBeSortedBy(fields) {
|
|
126
135
|
try {
|
|
127
136
|
fields = Array.isArray(fields) ? fields : [fields];
|
|
128
|
-
const data = type_is_1.default.is(this.response.contentType, [
|
|
137
|
+
const data = type_is_1.default.is(this.response.contentType, [
|
|
138
|
+
common_1.MimeTypes.opra_response_json,
|
|
139
|
+
])
|
|
129
140
|
? this.response.body.payload
|
|
130
141
|
: this.response.body;
|
|
131
142
|
this._expect(data).opraCollectionToBeSortedBy(fields);
|
|
@@ -144,7 +155,9 @@ class ApiExpectCollection extends api_expect_base_js_1.ApiExpectBase {
|
|
|
144
155
|
const f = convertFilter(filter);
|
|
145
156
|
if (f) {
|
|
146
157
|
const j = ruleJudgment(f);
|
|
147
|
-
const data = type_is_1.default.is(this.response.contentType, [
|
|
158
|
+
const data = type_is_1.default.is(this.response.contentType, [
|
|
159
|
+
common_1.MimeTypes.opra_response_json,
|
|
160
|
+
])
|
|
148
161
|
? this.response.body.payload
|
|
149
162
|
: this.response.body;
|
|
150
163
|
const filtered = data.filter(j);
|
|
@@ -189,7 +202,7 @@ expect.extend({
|
|
|
189
202
|
try {
|
|
190
203
|
expect(received).toEqual(sorted);
|
|
191
204
|
}
|
|
192
|
-
catch
|
|
205
|
+
catch {
|
|
193
206
|
pass = false;
|
|
194
207
|
message = () => 'Items are not sorted as expected';
|
|
195
208
|
}
|
|
@@ -10,7 +10,9 @@ class ApiExpectError extends api_expect_base_js_1.ApiExpectBase {
|
|
|
10
10
|
if (typeof expected === 'string')
|
|
11
11
|
expected = { message: expected };
|
|
12
12
|
else if (expected instanceof RegExp) {
|
|
13
|
-
expected = {
|
|
13
|
+
expected = {
|
|
14
|
+
message: expect.stringMatching(expected),
|
|
15
|
+
};
|
|
14
16
|
}
|
|
15
17
|
else
|
|
16
18
|
expected = (0, objects_1.omitNullish)(expected);
|
|
@@ -17,7 +17,9 @@ class ApiExpectObject extends api_expect_base_js_1.ApiExpectBase {
|
|
|
17
17
|
toMatch(expected) {
|
|
18
18
|
try {
|
|
19
19
|
expected = (0, objects_1.omitNullish)(expected);
|
|
20
|
-
const data = type_is_1.default.is(this.response.contentType, [
|
|
20
|
+
const data = type_is_1.default.is(this.response.contentType, [
|
|
21
|
+
common_1.MimeTypes.opra_response_json,
|
|
22
|
+
])
|
|
21
23
|
? this.response.body.payload
|
|
22
24
|
: this.response.body;
|
|
23
25
|
this._expect(data).toEqual(expect.objectContaining(expected));
|
|
@@ -35,7 +37,9 @@ class ApiExpectObject extends api_expect_base_js_1.ApiExpectBase {
|
|
|
35
37
|
toContainFields(fields) {
|
|
36
38
|
try {
|
|
37
39
|
fields = Array.isArray(fields) ? fields : [fields];
|
|
38
|
-
const data = type_is_1.default.is(this.response.contentType, [
|
|
40
|
+
const data = type_is_1.default.is(this.response.contentType, [
|
|
41
|
+
common_1.MimeTypes.opra_response_json,
|
|
42
|
+
])
|
|
39
43
|
? this.response.body.payload
|
|
40
44
|
: this.response.body;
|
|
41
45
|
this._expect(Object.keys(data)).toEqual(expect.arrayContaining(fields));
|
|
@@ -53,7 +57,9 @@ class ApiExpectObject extends api_expect_base_js_1.ApiExpectBase {
|
|
|
53
57
|
toContainAllFields(fields) {
|
|
54
58
|
try {
|
|
55
59
|
fields = Array.isArray(fields) ? fields : [fields];
|
|
56
|
-
const data = type_is_1.default.is(this.response.contentType, [
|
|
60
|
+
const data = type_is_1.default.is(this.response.contentType, [
|
|
61
|
+
common_1.MimeTypes.opra_response_json,
|
|
62
|
+
])
|
|
57
63
|
? this.response.body.payload
|
|
58
64
|
: this.response.body;
|
|
59
65
|
this._expect(Object.keys(data)).toEqual(fields);
|
|
@@ -28,17 +28,22 @@ class ApiExpect extends api_expect_base_js_1.ApiExpectBase {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
catch (e) {
|
|
31
|
-
e.message =
|
|
31
|
+
e.message =
|
|
32
|
+
"Request didn't succeeded as expected. " + msg + '\n\n' + e.message;
|
|
32
33
|
const issues = this.response.body?.errors;
|
|
33
34
|
if (issues) {
|
|
34
35
|
e.message += '\n\n';
|
|
35
36
|
issues.forEach((issue, i) => {
|
|
36
|
-
const stack = Array.isArray(issue.stack)
|
|
37
|
+
const stack = Array.isArray(issue.stack)
|
|
38
|
+
? issue.stack.join('\n')
|
|
39
|
+
: issue.stack;
|
|
37
40
|
e.message +=
|
|
38
41
|
ansi_colors_1.default.yellow(issues.length > 1 ? `Error [${i}]: ` : 'Error: ') +
|
|
39
42
|
issue.message +
|
|
40
43
|
'\n' +
|
|
41
|
-
(stack
|
|
44
|
+
(stack
|
|
45
|
+
? ' ' + stack.substring(stack.indexOf('at ')) + '\n'
|
|
46
|
+
: '');
|
|
42
47
|
});
|
|
43
48
|
}
|
|
44
49
|
Error.captureStackTrace(e, this.toSuccess);
|
|
@@ -63,17 +68,22 @@ class ApiExpect extends api_expect_base_js_1.ApiExpectBase {
|
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
catch (e) {
|
|
66
|
-
e.message =
|
|
71
|
+
e.message =
|
|
72
|
+
"Request didn't failed as expected. " + msg + '\n\n' + e.message;
|
|
67
73
|
const issues = this.response.body?.errors;
|
|
68
74
|
if (issues) {
|
|
69
75
|
e.message += '\n\n';
|
|
70
76
|
issues.forEach((issue, i) => {
|
|
71
|
-
const stack = Array.isArray(issue.stack)
|
|
77
|
+
const stack = Array.isArray(issue.stack)
|
|
78
|
+
? issue.stack.join('\n')
|
|
79
|
+
: issue.stack;
|
|
72
80
|
e.message +=
|
|
73
81
|
ansi_colors_1.default.yellow(issues.length > 1 ? `Error [${i}]: ` : 'Error: ') +
|
|
74
82
|
issue.message +
|
|
75
83
|
'\n' +
|
|
76
|
-
(stack
|
|
84
|
+
(stack
|
|
85
|
+
? ' ' + stack.substring(stack.indexOf('at ')) + '\n'
|
|
86
|
+
: '');
|
|
77
87
|
});
|
|
78
88
|
}
|
|
79
89
|
Error.captureStackTrace(e, this.toSuccess);
|
|
@@ -96,7 +106,8 @@ class ApiExpect extends api_expect_base_js_1.ApiExpectBase {
|
|
|
96
106
|
expect(Array.isArray(payload) ? 'array' : typeof payload).toEqual('array');
|
|
97
107
|
}
|
|
98
108
|
catch (e) {
|
|
99
|
-
e.message =
|
|
109
|
+
e.message =
|
|
110
|
+
"Api didn't returned a Collection. " + msg + '\n\n' + e.message;
|
|
100
111
|
if (msg)
|
|
101
112
|
e.message = msg + '\n\n' + e.message;
|
|
102
113
|
Error.captureStackTrace(e, this.toReturnCollection);
|
|
@@ -142,7 +153,8 @@ class ApiExpect extends api_expect_base_js_1.ApiExpectBase {
|
|
|
142
153
|
expect(typeof payload).toEqual('undefined');
|
|
143
154
|
}
|
|
144
155
|
catch (e) {
|
|
145
|
-
e.message =
|
|
156
|
+
e.message =
|
|
157
|
+
"Api didn't returned a OperationResult. " + msg + '\n\n' + e.message;
|
|
146
158
|
if (msg)
|
|
147
159
|
e.message = msg + '\n\n' + e.message;
|
|
148
160
|
Error.captureStackTrace(e, this.toReturnCollection);
|
package/cjs/test-backend.js
CHANGED
|
@@ -12,7 +12,9 @@ const api_expect_js_1 = require("./api-expect/api-expect.js");
|
|
|
12
12
|
*/
|
|
13
13
|
class TestBackend extends client_1.FetchBackend {
|
|
14
14
|
constructor(app, options) {
|
|
15
|
-
super(options?.basePath
|
|
15
|
+
super(options?.basePath
|
|
16
|
+
? path.join('http://tempuri.org', options.basePath)
|
|
17
|
+
: 'http://tempuri.org', options);
|
|
16
18
|
this._server = app instanceof node_http_1.Server ? app : (0, node_http_1.createServer)(app);
|
|
17
19
|
}
|
|
18
20
|
send(req) {
|
|
@@ -3,8 +3,9 @@ import { omitNullish } from '@jsopen/objects';
|
|
|
3
3
|
import { MimeTypes, OpraFilter } from '@opra/common';
|
|
4
4
|
import ruleJudgmentLib from 'rule-judgment';
|
|
5
5
|
import { ApiExpectBase } from './api-expect-base.js';
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const ruleJudgment = typeof ruleJudgmentLib === 'object'
|
|
7
|
+
? ruleJudgmentLib.default
|
|
8
|
+
: ruleJudgmentLib;
|
|
8
9
|
export class ApiExpectCollection extends ApiExpectBase {
|
|
9
10
|
get not() {
|
|
10
11
|
return new ApiExpectCollection(this.response, !this.isNot);
|
|
@@ -17,7 +18,9 @@ export class ApiExpectCollection extends ApiExpectBase {
|
|
|
17
18
|
toReturnItems(min, max) {
|
|
18
19
|
let msg = '';
|
|
19
20
|
try {
|
|
20
|
-
const data = typeIs.is(this.response.contentType, [
|
|
21
|
+
const data = typeIs.is(this.response.contentType, [
|
|
22
|
+
MimeTypes.opra_response_json,
|
|
23
|
+
])
|
|
21
24
|
? this.response.body.payload
|
|
22
25
|
: this.response.body;
|
|
23
26
|
msg += `Payload should be array.`;
|
|
@@ -60,7 +63,9 @@ export class ApiExpectCollection extends ApiExpectBase {
|
|
|
60
63
|
toMatch(expected) {
|
|
61
64
|
try {
|
|
62
65
|
expected = omitNullish(expected);
|
|
63
|
-
const data = typeIs.is(this.response.contentType, [
|
|
66
|
+
const data = typeIs.is(this.response.contentType, [
|
|
67
|
+
MimeTypes.opra_response_json,
|
|
68
|
+
])
|
|
64
69
|
? this.response.body.payload
|
|
65
70
|
: this.response.body;
|
|
66
71
|
for (const x of data) {
|
|
@@ -80,7 +85,9 @@ export class ApiExpectCollection extends ApiExpectBase {
|
|
|
80
85
|
toContainFields(fields) {
|
|
81
86
|
try {
|
|
82
87
|
fields = Array.isArray(fields) ? fields : [fields];
|
|
83
|
-
const data = typeIs.is(this.response.contentType, [
|
|
88
|
+
const data = typeIs.is(this.response.contentType, [
|
|
89
|
+
MimeTypes.opra_response_json,
|
|
90
|
+
])
|
|
84
91
|
? this.response.body.payload
|
|
85
92
|
: this.response.body;
|
|
86
93
|
for (const item of data) {
|
|
@@ -100,7 +107,9 @@ export class ApiExpectCollection extends ApiExpectBase {
|
|
|
100
107
|
toContainAllFields(fields) {
|
|
101
108
|
try {
|
|
102
109
|
fields = Array.isArray(fields) ? fields : [fields];
|
|
103
|
-
const data = typeIs.is(this.response.contentType, [
|
|
110
|
+
const data = typeIs.is(this.response.contentType, [
|
|
111
|
+
MimeTypes.opra_response_json,
|
|
112
|
+
])
|
|
104
113
|
? this.response.body.payload
|
|
105
114
|
: this.response.body;
|
|
106
115
|
for (const item of data) {
|
|
@@ -120,7 +129,9 @@ export class ApiExpectCollection extends ApiExpectBase {
|
|
|
120
129
|
toBeSortedBy(fields) {
|
|
121
130
|
try {
|
|
122
131
|
fields = Array.isArray(fields) ? fields : [fields];
|
|
123
|
-
const data = typeIs.is(this.response.contentType, [
|
|
132
|
+
const data = typeIs.is(this.response.contentType, [
|
|
133
|
+
MimeTypes.opra_response_json,
|
|
134
|
+
])
|
|
124
135
|
? this.response.body.payload
|
|
125
136
|
: this.response.body;
|
|
126
137
|
this._expect(data).opraCollectionToBeSortedBy(fields);
|
|
@@ -139,7 +150,9 @@ export class ApiExpectCollection extends ApiExpectBase {
|
|
|
139
150
|
const f = convertFilter(filter);
|
|
140
151
|
if (f) {
|
|
141
152
|
const j = ruleJudgment(f);
|
|
142
|
-
const data = typeIs.is(this.response.contentType, [
|
|
153
|
+
const data = typeIs.is(this.response.contentType, [
|
|
154
|
+
MimeTypes.opra_response_json,
|
|
155
|
+
])
|
|
143
156
|
? this.response.body.payload
|
|
144
157
|
: this.response.body;
|
|
145
158
|
const filtered = data.filter(j);
|
|
@@ -183,7 +196,7 @@ expect.extend({
|
|
|
183
196
|
try {
|
|
184
197
|
expect(received).toEqual(sorted);
|
|
185
198
|
}
|
|
186
|
-
catch
|
|
199
|
+
catch {
|
|
187
200
|
pass = false;
|
|
188
201
|
message = () => 'Items are not sorted as expected';
|
|
189
202
|
}
|
|
@@ -7,7 +7,9 @@ export class ApiExpectError extends ApiExpectBase {
|
|
|
7
7
|
if (typeof expected === 'string')
|
|
8
8
|
expected = { message: expected };
|
|
9
9
|
else if (expected instanceof RegExp) {
|
|
10
|
-
expected = {
|
|
10
|
+
expected = {
|
|
11
|
+
message: expect.stringMatching(expected),
|
|
12
|
+
};
|
|
11
13
|
}
|
|
12
14
|
else
|
|
13
15
|
expected = omitNullish(expected);
|
|
@@ -13,7 +13,9 @@ export class ApiExpectObject extends ApiExpectBase {
|
|
|
13
13
|
toMatch(expected) {
|
|
14
14
|
try {
|
|
15
15
|
expected = omitNullish(expected);
|
|
16
|
-
const data = typeIs.is(this.response.contentType, [
|
|
16
|
+
const data = typeIs.is(this.response.contentType, [
|
|
17
|
+
MimeTypes.opra_response_json,
|
|
18
|
+
])
|
|
17
19
|
? this.response.body.payload
|
|
18
20
|
: this.response.body;
|
|
19
21
|
this._expect(data).toEqual(expect.objectContaining(expected));
|
|
@@ -31,7 +33,9 @@ export class ApiExpectObject extends ApiExpectBase {
|
|
|
31
33
|
toContainFields(fields) {
|
|
32
34
|
try {
|
|
33
35
|
fields = Array.isArray(fields) ? fields : [fields];
|
|
34
|
-
const data = typeIs.is(this.response.contentType, [
|
|
36
|
+
const data = typeIs.is(this.response.contentType, [
|
|
37
|
+
MimeTypes.opra_response_json,
|
|
38
|
+
])
|
|
35
39
|
? this.response.body.payload
|
|
36
40
|
: this.response.body;
|
|
37
41
|
this._expect(Object.keys(data)).toEqual(expect.arrayContaining(fields));
|
|
@@ -49,7 +53,9 @@ export class ApiExpectObject extends ApiExpectBase {
|
|
|
49
53
|
toContainAllFields(fields) {
|
|
50
54
|
try {
|
|
51
55
|
fields = Array.isArray(fields) ? fields : [fields];
|
|
52
|
-
const data = typeIs.is(this.response.contentType, [
|
|
56
|
+
const data = typeIs.is(this.response.contentType, [
|
|
57
|
+
MimeTypes.opra_response_json,
|
|
58
|
+
])
|
|
53
59
|
? this.response.body.payload
|
|
54
60
|
: this.response.body;
|
|
55
61
|
this._expect(Object.keys(data)).toEqual(fields);
|
|
@@ -24,17 +24,22 @@ export class ApiExpect extends ApiExpectBase {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
catch (e) {
|
|
27
|
-
e.message =
|
|
27
|
+
e.message =
|
|
28
|
+
"Request didn't succeeded as expected. " + msg + '\n\n' + e.message;
|
|
28
29
|
const issues = this.response.body?.errors;
|
|
29
30
|
if (issues) {
|
|
30
31
|
e.message += '\n\n';
|
|
31
32
|
issues.forEach((issue, i) => {
|
|
32
|
-
const stack = Array.isArray(issue.stack)
|
|
33
|
+
const stack = Array.isArray(issue.stack)
|
|
34
|
+
? issue.stack.join('\n')
|
|
35
|
+
: issue.stack;
|
|
33
36
|
e.message +=
|
|
34
37
|
colors.yellow(issues.length > 1 ? `Error [${i}]: ` : 'Error: ') +
|
|
35
38
|
issue.message +
|
|
36
39
|
'\n' +
|
|
37
|
-
(stack
|
|
40
|
+
(stack
|
|
41
|
+
? ' ' + stack.substring(stack.indexOf('at ')) + '\n'
|
|
42
|
+
: '');
|
|
38
43
|
});
|
|
39
44
|
}
|
|
40
45
|
Error.captureStackTrace(e, this.toSuccess);
|
|
@@ -59,17 +64,22 @@ export class ApiExpect extends ApiExpectBase {
|
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
catch (e) {
|
|
62
|
-
e.message =
|
|
67
|
+
e.message =
|
|
68
|
+
"Request didn't failed as expected. " + msg + '\n\n' + e.message;
|
|
63
69
|
const issues = this.response.body?.errors;
|
|
64
70
|
if (issues) {
|
|
65
71
|
e.message += '\n\n';
|
|
66
72
|
issues.forEach((issue, i) => {
|
|
67
|
-
const stack = Array.isArray(issue.stack)
|
|
73
|
+
const stack = Array.isArray(issue.stack)
|
|
74
|
+
? issue.stack.join('\n')
|
|
75
|
+
: issue.stack;
|
|
68
76
|
e.message +=
|
|
69
77
|
colors.yellow(issues.length > 1 ? `Error [${i}]: ` : 'Error: ') +
|
|
70
78
|
issue.message +
|
|
71
79
|
'\n' +
|
|
72
|
-
(stack
|
|
80
|
+
(stack
|
|
81
|
+
? ' ' + stack.substring(stack.indexOf('at ')) + '\n'
|
|
82
|
+
: '');
|
|
73
83
|
});
|
|
74
84
|
}
|
|
75
85
|
Error.captureStackTrace(e, this.toSuccess);
|
|
@@ -92,7 +102,8 @@ export class ApiExpect extends ApiExpectBase {
|
|
|
92
102
|
expect(Array.isArray(payload) ? 'array' : typeof payload).toEqual('array');
|
|
93
103
|
}
|
|
94
104
|
catch (e) {
|
|
95
|
-
e.message =
|
|
105
|
+
e.message =
|
|
106
|
+
"Api didn't returned a Collection. " + msg + '\n\n' + e.message;
|
|
96
107
|
if (msg)
|
|
97
108
|
e.message = msg + '\n\n' + e.message;
|
|
98
109
|
Error.captureStackTrace(e, this.toReturnCollection);
|
|
@@ -138,7 +149,8 @@ export class ApiExpect extends ApiExpectBase {
|
|
|
138
149
|
expect(typeof payload).toEqual('undefined');
|
|
139
150
|
}
|
|
140
151
|
catch (e) {
|
|
141
|
-
e.message =
|
|
152
|
+
e.message =
|
|
153
|
+
"Api didn't returned a OperationResult. " + msg + '\n\n' + e.message;
|
|
142
154
|
if (msg)
|
|
143
155
|
e.message = msg + '\n\n' + e.message;
|
|
144
156
|
Error.captureStackTrace(e, this.toReturnCollection);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import colors from 'ansi-colors';
|
|
2
|
-
import { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';
|
|
2
|
+
import { matcherHint, printExpected, printReceived, } from 'jest-matcher-utils';
|
|
3
3
|
expect.extend({
|
|
4
4
|
toHaveFields(received, expected) {
|
|
5
5
|
const expectedKeys = (Array.isArray(expected) ? expected : Object.keys(expected)).map(x => x.toLowerCase());
|
package/esm/test-backend.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createServer, Server } from 'node:http';
|
|
1
|
+
import { createServer, Server, } from 'node:http';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { FetchBackend, HttpResponse } from '@opra/client';
|
|
4
4
|
import { ApiExpect } from './api-expect/api-expect.js';
|
|
@@ -8,7 +8,9 @@ import { ApiExpect } from './api-expect/api-expect.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export class TestBackend extends FetchBackend {
|
|
10
10
|
constructor(app, options) {
|
|
11
|
-
super(options?.basePath
|
|
11
|
+
super(options?.basePath
|
|
12
|
+
? path.join('http://tempuri.org', options.basePath)
|
|
13
|
+
: 'http://tempuri.org', options);
|
|
12
14
|
this._server = app instanceof Server ? app : createServer(app);
|
|
13
15
|
}
|
|
14
16
|
send(req) {
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/testing",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Opra testing package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@browsery/type-is": "^1.6.18-r5",
|
|
9
9
|
"@jsopen/objects": "^1.5.0",
|
|
10
|
-
"@opra/client": "^1.4.
|
|
11
|
-
"@opra/common": "^1.4.
|
|
10
|
+
"@opra/client": "^1.4.4",
|
|
11
|
+
"@opra/common": "^1.4.4",
|
|
12
12
|
"ansi-colors": "^4.1.3",
|
|
13
13
|
"jest-matcher-utils": "^29.7.0",
|
|
14
14
|
"rule-judgment": "^1.1.5",
|