Skip to content

Commit

Permalink
fix(utils): replace \n to NEW_LINE
Browse files Browse the repository at this point in the history
  • Loading branch information
IKatsuba committed Nov 13, 2023
1 parent 493946b commit 733de7b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
17 changes: 13 additions & 4 deletions packages/core/src/lib/implementation/persist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {
CODE_PUSHUP_DOMAIN,
FOOTER_PREFIX,
NEW_LINE,
README_LINK,
} from '@code-pushup/utils';
import { mockConsole, unmockConsole } from '../../../test';
Expand Down Expand Up @@ -76,7 +77,9 @@ describe('persistReport', () => {

it('should stdout as format by default`', async () => {
await persistReport(dummyReport, dummyConfig);
expect(logs.join('\n')).toContain(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
expect(logs.join(NEW_LINE)).toContain(
`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`,
);

expect(() => readReport('json')).not.toThrow();
expect(() => readReport('md')).toThrow('no such file or directory');
Expand All @@ -89,7 +92,9 @@ describe('persistReport', () => {
...dummyConfig,
persist,
});
expect(logs.join('\n')).toContain(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
expect(logs.join(NEW_LINE)).toContain(
`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`,
);

expect(() => readReport('json')).not.toThrow('no such file or directory');
expect(() => readReport('md')).toThrow('no such file or directory');
Expand Down Expand Up @@ -143,7 +148,9 @@ describe('persistReport', () => {
`${FOOTER_PREFIX} [Code PushUp](${README_LINK})`,
);

expect(logs.join('\n')).toContain(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
expect(logs.join(NEW_LINE)).toContain(
`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`,
);
});

it('should persist some formats`', async () => {
Expand All @@ -162,7 +169,9 @@ describe('persistReport', () => {
`${FOOTER_PREFIX} [Code PushUp](${README_LINK})`,
);

expect(logs.join('\n')).toMatch(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
expect(logs.join(NEW_LINE)).toMatch(
`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`,
);
});

// @TODO: should throw PersistDirError
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ export {
distinct,
slugify,
} from './lib/transformation';
export { NEW_LINE } from './lib/md';
2 changes: 2 additions & 0 deletions packages/utils/src/lib/report-to-stdout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { scoreReport } from './scoring';
describe('report-to-stdout', () => {
it('should contain all sections when using the fixture report', () => {
const logOutput = reportToStdout(scoreReport(report()));
// logOutput.replace(/\u001B\[\d+m/g, '') removes all color codes from the output
// for snapshot readability
// eslint-disable-next-line no-control-regex
expect(logOutput.replace(/\u001B\[\d+m/g, '')).toMatchSnapshot();
});
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/lib/report-to-stdout.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chalk from 'chalk';
import Table from 'cli-table3';
import cliui from 'cliui';
import { NEW_LINE } from './md';
import {
CODE_PUSHUP_DOMAIN,
FOOTER_PREFIX,
Expand All @@ -12,7 +13,7 @@ import {
import { ScoredReport } from './scoring';

function addLine(line = ''): string {
return line + '\n';
return line + NEW_LINE;
}

export function reportToStdout(report: ScoredReport): string {
Expand Down

0 comments on commit 733de7b

Please sign in to comment.