Fix double spacers in diagnostics
MODIFY
packages/@romejs/cli-diagnostics/DiagnosticsPrinter.ts
packages/@romejs/cli-diagnostics/DiagnosticsPrinter.ts
@@ -388,11 +388,11 @@ export default class DiagnosticsPrinter extends Error {
}
displayDiagnostics(diagnostics: Diagnostics) {
- this.reporter.redirectOutToErr(true);
+ const restoreRedirect = this.reporter.redirectOutToErr(true);
for (const diag of diagnostics) {
this.displayDiagnostic(diag);
}
- this.reporter.redirectOutToErr(false);
+ this.reporter.redirectOutToErr(restoreRedirect);
}
displayDiagnostic(diag: Diagnostic) {
@@ -401,9 +401,7 @@ export default class DiagnosticsPrinter extends Error {
const {advice} = diag.description;
// Determine if we should skip showing the frame at the top of the diagnostic output
-
// We check if there are any frame advice entries that match us exactly, this is
-
// useful for stuff like reporting call stacks
let skipFrame = false;
if (start !== undefined && end !== undefined && advice !== undefined) {
@@ -519,7 +517,7 @@ export default class DiagnosticsPrinter extends Error {
if (origins !== undefined && origins.length > 0) {
reporter.spacer();
reporter.info('Why are you seeing this diagnostic?');
- reporter.forceSpacer();
+ reporter.spacer();
reporter.list(
origins.map((origin) => {
let res = `<emphasis>${origin.category}</emphasis>`;
@@ -565,7 +563,9 @@ export default class DiagnosticsPrinter extends Error {
const isError = problemCount > 0;
if (isError) {
+ const restoreRedirect = reporter.redirectOutToErr(true);
reporter.hr();
+ reporter.redirectOutToErr(restoreRedirect);
}
if (this.hasTruncatedDiagnostics) {

MODIFY
packages/@romejs/cli-reporter/Reporter.ts
packages/@romejs/cli-reporter/Reporter.ts
@@ -113,7 +113,7 @@ export default class Reporter {
this.enabled = opts.disabled === true ? 0 : 1;
this.markupOptions =
opts.markupOptions === undefined ? {} : opts.markupOptions;
- this.hasSpacer = false;
+ this.streamHasSpacer = new Set();
this.shouldRedirectOutToErr = false;
this.stdin = opts.stdin;
@@ -254,7 +254,7 @@ export default class Reporter {
isRemote: boolean;
noProgress: boolean;
isVerbose: boolean;
- hasSpacer: boolean;
+ streamHasSpacer: Set<ReporterStream>;
indentLevel: number;
indentString: string;
enabled: number;
@@ -351,14 +351,13 @@ export default class Reporter {
msg = indentString + msg.replace(/\n([^\n])/g, `\n${indentString}$1`);
}
- // Track if there's going to be a completely empty line
- this.hasSpacer = msg === '' || msg[msg.length - 1] === '\n';
-
return msg;
}
- redirectOutToErr(should: boolean) {
+ redirectOutToErr(should: boolean): boolean {
+ const old = this.shouldRedirectOutToErr;
this.shouldRedirectOutToErr = should;
+ return old;
}
setStreamColumns(streams: Array<ReporterStream>, columns: number) {
@@ -851,8 +850,10 @@ export default class Reporter {
}
spacer() {
- if (!this.hasSpacer) {
- this.forceSpacer();
+ for (const stream of this.getStreams(false)) {
+ if (!this.streamHasSpacer.has(stream)) {
+ this.logOne(stream, '');
+ }
}
}
@@ -928,6 +929,15 @@ export default class Reporter {
if (opts.newline !== false) {
msg += '\n';
}
+
+ // Track if there's going to be a completely empty line
+ const hasSpacer = msg === '\n' || msg.endsWith('\n\n');
+ if (hasSpacer) {
+ this.streamHasSpacer.add(stream);
+ } else {
+ this.streamHasSpacer.delete(stream);
+ }
+
this.writeSpecific(stream, msg, opts);
}

MODIFY
packages/@romejs/core/test-worker/TestWorkerRunner.ts
packages/@romejs/core/test-worker/TestWorkerRunner.ts
@@ -10,7 +10,6 @@ import {
Diagnostic,
DiagnosticAdvice,
DiagnosticLogCategory,
- Diagnostics,
INTERNAL_ERROR_LOG_ADVICE,
catchDiagnostics,
createBlessedDiagnosticMessage,
@@ -39,11 +38,8 @@ import {
import {AbsoluteFilePath, createAbsoluteFilePath} from '@romejs/path';
import {escapeMarkup, markup} from '@romejs/string-markup';
import util = require('util');
-import {
- ErrorFrames,
- getErrorStructure,
- getSourceLocationFromErrorFrame,
-} from '@romejs/v8';
+import {ErrorFrames, getErrorStructure} from '@romejs/v8';
+
const MAX_RUNNING_TESTS = 20;
function cleanFrames(frames: ErrorFrames): ErrorFrames {

MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -697,7 +697,7 @@ export const descriptions = createMessages({
category: 'tests/noneDeclared',
},
LOGS: (advice: DiagnosticAdvice) => ({
- message: 'File produced console logs',
+ message: 'Test file produced console logs',
category: 'tests/logs',
advice: [
...advice,

MODIFY
packages/@romejs/string-markup/formatAnsi.ts
packages/@romejs/string-markup/formatAnsi.ts
@@ -28,6 +28,10 @@ export function markupToAnsi(
ancestry: [],
formatTag: ansiFormatTag,
formatText: (value, tags) => {
+ if (tags.length === 0) {
+ return value;
+ }
+
// Format tags in reverse
for (let i = tags.length - 1; i >= 0; i--) {
const tag = tags[i];

Fix double spacers in diagnostics