Skip to content

Commit

Permalink
Format, fix error and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Nov 17, 2024
1 parent a820036 commit 9dffe5c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const cli = meow(
},
);

const gui = new GUI({ printSummary: cli.flags.summary });
const gui = new GUI({printSummary: cli.flags.summary});

process.on('exit', () => {
gui.finish();
Expand Down
15 changes: 11 additions & 4 deletions src/cli/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const logHistory = Logger.cliConsole;
/** @typedef {import("../lib/linting.js")} Linting */

export default class GUI {
constructor({ printSummary = true } = {}) {
constructor({printSummary = true} = {}) {
// Subscribe to global logs
Logger.setCLI(true);
logHistory.on('msg', () => this.update());
Expand All @@ -40,8 +40,11 @@ export default class GUI {
*/
finish() {
if (this.ci) {
// eslint-disable-next-line no-console
console.log(this.render());
const output = this.render();
if (output) {
// eslint-disable-next-line no-console
console.log(output);
}
} else {
this.update(true);
}
Expand Down Expand Up @@ -107,6 +110,7 @@ export default class GUI {
if (this.$summary) {
outp.push('', this.$titles.summary, this.$summary);
}

if (outp[0] === '') {
outp.shift();
}
Expand All @@ -129,7 +133,10 @@ export default class GUI {
*/
addLinting(linting) {
this.$lintings.push(new LintingDisplay(linting));
this.$summary?.addLinting(linting);
if (this.$summary) {
this.$summary.addLinting(linting);
}

linting.on('rule', () => this.update());
linting.on('done', () => this.update());
}
Expand Down
17 changes: 17 additions & 0 deletions test/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,20 @@ describe('Configuration files', function () {
expect(stdout).not.toMatch('Failed to lint');
});
});

describe('--no-summary', function () {
it('should not print nothing with valid SVG', async function () {
const {stdout} = await execCli([VALID_SVG, '--no-summary']);
expect(stdout).toMatch('');
});

it('should print the summary not passing --no-summary', async function () {
const {stdout} = await execCli([VALID_SVG]);
expect(stdout).toMatch('Summary');
});

it('should print errors with invalid SVG', async function () {
const {stdout} = await execCli([INVALID_SVG, '--no-summary']);
expect(stdout).toMatch('Files');
});
});

0 comments on commit 9dffe5c

Please sign in to comment.