Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/utils/src/lib/text-formats/ascii/link.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ansis from 'ansis';

export function formatAsciiLink(url: string): string {
return ansis.underline.blueBright(url);
// no underline because terminals recognize URLs, and nested ansis styles aren't handled by wrap-ansi
return ansis.blueBright(url);
}
3 changes: 3 additions & 0 deletions packages/utils/src/lib/text-formats/ascii/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ function wrapText(text: string, width: number | undefined): string {
if (!width || getTextWidth(text) <= width) {
return text;
}
if (text !== ansis.strip(text)) {
return wrapAnsi(text, width, { hard: true });
}
const words = extractWords(text);
const longWords = words.filter(word => word.length > width);
const replacements = longWords.map(original => {
Expand Down
63 changes: 63 additions & 0 deletions packages/utils/src/lib/text-formats/ascii/table.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import ansis from 'ansis';
import { formatAsciiTable } from './table.js';

describe('formatAsciiTable', () => {

Check failure on line 4 in packages/utils/src/lib/text-formats/ascii/table.unit.test.ts

View workflow job for this annotation

GitHub Actions / Standalone mode

<✓> TypeScript | Semantic errors

TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
it('should format table with primitive rows and no header', () => {

Check failure on line 5 in packages/utils/src/lib/text-formats/ascii/table.unit.test.ts

View workflow job for this annotation

GitHub Actions / Standalone mode

<✓> TypeScript | Semantic errors

TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
const output = formatAsciiTable({
rows: [
['x', '0'],
['y', '0'],
],
});
expect(ansis.strip(output)).toBe(

Check failure on line 12 in packages/utils/src/lib/text-formats/ascii/table.unit.test.ts

View workflow job for this annotation

GitHub Actions / Standalone mode

<✓> TypeScript | Semantic errors

TS2304: Cannot find name 'expect'.
`
┌───┬───┐
│ x │ 0 │
Expand All @@ -19,7 +19,7 @@
);
});

it('should format table with objects rows and column headers', () => {

Check failure on line 22 in packages/utils/src/lib/text-formats/ascii/table.unit.test.ts

View workflow job for this annotation

GitHub Actions / Standalone mode

<✓> TypeScript | Semantic errors

TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
const output = formatAsciiTable({
columns: [
{ key: 'x', label: 'X' },
Expand All @@ -32,7 +32,7 @@
{ x: 2, y: 1 },
],
});
expect(ansis.strip(output)).toBe(

Check failure on line 35 in packages/utils/src/lib/text-formats/ascii/table.unit.test.ts

View workflow job for this annotation

GitHub Actions / Standalone mode

<✓> TypeScript | Semantic errors

TS2304: Cannot find name 'expect'.
`
┌───┬───┐
│ X │ Y │
Expand All @@ -46,11 +46,11 @@
);
});

it('should support various primitive cell values', () => {

Check failure on line 49 in packages/utils/src/lib/text-formats/ascii/table.unit.test.ts

View workflow job for this annotation

GitHub Actions / Standalone mode

<✓> TypeScript | Semantic errors

TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
const output = formatAsciiTable({
rows: [['foo', 42, true, null]],
});
expect(ansis.strip(output)).toBe(

Check failure on line 53 in packages/utils/src/lib/text-formats/ascii/table.unit.test.ts

View workflow job for this annotation

GitHub Actions / Standalone mode

<✓> TypeScript | Semantic errors

TS2304: Cannot find name 'expect'.
`
┌─────┬────┬──────┬──┐
│ foo │ 42 │ true │ │
Expand All @@ -59,7 +59,7 @@
);
});

it('should align columns', () => {

Check failure on line 62 in packages/utils/src/lib/text-formats/ascii/table.unit.test.ts

View workflow job for this annotation

GitHub Actions / Standalone mode

<✓> TypeScript | Semantic errors

TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
const output = formatAsciiTable({
columns: [
{ key: 'property', label: 'Property', align: 'left' },
Expand All @@ -74,7 +74,7 @@
{ property: 'proj4', required: false, default: 'EPSG:3857' },
],
});
expect(ansis.strip(output)).toBe(

Check failure on line 77 in packages/utils/src/lib/text-formats/ascii/table.unit.test.ts

View workflow job for this annotation

GitHub Actions / Standalone mode

<✓> TypeScript | Semantic errors

TS2304: Cannot find name 'expect'.
`
┌───────────┬──────────┬───────────┐
│ Property │ Required │ Default │
Expand All @@ -89,7 +89,7 @@
);
});

it('should align columns without header', () => {

Check failure on line 92 in packages/utils/src/lib/text-formats/ascii/table.unit.test.ts

View workflow job for this annotation

GitHub Actions / Standalone mode

<✓> TypeScript | Semantic errors

TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
const output = formatAsciiTable({
columns: ['left', 'center', 'right'],
rows: [
Expand Down Expand Up @@ -453,6 +453,69 @@
├──────────┼────────────┼─────────┼────────────┼──────────┼─────────┼──────────┤
│ 81 │ 64 │ 92 │ 100 │ 95 │ 62 │ 6 │
└──────────┴────────────┴─────────┴────────────┴──────────┴─────────┴──────────┘
`.trim(),
);
});

it('should wrap ansi styles correctly', () => {
const output = formatAsciiTable(
{
rows: [
[''],
[ansis.bold('💡 Integrate the Portal')],
[''],
[`${ansis.gray('❯')} Configure upload in code-pushup.config.ts`],
[
ansis.underline(
'https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#portal-integration',
),
],
[
`${ansis.gray('❯')} npx code-pushup upload${ansis.gray(' - Upload previously collected report to the Portal')}`,
],
[
ansis.underline(
'https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command',
),
],
[''],
],
},
{ padding: 4 },
);

expect(ansis.strip(output)).toBe(
`
┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ 💡 Integrate the Portal │
│ │
│ ❯ Configure upload in code-pushup.config.ts │
│ https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#po │
│ rtal-integration │
│ ❯ npx code-pushup upload - Upload previously collected report to the │
│ Portal │
│ https://github.com/code-pushup/cli/tree/main/packages/cli#upload-comma │
│ nd │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
`.trim(),
);
expect(output).toBe(
`
${ansis.dim('┌──────────────────────────────────────────────────────────────────────────────┐')}
${ansis.dim('│')} ${ansis.dim('│')}
${ansis.dim('│')} ${ansis.bold('💡 Integrate the Portal')} ${ansis.dim('│')}
${ansis.dim('│')} ${ansis.dim('│')}
${ansis.dim('│')} ${ansis.gray('❯')} Configure upload in code-pushup.config.ts ${ansis.dim('│')}
${ansis.dim('│')} ${ansis.underline('https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#po')} ${ansis.dim('│')}
${ansis.dim('│')} ${ansis.underline('rtal-integration')} ${ansis.dim('│')}
${ansis.dim('│')} ${ansis.gray('❯')} npx code-pushup upload${ansis.gray(' - Upload previously collected report to the')} ${ansis.dim('│')}
${ansis.dim('│')} ${ansis.gray('Portal')} ${ansis.dim('│')}
${ansis.dim('│')} ${ansis.underline('https://github.com/code-pushup/cli/tree/main/packages/cli#upload-comma')} ${ansis.dim('│')}
${ansis.dim('│')} ${ansis.underline('nd')} ${ansis.dim('│')}
${ansis.dim('│')} ${ansis.dim('│')}
${ansis.dim('└──────────────────────────────────────────────────────────────────────────────┘')}
`.trim(),
);
});
Expand Down