@andy2639/jest-context 1.0.5 → 1.0.7
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/CHANGELOG.md +11 -0
- package/dist/bin/console-context.cjs +62 -21
- package/dist/bin/console-context.cjs.map +1 -1
- package/dist/bin/console-context.mjs +2 -2
- package/dist/bin/coverage-context.cjs +63 -28
- package/dist/bin/coverage-context.cjs.map +1 -1
- package/dist/bin/coverage-context.mjs +2 -2
- package/dist/bin/jest-context-init.mjs +2 -2
- package/dist/bin/test-context.cjs +63 -26
- package/dist/bin/test-context.cjs.map +1 -1
- package/dist/bin/test-context.mjs +2 -2
- package/dist/{chunk-44SYPQVJ.mjs → chunk-2B6NO7WQ.mjs} +35 -7
- package/dist/{chunk-44SYPQVJ.mjs.map → chunk-2B6NO7WQ.mjs.map} +1 -1
- package/dist/{chunk-54T2WTJJ.mjs → chunk-MRWQAVS4.mjs} +2 -2
- package/dist/{chunk-DFRTVPXC.mjs → chunk-SSW26YOL.mjs} +30 -17
- package/dist/chunk-SSW26YOL.mjs.map +1 -0
- package/dist/{chunk-DMN6LBSV.mjs → chunk-TQVH7JRM.mjs} +31 -24
- package/dist/chunk-TQVH7JRM.mjs.map +1 -0
- package/dist/{chunk-B3JGCTH3.mjs → chunk-UHFZOKGL.mjs} +31 -22
- package/dist/chunk-UHFZOKGL.mjs.map +1 -0
- package/dist/index.cjs +120 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +5 -5
- package/package.json +1 -1
- package/dist/chunk-B3JGCTH3.mjs.map +0 -1
- package/dist/chunk-DFRTVPXC.mjs.map +0 -1
- package/dist/chunk-DMN6LBSV.mjs.map +0 -1
- /package/dist/{chunk-54T2WTJJ.mjs.map → chunk-MRWQAVS4.mjs.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -541,17 +541,16 @@ var NOOP_PROGRESS_BAR = {
|
|
|
541
541
|
var hasWarnedSpinnerFallback = false;
|
|
542
542
|
var hasWarnedProgressFallback = false;
|
|
543
543
|
function shouldShowUI(exportMode, noBanner = false) {
|
|
544
|
-
return !
|
|
544
|
+
return !noBanner;
|
|
545
545
|
}
|
|
546
546
|
function displayBanner(config) {
|
|
547
547
|
const { text, subtitle, info = {}, colors = ["cyan"], font = "block" } = config;
|
|
548
|
-
const bannerText = [text, subtitle].filter(Boolean).join(" ").trim();
|
|
549
548
|
const cfonts = require("cfonts");
|
|
550
549
|
const boxenModule = require("boxen");
|
|
551
550
|
const boxen = typeof boxenModule === "function" ? boxenModule : boxenModule.default;
|
|
552
|
-
const
|
|
551
|
+
const renderedTitle = cfonts.render(text, {
|
|
553
552
|
font,
|
|
554
|
-
colors,
|
|
553
|
+
colors: [colors[0] ?? "cyan"],
|
|
555
554
|
align: "left",
|
|
556
555
|
background: "transparent",
|
|
557
556
|
letterSpacing: 1,
|
|
@@ -560,10 +559,39 @@ function displayBanner(config) {
|
|
|
560
559
|
maxLength: "0",
|
|
561
560
|
env: "node"
|
|
562
561
|
});
|
|
562
|
+
const renderedSubtitle = subtitle ? cfonts.render(subtitle, {
|
|
563
|
+
font,
|
|
564
|
+
colors: [colors[1] ?? colors[0] ?? "cyan"],
|
|
565
|
+
align: "left",
|
|
566
|
+
background: "transparent",
|
|
567
|
+
letterSpacing: 1,
|
|
568
|
+
lineHeight: 1,
|
|
569
|
+
space: false,
|
|
570
|
+
maxLength: "0",
|
|
571
|
+
env: "node"
|
|
572
|
+
}) : null;
|
|
573
|
+
const stripAnsi2 = (value) => value.replace(/\x1b\[[0-9;]*m/g, "");
|
|
574
|
+
const centerLines = (lines, width) => {
|
|
575
|
+
return lines.map((line) => {
|
|
576
|
+
const visibleLength = stripAnsi2(line).length;
|
|
577
|
+
const leftPad = Math.max(0, Math.floor((width - visibleLength) / 2));
|
|
578
|
+
return `${" ".repeat(leftPad)}${line}`;
|
|
579
|
+
});
|
|
580
|
+
};
|
|
581
|
+
const titleLines = renderedTitle.string.trimEnd().split("\n");
|
|
582
|
+
const subtitleLines = renderedSubtitle ? renderedSubtitle.string.trimEnd().split("\n") : [];
|
|
583
|
+
const centeredWidth = Math.max(
|
|
584
|
+
...titleLines.map((line) => stripAnsi2(line).length),
|
|
585
|
+
...(subtitleLines.length > 0 ? subtitleLines : [""]).map((line) => stripAnsi2(line).length)
|
|
586
|
+
);
|
|
563
587
|
const infoLine = Object.entries(info).map(([key, value]) => `${key}: ${value}`).join(" | ");
|
|
564
|
-
const contentLines = [
|
|
588
|
+
const contentLines = [...centerLines(titleLines, centeredWidth)];
|
|
589
|
+
if (subtitleLines.length > 0) {
|
|
590
|
+
contentLines.push("", ...centerLines(subtitleLines, centeredWidth));
|
|
591
|
+
}
|
|
592
|
+
contentLines.push("");
|
|
565
593
|
if (infoLine) {
|
|
566
|
-
contentLines.push(
|
|
594
|
+
contentLines.push(` ${infoLine}`);
|
|
567
595
|
}
|
|
568
596
|
contentLines.push(` Date: ${getDisplayTimestamp()}`);
|
|
569
597
|
const boxed = boxen(contentLines.join("\n"), {
|
|
@@ -620,6 +648,25 @@ function createProgressBar(total = 100, task = "Progress") {
|
|
|
620
648
|
}
|
|
621
649
|
|
|
622
650
|
// src/commands/test-context.ts
|
|
651
|
+
function outputTestContext(content, options) {
|
|
652
|
+
const { exportFormat } = options;
|
|
653
|
+
if (!exportFormat) {
|
|
654
|
+
handleExportOrDisplay(content, {
|
|
655
|
+
exportFormat,
|
|
656
|
+
prefix: "export-test-context",
|
|
657
|
+
title: "Test Context"
|
|
658
|
+
});
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const exportSpinner = createSpinner("Exporting test context...", "cyan");
|
|
662
|
+
exportSpinner.start();
|
|
663
|
+
handleExportOrDisplay(content, {
|
|
664
|
+
exportFormat,
|
|
665
|
+
prefix: "export-test-context",
|
|
666
|
+
title: "Test Context"
|
|
667
|
+
});
|
|
668
|
+
exportSpinner.succeed("Test context exported");
|
|
669
|
+
}
|
|
623
670
|
function extractFailures(raw) {
|
|
624
671
|
const lines = raw.split("\n");
|
|
625
672
|
const temp = [];
|
|
@@ -703,8 +750,8 @@ async function runTestContext(argv = process.argv.slice(2)) {
|
|
|
703
750
|
}
|
|
704
751
|
const modeArg = parsed.mode ?? "--all";
|
|
705
752
|
const mode = modeArg === "--related" ? "related" : modeArg === "--tests" ? "tests" : "all";
|
|
706
|
-
const
|
|
707
|
-
if (
|
|
753
|
+
const showBanner = shouldShowUI(exportFormat, noBanner);
|
|
754
|
+
if (showBanner) {
|
|
708
755
|
displayBanner({
|
|
709
756
|
text: "JEST",
|
|
710
757
|
subtitle: "TEST",
|
|
@@ -720,28 +767,22 @@ async function runTestContext(argv = process.argv.slice(2)) {
|
|
|
720
767
|
} catch (error) {
|
|
721
768
|
exitWithError(error.message);
|
|
722
769
|
}
|
|
723
|
-
const spinner =
|
|
724
|
-
spinner
|
|
770
|
+
const spinner = createSpinner("Running Jest tests...");
|
|
771
|
+
spinner.start();
|
|
725
772
|
const result = await runJest(jestArgs, {
|
|
726
773
|
verbose: true,
|
|
727
774
|
ignoreErrors: true
|
|
728
775
|
});
|
|
729
776
|
const output = stripAnsi(result.output);
|
|
730
777
|
const hadFailures = output.includes("FAIL") || output.includes("\u25CF");
|
|
731
|
-
if (
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
spinner.succeed("All tests passed!");
|
|
736
|
-
}
|
|
778
|
+
if (hadFailures) {
|
|
779
|
+
spinner.warn("Tests completed with failures");
|
|
780
|
+
} else {
|
|
781
|
+
spinner.succeed("All tests passed!");
|
|
737
782
|
}
|
|
738
783
|
if (!hadFailures) {
|
|
739
784
|
const passMessage = "All tests passed!";
|
|
740
|
-
|
|
741
|
-
exportFormat,
|
|
742
|
-
prefix: "export-test-context",
|
|
743
|
-
title: "Test Context"
|
|
744
|
-
});
|
|
785
|
+
outputTestContext(passMessage, { exportFormat });
|
|
745
786
|
return;
|
|
746
787
|
}
|
|
747
788
|
const failures = extractFailures(output);
|
|
@@ -759,11 +800,7 @@ async function runTestContext(argv = process.argv.slice(2)) {
|
|
|
759
800
|
lines.push("");
|
|
760
801
|
}
|
|
761
802
|
lines.push("=== LLM TEST CONTEXT END ===");
|
|
762
|
-
|
|
763
|
-
exportFormat,
|
|
764
|
-
prefix: "export-test-context",
|
|
765
|
-
title: "Test Context"
|
|
766
|
-
});
|
|
803
|
+
outputTestContext(lines.join("\n"), { exportFormat });
|
|
767
804
|
}
|
|
768
805
|
|
|
769
806
|
// src/commands/coverage-context.ts
|
|
@@ -838,6 +875,25 @@ function formatCoverageOutput(grouped) {
|
|
|
838
875
|
}
|
|
839
876
|
return output.trim();
|
|
840
877
|
}
|
|
878
|
+
function outputCoverageContext(content, options) {
|
|
879
|
+
const { exportFormat } = options;
|
|
880
|
+
if (!exportFormat) {
|
|
881
|
+
handleExportOrDisplay(content, {
|
|
882
|
+
exportFormat,
|
|
883
|
+
prefix: "export-coverage-context",
|
|
884
|
+
title: "Coverage Context"
|
|
885
|
+
});
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
const exportSpinner = createSpinner("Exporting coverage context...", "magenta");
|
|
889
|
+
exportSpinner.start();
|
|
890
|
+
handleExportOrDisplay(content, {
|
|
891
|
+
exportFormat,
|
|
892
|
+
prefix: "export-coverage-context",
|
|
893
|
+
title: "Coverage Context"
|
|
894
|
+
});
|
|
895
|
+
exportSpinner.succeed("Coverage context exported");
|
|
896
|
+
}
|
|
841
897
|
async function runCoverageContext(argv = process.argv.slice(2)) {
|
|
842
898
|
if (argv.includes("-h") || argv.includes("--help")) {
|
|
843
899
|
displayHelp("Coverage Context Script", {
|
|
@@ -868,8 +924,8 @@ async function runCoverageContext(argv = process.argv.slice(2)) {
|
|
|
868
924
|
logWarning(`Unknown arguments ignored: ${filteredUnknownArgs.join(", ")}`);
|
|
869
925
|
}
|
|
870
926
|
const threshold = parsed.threshold ? Number(parsed.threshold) : 100;
|
|
871
|
-
const
|
|
872
|
-
if (
|
|
927
|
+
const showBanner = shouldShowUI(exportFormat, noBanner);
|
|
928
|
+
if (showBanner) {
|
|
873
929
|
displayBanner({
|
|
874
930
|
text: "JEST",
|
|
875
931
|
subtitle: "COVERAGE",
|
|
@@ -879,8 +935,8 @@ async function runCoverageContext(argv = process.argv.slice(2)) {
|
|
|
879
935
|
colors: ["magenta", "blue"]
|
|
880
936
|
});
|
|
881
937
|
}
|
|
882
|
-
const spinner =
|
|
883
|
-
spinner
|
|
938
|
+
const spinner = createSpinner("Running Jest coverage...", "magenta");
|
|
939
|
+
spinner.start();
|
|
884
940
|
const result = await runJest([], {
|
|
885
941
|
coverage: true,
|
|
886
942
|
coverageReporters: ["text", "text-summary"],
|
|
@@ -888,32 +944,20 @@ async function runCoverageContext(argv = process.argv.slice(2)) {
|
|
|
888
944
|
});
|
|
889
945
|
const rows = parseCoverage(result.output);
|
|
890
946
|
if (rows.length === 0) {
|
|
891
|
-
spinner
|
|
892
|
-
|
|
893
|
-
exportFormat,
|
|
894
|
-
prefix: "export-coverage-context",
|
|
895
|
-
title: "Coverage Context"
|
|
896
|
-
});
|
|
947
|
+
spinner.warn("No coverage rows parsed");
|
|
948
|
+
outputCoverageContext("No coverage rows parsed from Jest output.", { exportFormat });
|
|
897
949
|
return;
|
|
898
950
|
}
|
|
899
951
|
const incomplete = filterIncomplete(rows, threshold);
|
|
900
952
|
const grouped = groupByFolder(incomplete);
|
|
901
953
|
if (Object.keys(grouped).length === 0) {
|
|
902
|
-
spinner
|
|
903
|
-
|
|
904
|
-
exportFormat,
|
|
905
|
-
prefix: "export-coverage-context",
|
|
906
|
-
title: "Coverage Context"
|
|
907
|
-
});
|
|
954
|
+
spinner.succeed(`All files meet threshold >= ${threshold}%`);
|
|
955
|
+
outputCoverageContext(`All files meet threshold >= ${threshold}%`, { exportFormat });
|
|
908
956
|
return;
|
|
909
957
|
}
|
|
910
958
|
const formatted = formatCoverageOutput(grouped);
|
|
911
|
-
spinner
|
|
912
|
-
|
|
913
|
-
exportFormat,
|
|
914
|
-
prefix: "export-coverage-context",
|
|
915
|
-
title: "Coverage Context"
|
|
916
|
-
});
|
|
959
|
+
spinner.warn(`Found ${incomplete.length} file(s) below threshold`);
|
|
960
|
+
outputCoverageContext(formatted, { exportFormat });
|
|
917
961
|
}
|
|
918
962
|
|
|
919
963
|
// src/commands/console-context.ts
|
|
@@ -1049,6 +1093,25 @@ function calculateStatistics(warnings) {
|
|
|
1049
1093
|
}
|
|
1050
1094
|
return stats;
|
|
1051
1095
|
}
|
|
1096
|
+
function outputConsoleContext(content, options) {
|
|
1097
|
+
const { exportFormat } = options;
|
|
1098
|
+
if (!exportFormat) {
|
|
1099
|
+
handleExportOrDisplay(content, {
|
|
1100
|
+
exportFormat,
|
|
1101
|
+
prefix: "export-console-context",
|
|
1102
|
+
title: "Console Warnings Context"
|
|
1103
|
+
});
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
const exportSpinner = createSpinner("Exporting console context...", "yellow");
|
|
1107
|
+
exportSpinner.start();
|
|
1108
|
+
handleExportOrDisplay(content, {
|
|
1109
|
+
exportFormat,
|
|
1110
|
+
prefix: "export-console-context",
|
|
1111
|
+
title: "Console Warnings Context"
|
|
1112
|
+
});
|
|
1113
|
+
exportSpinner.succeed("Console context exported");
|
|
1114
|
+
}
|
|
1052
1115
|
async function runConsoleContext(argv = process.argv.slice(2)) {
|
|
1053
1116
|
if (argv.includes("-h") || argv.includes("--help")) {
|
|
1054
1117
|
displayHelp("Console Context Script", {
|
|
@@ -1096,8 +1159,8 @@ async function runConsoleContext(argv = process.argv.slice(2)) {
|
|
|
1096
1159
|
}
|
|
1097
1160
|
const mode = parsed.mode ?? "--all";
|
|
1098
1161
|
const filter = parsed.filter === "--only-errors" ? "errors" : parsed.filter === "--only-warns" ? "warns" : null;
|
|
1099
|
-
const
|
|
1100
|
-
if (
|
|
1162
|
+
const showBanner = shouldShowUI(exportFormat, noBanner);
|
|
1163
|
+
if (showBanner) {
|
|
1101
1164
|
displayBanner({
|
|
1102
1165
|
text: "JEST",
|
|
1103
1166
|
subtitle: "CONSOLE",
|
|
@@ -1115,30 +1178,24 @@ async function runConsoleContext(argv = process.argv.slice(2)) {
|
|
|
1115
1178
|
} catch (error) {
|
|
1116
1179
|
exitWithError(error.message);
|
|
1117
1180
|
}
|
|
1118
|
-
const spinner =
|
|
1119
|
-
spinner
|
|
1181
|
+
const spinner = createSpinner("Capturing console warnings...", "yellow");
|
|
1182
|
+
spinner.start();
|
|
1120
1183
|
const result = await runJest(jestArgs, {
|
|
1121
1184
|
disableVerbose: true,
|
|
1122
1185
|
ignoreErrors: true
|
|
1123
1186
|
});
|
|
1124
1187
|
let warnings = parseConsoleWarnings(result.output);
|
|
1125
1188
|
warnings = filterWarningsByType(warnings, filter);
|
|
1126
|
-
if (
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
spinner.succeed("No console warnings found");
|
|
1131
|
-
}
|
|
1189
|
+
if (warnings.length > 0) {
|
|
1190
|
+
spinner.warn(`Found ${warnings.length} warning(s)`);
|
|
1191
|
+
} else {
|
|
1192
|
+
spinner.succeed("No console warnings found");
|
|
1132
1193
|
}
|
|
1133
1194
|
const grouped = groupByTestFile(warnings);
|
|
1134
1195
|
const stats = calculateStatistics(warnings);
|
|
1135
1196
|
const timestamp = getDisplayTimestamp();
|
|
1136
1197
|
const formatted = formatWarningsOutput(grouped, timestamp, stats);
|
|
1137
|
-
|
|
1138
|
-
exportFormat,
|
|
1139
|
-
prefix: "export-console-context",
|
|
1140
|
-
title: "Console Warnings Context"
|
|
1141
|
-
});
|
|
1198
|
+
outputConsoleContext(formatted, { exportFormat });
|
|
1142
1199
|
}
|
|
1143
1200
|
|
|
1144
1201
|
// src/commands/init-context-scripts.ts
|