Skip to content

Commit 733de7b

Browse files
committed
fix(utils): replace \n to NEW_LINE
1 parent 493946b commit 733de7b

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

packages/core/src/lib/implementation/persist.spec.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import {
1313
CODE_PUSHUP_DOMAIN,
1414
FOOTER_PREFIX,
15+
NEW_LINE,
1516
README_LINK,
1617
} from '@code-pushup/utils';
1718
import { mockConsole, unmockConsole } from '../../../test';
@@ -76,7 +77,9 @@ describe('persistReport', () => {
7677

7778
it('should stdout as format by default`', async () => {
7879
await persistReport(dummyReport, dummyConfig);
79-
expect(logs.join('\n')).toContain(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
80+
expect(logs.join(NEW_LINE)).toContain(
81+
`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`,
82+
);
8083

8184
expect(() => readReport('json')).not.toThrow();
8285
expect(() => readReport('md')).toThrow('no such file or directory');
@@ -89,7 +92,9 @@ describe('persistReport', () => {
8992
...dummyConfig,
9093
persist,
9194
});
92-
expect(logs.join('\n')).toContain(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
95+
expect(logs.join(NEW_LINE)).toContain(
96+
`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`,
97+
);
9398

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

146-
expect(logs.join('\n')).toContain(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
151+
expect(logs.join(NEW_LINE)).toContain(
152+
`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`,
153+
);
147154
});
148155

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

165-
expect(logs.join('\n')).toMatch(`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`);
172+
expect(logs.join(NEW_LINE)).toMatch(
173+
`${FOOTER_PREFIX} ${CODE_PUSHUP_DOMAIN}`,
174+
);
166175
});
167176

168177
// @TODO: should throw PersistDirError

packages/utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ export {
4242
distinct,
4343
slugify,
4444
} from './lib/transformation';
45+
export { NEW_LINE } from './lib/md';

packages/utils/src/lib/report-to-stdout.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { scoreReport } from './scoring';
66
describe('report-to-stdout', () => {
77
it('should contain all sections when using the fixture report', () => {
88
const logOutput = reportToStdout(scoreReport(report()));
9+
// logOutput.replace(/\u001B\[\d+m/g, '') removes all color codes from the output
10+
// for snapshot readability
911
// eslint-disable-next-line no-control-regex
1012
expect(logOutput.replace(/\u001B\[\d+m/g, '')).toMatchSnapshot();
1113
});

packages/utils/src/lib/report-to-stdout.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import chalk from 'chalk';
22
import Table from 'cli-table3';
33
import cliui from 'cliui';
4+
import { NEW_LINE } from './md';
45
import {
56
CODE_PUSHUP_DOMAIN,
67
FOOTER_PREFIX,
@@ -12,7 +13,7 @@ import {
1213
import { ScoredReport } from './scoring';
1314

1415
function addLine(line = ''): string {
15-
return line + '\n';
16+
return line + NEW_LINE;
1617
}
1718

1819
export function reportToStdout(report: ScoredReport): string {

0 commit comments

Comments
 (0)