@opra/testing 1.27.2 → 1.27.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.
@@ -48,4 +48,5 @@ export declare class ApiExpect extends ApiExpectBase {
48
48
  * @throws {@link Error} if the assertion fails.
49
49
  */
50
50
  toReturnOperationResult(): ApiExpectOperationResult;
51
+ protected _parseBodyErrors(errors: any[]): string | undefined;
51
52
  }
@@ -36,22 +36,11 @@ export class ApiExpect extends ApiExpectBase {
36
36
  catch (e) {
37
37
  e.message =
38
38
  "Request didn't succeeded as expected. " + msg + '\n\n' + e.message;
39
- const issues = this.response.body?.errors;
40
- if (issues) {
41
- e.message += '\n\n';
42
- issues.forEach((issue, i) => {
43
- const stack = Array.isArray(issue.stack)
44
- ? issue.stack.join('\n')
45
- : issue.stack;
46
- e.message +=
47
- colors.yellow(issues.length > 1 ? `Error [${i}]: ` : 'Error: ') +
48
- issue.message +
49
- '\n' +
50
- (stack
51
- ? ' ' + stack.substring(stack.indexOf('at ')) + '\n'
52
- : '');
53
- });
54
- }
39
+ const issues = this._parseBodyErrors(this.response.body?.errors);
40
+ if (issues)
41
+ e.message += '\n\n' + issues;
42
+ else
43
+ e.message += '\n\nbody: ' + this.response.body;
55
44
  if (typeof Error.captureStackTrace === 'function')
56
45
  Error.captureStackTrace(e, this.toSuccess);
57
46
  else
@@ -81,23 +70,12 @@ export class ApiExpect extends ApiExpectBase {
81
70
  }
82
71
  catch (e) {
83
72
  e.message =
84
- "Request didn't failed as expected. " + msg + '\n\n' + e.message;
85
- const issues = this.response.body?.errors;
86
- if (issues) {
87
- e.message += '\n\n';
88
- issues.forEach((issue, i) => {
89
- const stack = Array.isArray(issue.stack)
90
- ? issue.stack.join('\n')
91
- : issue.stack;
92
- e.message +=
93
- colors.yellow(issues.length > 1 ? `Error [${i}]: ` : 'Error: ') +
94
- issue.message +
95
- '\n' +
96
- (stack
97
- ? ' ' + stack.substring(stack.indexOf('at ')) + '\n'
98
- : '');
99
- });
100
- }
73
+ "Request didn't failed as expected. " +
74
+ msg +
75
+ '\n\n' +
76
+ e.message +
77
+ '\n\nbody: ' +
78
+ this.response.body;
101
79
  if (typeof Error.captureStackTrace === 'function')
102
80
  Error.captureStackTrace(e, this.toFail);
103
81
  else
@@ -125,9 +103,15 @@ export class ApiExpect extends ApiExpectBase {
125
103
  }
126
104
  catch (e) {
127
105
  e.message =
128
- "Api didn't returned a Collection. " + msg + '\n\n' + e.message;
129
- if (msg)
130
- e.message = msg + '\n\n' + e.message;
106
+ "Api didn't returned a Collection. " +
107
+ msg +
108
+ '\n\n' +
109
+ e.message +
110
+ '\n\nbody: ' +
111
+ this.response.body;
112
+ const issues = this._parseBodyErrors(this.response.body?.errors);
113
+ if (issues)
114
+ e.message += '\n\n' + issues;
131
115
  if (typeof Error.captureStackTrace === 'function')
132
116
  Error.captureStackTrace(e, this.toReturnCollection);
133
117
  else
@@ -155,9 +139,13 @@ export class ApiExpect extends ApiExpectBase {
155
139
  expect(typeof payload).toEqual('object');
156
140
  }
157
141
  catch (e) {
158
- e.message = "Api didn't returned an Object. " + msg + '\n\n' + e.message;
159
- if (msg)
160
- e.message = msg + '\n\n' + e.message;
142
+ e.message =
143
+ "Api didn't returned an Object. " +
144
+ msg +
145
+ '\n\n' +
146
+ e.message +
147
+ '\n\nbody: ' +
148
+ this.response.body;
161
149
  if (typeof Error.captureStackTrace === 'function')
162
150
  Error.captureStackTrace(e, this.toReturnObject);
163
151
  else
@@ -185,9 +173,17 @@ export class ApiExpect extends ApiExpectBase {
185
173
  }
186
174
  catch (e) {
187
175
  e.message =
188
- "Api didn't returned a OperationResult. " + msg + '\n\n' + e.message;
176
+ "Api didn't returned a OperationResult. " +
177
+ msg +
178
+ '\n\n' +
179
+ e.message +
180
+ '\n\nbody: ' +
181
+ this.response.body;
189
182
  if (msg)
190
183
  e.message = msg + '\n\n' + e.message;
184
+ const issues = this._parseBodyErrors(this.response.body?.errors);
185
+ if (issues)
186
+ e.message += '\n\n' + issues;
191
187
  if (typeof Error.captureStackTrace === 'function')
192
188
  Error.captureStackTrace(e, this.toReturnOperationResult);
193
189
  else
@@ -196,4 +192,20 @@ export class ApiExpect extends ApiExpectBase {
196
192
  }
197
193
  return new ApiExpectOperationResult(this.response);
198
194
  }
195
+ _parseBodyErrors(errors) {
196
+ if (Array.isArray(errors)) {
197
+ let out = '';
198
+ errors.forEach((issue, i) => {
199
+ const stack = Array.isArray(issue.stack)
200
+ ? issue.stack.join('\n')
201
+ : issue.stack;
202
+ out +=
203
+ colors.yellow(errors.length > 1 ? `Error [${i}]: ` : 'Error: ') +
204
+ issue.message +
205
+ '\n' +
206
+ (stack ? ' ' + stack.substring(stack.indexOf('at ')) + '\n' : '');
207
+ });
208
+ return out;
209
+ }
210
+ }
199
211
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/testing",
3
- "version": "1.27.2",
3
+ "version": "1.27.4",
4
4
  "description": "Opra testing package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -12,8 +12,8 @@
12
12
  "tslib": "^2.8.1"
13
13
  },
14
14
  "peerDependencies": {
15
- "@opra/client": "^1.27.2",
16
- "@opra/common": "^1.27.2",
15
+ "@opra/client": "^1.27.4",
16
+ "@opra/common": "^1.27.4",
17
17
  "expect": "^29.0.0 || ^30.0.0",
18
18
  "jest-matcher-utils": "^29.0.0 || ^30.0.0"
19
19
  },