deflake 1.0.7 â 1.0.8
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/cli.js +77 -24
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -307,7 +307,7 @@ function extractFailureLocation(logText) {
|
|
|
307
307
|
return null;
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
function printDetailedFix(fixText, location, sourceCode = null) {
|
|
310
|
+
function printDetailedFix(fixText, location, sourceCode = null, isApplied = false) {
|
|
311
311
|
const C = {
|
|
312
312
|
RESET: "\x1b[0m",
|
|
313
313
|
BRIGHT: "\x1b[1m",
|
|
@@ -332,32 +332,85 @@ function printDetailedFix(fixText, location, sourceCode = null) {
|
|
|
332
332
|
} catch (e) { }
|
|
333
333
|
|
|
334
334
|
console.log("\n" + C.GRAY + "â".repeat(50) + C.RESET);
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
335
|
+
|
|
336
|
+
if (isApplied) {
|
|
337
|
+
// --- APPLIED VIEW ---
|
|
338
|
+
console.log(`${C.GREEN}${C.BRIGHT}â
FIX APPLIED:${C.RESET}`);
|
|
339
|
+
if (location) {
|
|
340
|
+
// Label is default color, Value is colored
|
|
341
|
+
const fileLabel = location.specFile || location.rootFile;
|
|
342
|
+
let lineLabel = location.testLine || location.rootLine;
|
|
343
|
+
|
|
344
|
+
if (fileLabel) {
|
|
345
|
+
console.log(`${C.BRIGHT}đ File:${C.RESET} ${fileLabel}:${lineLabel}`);
|
|
346
|
+
}
|
|
339
347
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (location.testLine) targetLabel += `:${location.testLine}`;
|
|
344
|
-
console.log(`đ¯ Fix Target: ${C.CYAN}${targetLabel} (Definition)${C.RESET}`);
|
|
348
|
+
|
|
349
|
+
if (explanation) { // Highlight the reason as requested by user
|
|
350
|
+
console.log(`\n${C.BRIGHT}âšī¸ Reason:${C.RESET} ${explanation}`);
|
|
345
351
|
}
|
|
352
|
+
|
|
353
|
+
console.log(C.GRAY + "â".repeat(20) + C.RESET);
|
|
354
|
+
|
|
355
|
+
// --- OLD CODE (Context) ---
|
|
356
|
+
if (sourceCode && location && location.rootLine) {
|
|
357
|
+
console.log(`${C.RED}đ´ OLD:${C.RESET}`);
|
|
358
|
+
try {
|
|
359
|
+
const lines = sourceCode.split('\n');
|
|
360
|
+
const centerIdx = parseInt(location.rootLine) - 1;
|
|
361
|
+
// Show a small window around the error
|
|
362
|
+
const start = Math.max(0, centerIdx - 2);
|
|
363
|
+
const end = Math.min(lines.length - 1, centerIdx + 2);
|
|
364
|
+
|
|
365
|
+
for (let i = start; i <= end; i++) {
|
|
366
|
+
let prefix = (i === centerIdx) ? "> " : " ";
|
|
367
|
+
let line = lines[i];
|
|
368
|
+
if (i === centerIdx) line = `${C.RED}${line}${C.RESET}`;
|
|
369
|
+
else line = `${C.GRAY}${line}${C.RESET}`;
|
|
370
|
+
console.log(prefix + line);
|
|
371
|
+
}
|
|
372
|
+
} catch (e) { }
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// --- NEW CODE ---
|
|
376
|
+
console.log(`\n${C.GREEN}đĸ NEW:${C.RESET}`);
|
|
377
|
+
fixCode.split('\n').forEach(line => {
|
|
378
|
+
let colored = line
|
|
379
|
+
.replace(/(\/\/.*)/g, `${C.GRAY}$1${C.RESET}`)
|
|
380
|
+
.replace(/\b(const|let|var|await|async|function|return)\b/g, `${C.YELLOW}$1${C.RESET}`)
|
|
381
|
+
.replace(/('.*?')|(".*?")|(`.*?`)/g, `${C.GREEN}$1${C.RESET}`)
|
|
382
|
+
.replace(/(\.click|\.fill|\.locator)/g, `${C.CYAN}$1${C.RESET}`);
|
|
383
|
+
console.log(" " + colored);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
} else {
|
|
387
|
+
// --- SUGGESTION VIEW (Default) ---
|
|
388
|
+
if (location) {
|
|
389
|
+
if (location.rootFile && location.rootLine) {
|
|
390
|
+
console.log(`đĨ Runtime Error: ${C.RED}${location.rootFile}:${location.rootLine}${C.RESET}`);
|
|
391
|
+
}
|
|
392
|
+
if (location.specFile) {
|
|
393
|
+
let targetLabel = location.specFile;
|
|
394
|
+
if (location.testLine) targetLabel += `:${location.testLine}`;
|
|
395
|
+
console.log(`đ¯ Fix Target: ${C.CYAN}${targetLabel} (Definition)${C.RESET}`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
console.log(C.GRAY + "â".repeat(50) + C.RESET);
|
|
399
|
+
|
|
400
|
+
console.log(`${C.GREEN}${C.BRIGHT}⨠DEFLAKE SUGGESTION:${C.RESET}`);
|
|
401
|
+
if (explanation) console.log(`${C.GRAY}// ${explanation}${C.RESET}`);
|
|
402
|
+
|
|
403
|
+
// Print code with simple coloring
|
|
404
|
+
fixCode.split('\n').forEach(line => {
|
|
405
|
+
let colored = line
|
|
406
|
+
.replace(/(\/\/.*)/g, `${C.GRAY}$1${C.RESET}`)
|
|
407
|
+
.replace(/\b(const|let|var|await|async|function|return)\b/g, `${C.YELLOW}$1${C.RESET}`)
|
|
408
|
+
.replace(/('.*?')|(".*?")|(`.*?`)/g, `${C.GREEN}$1${C.RESET}`)
|
|
409
|
+
.replace(/(\.click|\.fill|\.locator)/g, `${C.CYAN}$1${C.RESET}`);
|
|
410
|
+
console.log(" " + colored);
|
|
411
|
+
});
|
|
346
412
|
}
|
|
347
|
-
console.log(C.GRAY + "â".repeat(50) + C.RESET);
|
|
348
413
|
|
|
349
|
-
console.log(`${C.GREEN}${C.BRIGHT}⨠DEFLAKE SUGGESTION:${C.RESET}`);
|
|
350
|
-
if (explanation) console.log(`${C.GRAY}// ${explanation}${C.RESET}`);
|
|
351
|
-
|
|
352
|
-
// Print code with simple coloring
|
|
353
|
-
fixCode.split('\n').forEach(line => {
|
|
354
|
-
let colored = line
|
|
355
|
-
.replace(/(\/\/.*)/g, `${C.GRAY}$1${C.RESET}`)
|
|
356
|
-
.replace(/\b(const|let|var|await|async|function|return)\b/g, `${C.YELLOW}$1${C.RESET}`)
|
|
357
|
-
.replace(/('.*?')|(".*?")|(`.*?`)/g, `${C.GREEN}$1${C.RESET}`)
|
|
358
|
-
.replace(/(\.click|\.fill|\.locator)/g, `${C.CYAN}$1${C.RESET}`);
|
|
359
|
-
console.log(" " + colored);
|
|
360
|
-
});
|
|
361
414
|
console.log(C.GRAY + "â".repeat(50) + C.RESET);
|
|
362
415
|
}
|
|
363
416
|
|
|
@@ -690,7 +743,7 @@ async function analyzeFailures(artifacts, fullLog, client) {
|
|
|
690
743
|
});
|
|
691
744
|
|
|
692
745
|
for (const key of sortedKeys) {
|
|
693
|
-
printDetailedFix(groups[key].fix, groups[key].location, groups[key].sourceCode);
|
|
746
|
+
printDetailedFix(groups[key].fix, groups[key].location, groups[key].sourceCode, argv.fix);
|
|
694
747
|
}
|
|
695
748
|
|
|
696
749
|
if (results.length > 0 && sortedKeys.length === 0) {
|