Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use supports-color module to test if system supports colors
This fixes #1574
- Loading branch information
Showing
4 changed files
with
132 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"use strict"; | ||
|
||
var assert = require("referee").assert; | ||
var proxyquire = require("proxyquire"); | ||
|
||
function getColorMethods() { | ||
return [{ | ||
name: "red", | ||
code: 31 | ||
}, { | ||
name: "green", | ||
code: 32 | ||
}]; | ||
} | ||
|
||
describe("color", function () { | ||
describe("when environment supports color", function () { | ||
var color; | ||
|
||
beforeEach(function () { | ||
color = proxyquire("../../../lib/sinon/color", { | ||
"supports-color": {} | ||
}); | ||
}); | ||
|
||
getColorMethods().forEach(function (method) { | ||
describe(method.name, function () { | ||
it("should return a colored string", function () { | ||
var string = "lorem ipsum"; | ||
var actual = color[method.name](string); | ||
|
||
assert.isTrue(actual.indexOf(method.code + "m" + string) !== -1); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("when environment does not support color", function () { | ||
var color; | ||
|
||
beforeEach(function () { | ||
color = proxyquire("../../../lib/sinon/color", { | ||
"supports-color": false | ||
}); | ||
}); | ||
|
||
getColorMethods().forEach(function (method) { | ||
describe(method.name, function () { | ||
it("should return a colored string", function () { | ||
var string = "lorem ipsum"; | ||
var actual = color[method.name](string); | ||
|
||
assert.equals(actual, string); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |