Skip to content

Commit a9c6b7a

Browse files
committedDec 16, 2018
Explicitly test for color output on supporting consoles.
Coverage should not be dependent on the build environment's console, and Travis CI seems to set process.stdout.isTTY to false on its Windows environment.
1 parent 3a2486e commit a9c6b7a

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed
 

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
"lab": "./bin/lab"
3939
},
4040
"scripts": {
41-
"test": "node ./bin/_lab -fL -t 100 -m 3000",
41+
"test": "node ./bin/_lab -fL -t 100 -m 10000",
4242
"posttest": "npm run lint-md",
43-
"test-cov-html": "node ./bin/_lab -fL -r html -m 3000 -o coverage.html",
43+
"test-cov-html": "node ./bin/_lab -fL -r html -m 10000 -o coverage.html",
4444
"lint": "node ./bin/_lab -d -f -L",
4545
"lint-md": "eslint --config hapi --rule \"strict: 0, eol-last: 0\" --plugin markdown --ext md --parser-options \"ecmaVersion: 9\" ."
4646
},

‎test/reporters.js

+33
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,39 @@ describe('Reporter', () => {
999999
expect(output).to.match(/^\n \n \.\n\n1 tests complete\nTest duration: \d+ ms\nNo global variable leaks detected\n\n$/);
10001000
});
10011001

1002+
it('includes colors when terminal supports', async () => {
1003+
1004+
delete require.cache[require.resolve('supports-color')];
1005+
const orig = {
1006+
isTTY: process.stdout.isTTY,
1007+
env: process.env
1008+
};
1009+
process.stdout.isTTY = true;
1010+
process.env = {
1011+
FORCE_COLOR: true
1012+
};
1013+
1014+
const script = Lab.script();
1015+
script.experiment('test', () => {
1016+
1017+
script.test('works', () => {
1018+
1019+
expect(true).to.equal(true);
1020+
});
1021+
script.test('does not work', () => {
1022+
1023+
expect(true).to.equal(false);
1024+
});
1025+
});
1026+
1027+
const { code, output } = await Lab.report(script, { reporter: 'console', output: false, assert: false });
1028+
1029+
process.stdout.isTTY = orig.isTTY;
1030+
process.env = orig.env;
1031+
expect(code).to.equal(1);
1032+
expect(output).to.match(/^\n \n \.\u001b\[31mx\u001b\[0m\n\nFailed tests:\n\n 2\) test does not work:\n\n \u001b\[37;41mactual\u001b\[0m \u001b\[30;42mexpected\u001b\[0m\n\n \u001b\[37;41mtrue\u001b\[0m\u001b\[30;42mfalse\u001b\[0m\n\n \u001b\[33mExpected true to equal specified value: false\u001b\[0m\n\n.*?\u001b\[0m\n\n\n\u001b\[31m1 of 2 tests failed\u001b\[0m\nTest duration: \d+ ms\n\u001b\[32mNo global variable leaks detected\u001b\[0m\n\n$/);
1033+
});
1034+
10021035
it('displays custom error messages in expect', async () => {
10031036

10041037
const script = Lab.script();

0 commit comments

Comments
 (0)
Please sign in to comment.