Skip to content

Commit

Permalink
Fix: reset to the default color (#12174)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza authored and btmills committed Aug 30, 2019
1 parent 4009d39 commit aab1b84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/cli-engine/formatters/stylish.js
Expand Up @@ -96,5 +96,6 @@ module.exports = function(results) {
}
}

return total > 0 ? output : "";
// Resets output color, for prevent change on top level
return total > 0 ? chalk.reset(output) : "";
};
20 changes: 20 additions & 0 deletions tests/lib/cli-engine/formatters/stylish.js
Expand Up @@ -19,6 +19,12 @@ const assert = require("chai").assert,
* for Sinon to work.
*/
const chalkStub = Object.create(chalk, {
reset: {
value(str) {
return chalk.reset(str);
},
writable: true
},
yellow: {
value(str) {
return chalk.yellow(str);
Expand Down Expand Up @@ -47,6 +53,7 @@ describe("formatter:stylish", () => {

beforeEach(() => {
chalk.enabled = false;
sinon.spy(chalkStub, "reset");
sinon.spy(chalkStub.yellow, "bold");
sinon.spy(chalkStub.red, "bold");
});
Expand All @@ -68,6 +75,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "");
assert.strictEqual(chalkStub.reset.callCount, 0);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 0);
});
Expand All @@ -93,8 +101,10 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\n\u2716 1 problem (1 error, 0 warnings)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);

});

describe("when the error is fixable", () => {
Expand All @@ -106,6 +116,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\n\u2716 1 problem (1 error, 0 warnings)\n 1 error and 0 warnings potentially fixable with the `--fix` option.\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 2);
});
Expand All @@ -132,6 +143,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 warning Unexpected foo foo\n\n\u2716 1 problem (0 errors, 1 warning)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 1);
assert.strictEqual(chalkStub.red.bold.callCount, 0);
});
Expand All @@ -145,6 +157,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 warning Unexpected foo foo\n\n\u2716 1 problem (0 errors, 1 warning)\n 0 errors and 1 warning potentially fixable with the `--fix` option.\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 2);
assert.strictEqual(chalkStub.red.bold.callCount, 0);
});
Expand Down Expand Up @@ -172,6 +185,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 warning Unexpected . foo\n\n\u2716 1 problem (0 errors, 1 warning)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 1);
assert.strictEqual(chalkStub.red.bold.callCount, 0);
});
Expand All @@ -195,6 +209,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\n\u2716 1 problem (1 error, 0 warnings)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand Down Expand Up @@ -224,6 +239,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n 6:11 warning Unexpected bar bar\n\n\u2716 2 problems (1 error, 1 warning)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand Down Expand Up @@ -258,6 +274,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\nbar.js\n 6:11 warning Unexpected bar bar\n\n\u2716 2 problems (1 error, 1 warning)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand All @@ -271,6 +288,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\nbar.js\n 6:11 warning Unexpected bar bar\n\n\u2716 2 problems (2 errors, 0 warnings)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand All @@ -284,6 +302,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 5:10 error Unexpected foo foo\n\nbar.js\n 6:11 warning Unexpected bar bar\n\n\u2716 2 problems (0 errors, 2 warnings)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand All @@ -304,6 +323,7 @@ describe("formatter:stylish", () => {
const result = formatter(code);

assert.strictEqual(result, "\nfoo.js\n 0:0 error Couldn't find foo.js\n\n\u2716 1 problem (1 error, 0 warnings)\n");
assert.strictEqual(chalkStub.reset.callCount, 1);
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
assert.strictEqual(chalkStub.red.bold.callCount, 1);
});
Expand Down

0 comments on commit aab1b84

Please sign in to comment.