@zohodesk/testinglibrary 0.4.72-n18-experimental → 0.4.73-n18-experimental
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.
|
@@ -8,6 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
10
|
var _codeFrame = require("@babel/code-frame");
|
|
11
|
+
var _JSONStream = _interopRequireDefault(require("JSONStream"));
|
|
11
12
|
class CustomJsonReporter {
|
|
12
13
|
constructor({
|
|
13
14
|
outputFile = 'test-results.json'
|
|
@@ -32,23 +33,12 @@ class CustomJsonReporter {
|
|
|
32
33
|
attachments: result.attachments,
|
|
33
34
|
startTime: result.startTime,
|
|
34
35
|
retry: result.retry,
|
|
35
|
-
stderr: result.stderr.map(err => (
|
|
36
|
-
|
|
37
|
-
})),
|
|
38
|
-
stdout: result.stdout.map(out => ({
|
|
39
|
-
text: out
|
|
40
|
-
})),
|
|
36
|
+
stderr: result.stderr.map(err => stdioEntry(err)),
|
|
37
|
+
stdout: result.stdout.map(out => stdioEntry(out)),
|
|
41
38
|
workerIndex: result.workerIndex,
|
|
42
39
|
duration: result.duration,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
stack,
|
|
46
|
-
snippet
|
|
47
|
-
}) => ({
|
|
48
|
-
message,
|
|
49
|
-
stack,
|
|
50
|
-
snippet
|
|
51
|
-
}))) ?? [],
|
|
40
|
+
error: result.error,
|
|
41
|
+
errors: (_result$errors = result.errors) === null || _result$errors === void 0 ? void 0 : _result$errors.map(processError),
|
|
52
42
|
steps: ((_result$steps = result.steps) === null || _result$steps === void 0 ? void 0 : _result$steps.map(step => extractMergedSteps(this.report.config.rootDir, step))) ?? []
|
|
53
43
|
};
|
|
54
44
|
const existingResults = this.testResultsById.get(key) ?? [];
|
|
@@ -178,4 +168,125 @@ const parseLocation = (rootDir, {
|
|
|
178
168
|
file: isRelative ? _path.default.relative(rootDir, file) : file,
|
|
179
169
|
line,
|
|
180
170
|
column
|
|
181
|
-
} : {};
|
|
171
|
+
} : {};
|
|
172
|
+
const stdioEntry = s => typeof s === 'string' ? {
|
|
173
|
+
text: s
|
|
174
|
+
} : {
|
|
175
|
+
buffer: s.toString('base64')
|
|
176
|
+
};
|
|
177
|
+
const processError = error => {
|
|
178
|
+
const message = error.message || error.value || '';
|
|
179
|
+
const stack = error.stack;
|
|
180
|
+
if (!stack && !error.location) return {
|
|
181
|
+
message
|
|
182
|
+
};
|
|
183
|
+
const tokens = [];
|
|
184
|
+
const parsedStack = stack ? constructErrorStack(stack) : undefined;
|
|
185
|
+
tokens.push((parsedStack === null || parsedStack === void 0 ? void 0 : parsedStack.message) || message);
|
|
186
|
+
if (error.snippet) {
|
|
187
|
+
tokens.push('');
|
|
188
|
+
tokens.push(error.snippet);
|
|
189
|
+
}
|
|
190
|
+
if (parsedStack && parsedStack.stackLines.length) {
|
|
191
|
+
const dimmedStackLines = parsedStack.stackLines.split('\n').map(line => dimify(line));
|
|
192
|
+
tokens.push(dimmedStackLines.join('\n'));
|
|
193
|
+
}
|
|
194
|
+
let location = error.location;
|
|
195
|
+
if (parsedStack && !location) location = parsedStack.location;
|
|
196
|
+
if (error.cause) tokens.push(dimify('[cause]: ') + processError(error.cause).message);
|
|
197
|
+
return {
|
|
198
|
+
location,
|
|
199
|
+
message: tokens.join('\n')
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
const constructErrorStack = stack => parseErrorStack(stack, _path.default.sep, false);
|
|
203
|
+
const dimify = text => `\x1b[2m${text}\x1b[22m`;
|
|
204
|
+
const parseErrorStack = (stack, pathSeparator, showInternalStackFrames = false) => {
|
|
205
|
+
const lines = stack.split("\n");
|
|
206
|
+
let firstStackLineIndex = lines.findIndex(line => line.startsWith(" at "));
|
|
207
|
+
if (firstStackLineIndex === -1) firstStackLineIndex = lines.length;
|
|
208
|
+
const message = lines.slice(0, firstStackLineIndex).join("\n");
|
|
209
|
+
const stackStartIndex = indexLocator(stack, '\n', firstStackLineIndex) + 1 || 0;
|
|
210
|
+
const stackLinesString = stackStartIndex ? stack.slice(stackStartIndex) : '';
|
|
211
|
+
let location;
|
|
212
|
+
const stackLinesArr = stackLinesString.split('\n');
|
|
213
|
+
for (const line of stackLinesArr) {
|
|
214
|
+
const frame = parseStackFrame(line, pathSeparator, showInternalStackFrames);
|
|
215
|
+
if (!frame || !frame.file) continue;
|
|
216
|
+
if (isInNodeModules(frame.file, pathSeparator)) continue;
|
|
217
|
+
location = {
|
|
218
|
+
file: frame.file,
|
|
219
|
+
column: frame.column || 0,
|
|
220
|
+
line: frame.line || 0
|
|
221
|
+
};
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
message,
|
|
226
|
+
stackLines: stackLinesString,
|
|
227
|
+
location
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
const indexLocator = (str, pat, n) => {
|
|
231
|
+
let L = str.length,
|
|
232
|
+
i = -1;
|
|
233
|
+
while (n-- && i++ < L) {
|
|
234
|
+
i = str.indexOf(pat, i);
|
|
235
|
+
if (i < 0) break;
|
|
236
|
+
}
|
|
237
|
+
return i;
|
|
238
|
+
};
|
|
239
|
+
const isInNodeModules = (file, pathSeparator) => file.includes(`${pathSeparator}node_modules${pathSeparator}`);
|
|
240
|
+
const parseStackFrame = (text, pathSeparator, showInternalStackFrames) => {
|
|
241
|
+
const re = new RegExp("^(?:\\s*at )?(?:(new) )?(?:(.*?) \\()?(?:eval at ([^ ]+) \\((.+?):(\\d+):(\\d+)\\), )?(?:(.+?):(\\d+):(\\d+)|(native))(\\)?)$");
|
|
242
|
+
const methodRe = /^(.*?) \[as (.*?)\]$/;
|
|
243
|
+
const match = text && text.match(re);
|
|
244
|
+
if (!match) return null;
|
|
245
|
+
let fname = match[2];
|
|
246
|
+
let file = match[7];
|
|
247
|
+
if (!file) return null;
|
|
248
|
+
if (!showInternalStackFrames && (file.startsWith("internal") || file.startsWith("node:"))) return null;
|
|
249
|
+
const line = match[8];
|
|
250
|
+
const column = match[9];
|
|
251
|
+
const closeParen = match[11] === ")";
|
|
252
|
+
const frame = {
|
|
253
|
+
file: "",
|
|
254
|
+
line: 0,
|
|
255
|
+
column: 0
|
|
256
|
+
};
|
|
257
|
+
if (line) frame.line = Number(line);
|
|
258
|
+
if (column) frame.column = Number(column);
|
|
259
|
+
if (closeParen && file) {
|
|
260
|
+
let closes = 0;
|
|
261
|
+
for (let i = file.length - 1; i > 0; i--) {
|
|
262
|
+
if (file.charAt(i) === ")") {
|
|
263
|
+
closes++;
|
|
264
|
+
} else if (file.charAt(i) === "(" && file.charAt(i - 1) === " ") {
|
|
265
|
+
closes--;
|
|
266
|
+
if (closes === -1 && file.charAt(i - 1) === " ") {
|
|
267
|
+
const before = file.slice(0, i - 1);
|
|
268
|
+
const after = file.slice(i + 1);
|
|
269
|
+
file = after;
|
|
270
|
+
fname += ` (${before}`;
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (fname) {
|
|
277
|
+
const methodMatch = fname.match(methodRe);
|
|
278
|
+
if (methodMatch) fname = methodMatch[1];
|
|
279
|
+
}
|
|
280
|
+
if (file) {
|
|
281
|
+
if (file.startsWith("file://")) file = fileURLToPath(file, pathSeparator);
|
|
282
|
+
frame.file = file;
|
|
283
|
+
}
|
|
284
|
+
if (fname) frame.function = fname;
|
|
285
|
+
return frame;
|
|
286
|
+
};
|
|
287
|
+
const fileURLToPath = (fileUrl, pathSeparator) => {
|
|
288
|
+
if (!fileUrl.startsWith("file://")) return fileUrl;
|
|
289
|
+
let path = decodeURIComponent(fileUrl.slice(7));
|
|
290
|
+
if (path.startsWith("/") && /^[a-zA-Z]:/.test(path.slice(1))) path = path.slice(1);
|
|
291
|
+
return path.replace(/\//g, pathSeparator);
|
|
292
|
+
};
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/testinglibrary",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.73-n18-experimental",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@zohodesk/testinglibrary",
|
|
9
|
-
"version": "0.4.
|
|
9
|
+
"version": "0.4.73-n18-experimental",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|