diff --git a/bin/cli.js b/bin/cli.js index 9260c9b..d7145b4 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -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(); diff --git a/src/cli/gui.js b/src/cli/gui.js index 0ae1617..2c21d63 100644 --- a/src/cli/gui.js +++ b/src/cli/gui.js @@ -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()); @@ -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); } @@ -107,6 +110,7 @@ export default class GUI { if (this.$summary) { outp.push('', this.$titles.summary, this.$summary); } + if (outp[0] === '') { outp.shift(); } @@ -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()); } diff --git a/test/cli.spec.js b/test/cli.spec.js index 564097c..6976e36 100644 --- a/test/cli.spec.js +++ b/test/cli.spec.js @@ -144,3 +144,20 @@ describe('Configuration files', function () { expect(stdout).not.toMatch('Failed to lint'); }); }); + +describe('--no-summary', function () { + it('should not print summary with valid SVG', async function () { + const {stdout} = await execCli([VALID_SVG, '--no-summary']); + expect(stdout).toMatch('Summary'); + }); + + 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'); + }); +});