Skip to content

Commit

Permalink
supports color tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srsholmes committed Feb 26, 2018
1 parent 99c2f2f commit c04834e
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 22 deletions.
99 changes: 98 additions & 1 deletion __tests__/colors_support.re
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,111 @@ let () =
ExpectJs.(
() => {
test("supportsColors", () =>
expect(supportsColors([1, 2, 3])) |> toBe(3)
expect(findMax([1, 2, 3])) |> toBe(3)
);
test("notFoundString", () =>
expect(notFoundStr) |> toBe("NOT_FOUND")
);
test("safeGetEnv", () =>
expect(safeGetEnv("SOME_RUBBISH_ENV")) |> toBe("NOT_FOUND")
);
test("isColorCompatibleCi returns 1 if TRAVIS CI", () => {
[%raw {| process.env.CI = 'TRAVIS'|}];
expect(isColorCompatibleCi()) |> toBe(1);
});
test("isColorCompatibleCi returns 1 if CIRCLE CI", () => {
[%raw {| process.env.CI = 'CIRCLECI' |}];
expect(isColorCompatibleCi()) |> toBe(1);
});
test("isColorCompatibleCi returns 1 if APPVEYOR CI", () => {
[%raw {| process.env.CI = 'APPVEYOR' |}];
expect(isColorCompatibleCi()) |> toBe(1);
});
test("isColorCompatibleCi returns 1 if GITLAB_CI CI", () => {
[%raw {| process.env.CI = 'GITLAB_CI' |}];
expect(isColorCompatibleCi()) |> toBe(1);
});
test("isColorCompatibleCi returns 1 if codeship CI", () => {
[%raw {| process.env.CI_NAME = 'codeship' |}];
[%raw {| process.env.CI = 'true' |}];
expect(isColorCompatibleCi()) |> toBe(1);
});
test("isTeamCityCompatible returns 0 if old version", () => {
[%raw {| process.env.TEAMCITY_VERSION = '9.0.5 (build 32523)'|}];
expect(isTeamCityCompatible()) |> toBe(0);
});
test("isTeamCityCompatible returns 1 if newer version", () => {
[%raw {| process.env.TEAMCITY_VERSION = '9.1.5 (build 32523)'|}];
expect(isTeamCityCompatible()) |> toBe(1);
});
test("isColorTerm returns 0 if NO COLORTERM", () =>
expect(isColorTerm()) |> toBe(0)
);
test("isColorTerm returns 1 if COLORTERM", () => {
[%raw {| process.env.COLORTERM = 'true'|}];
expect(isColorTerm()) |> toBe(1);
});
test("isBasicTerm returns 0 if NO TERM", () => {
[%raw {| delete process.env.TERM |}];
expect(isBasicTerminal()) |> toBe(0);
});
test("isBasicTerm returns 1 if TERM is recognised terminal", () => {
[%raw {| process.env.TERM = 'xterm'|}];
expect(isBasicTerminal()) |> toBe(1);
});
test("isBasicTerm returns 0 if TERM is not recognised terminal", () => {
[%raw {| process.env.TERM = 'blah'|}];
expect(isBasicTerminal()) |> toBe(0);
});
test("isTerminal256 returns 1 if TERM is recognised terminal", () => {
[%raw {| process.env.TERM = 'blah-256'|}];
expect(isTerminal256()) |> toBe(2);
});
test("isTerminal256 returns 0 if TERM is recognised terminal", () => {
[%raw {| process.env.TERM = 'blah-156'|}];
expect(isTerminal256()) |> toBe(0);
});
test("isTerminal256 returns 0 if NO TERM", () => {
[%raw {| delete process.env.TERM |}];
expect(isTerminal256()) |> toBe(0);
});
test(
"isFancyTerminal returns 3 if TERM_PROGRAM_VERSION is iTerm 3", () => {
[%raw {| delete process.env.TERM_PROGRAM |}];
[%raw {| delete process.env.TERM_PROGRAM_VERSION |}];
[%raw {| process.env.TERM_PROGRAM = 'iTerm.app'|}];
[%raw {| process.env.TERM_PROGRAM_VERSION = '3.1.0'|}];
expect(isFancyTerminal()) |> toBe(3);
});
test(
"isFancyTerminal returns 2 if TERM_PROGRAM_VERSION is iTerm 2", () => {
[%raw {| delete process.env.TERM_PROGRAM |}];
[%raw {| delete process.env.TERM_PROGRAM_VERSION |}];
[%raw {| process.env.TERM_PROGRAM = 'iTerm.app'|}];
[%raw {| process.env.TERM_PROGRAM_VERSION = '2.0.0'|}];
expect(isFancyTerminal()) |> toBe(2);
});
test("isFancyTerminal returns 3 if TERM_PROGRAM_VERSION is Hyper", () => {
[%raw {| delete process.env.TERM_PROGRAM |}];
[%raw {| delete process.env.TERM_PROGRAM_VERSION |}];
[%raw {| process.env.TERM_PROGRAM = 'Hyper'|}];
expect(isFancyTerminal()) |> toBe(3);
});
test("isFancyTerminal returns 0 if TERM is recognised terminal", () => {
[%raw {| delete process.env.TERM_PROGRAM |}];
[%raw {| process.env.TERM_PROGRAM = 'Apple_Terminal'|}];
expect(isFancyTerminal()) |> toBe(2);
});
test("isFancyTerminal returns 2 if NO TERM_PROGRAM_VERSION", () => {
[%raw {| delete process.env.TERM_PROGRAM |}];
[%raw {| process.env.TERM_PROGRAM = 'true'|}];
expect(isFancyTerminal()) |> toBe(0);
});
test("isFancyTerminal returns 0 if NO TERM_PROGRAM", () => {
[%raw {| delete process.env.TERM_PROGRAM |}];
[%raw {| process.env.TERM_PROGRAM = 'true'|}];
expect(isFancyTerminal()) |> toBe(0);
});
}
)
);
14 changes: 14 additions & 0 deletions __tests__/colors_support_ci_travis.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open Jest;

let () =
describe(
"colors.re Colors_Support",
ExpectJs.(
() =>
test("isColorCompatibleCi returns 1 if TRAVIS CI", () => {
[%raw {| process.env={"CI":"TRAVIS"}|}];
[%raw {| console.log(process.env)|}];
Colors_Support.(expect(isColorCompatibleCi()) |> toBe(1));
})
)
);
101 changes: 98 additions & 3 deletions lib/js/__tests__/colors_support.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions lib/js/__tests__/colors_support_ci_travis.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions lib/js/src/Colors_Support.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions src/Colors_Support.re
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ let isTerminal256 = () => {

let isFancyTerminal = () => {
let termEnv = safeGetEnv("TERM_PROGRAM");
Js.log(termEnv);
termEnv !== notFoundStr ?
{
let version =
int_of_string(
Js.String.split(".", safeGetEnv("TERM_PROGRAM_VERSION"))[0]
);
switch termEnv {
| "iTerm.app" => version >= 3 ? 3 : 2
| "Hyper" => 3
| "Apple_Terminal" => 2
| _ => 0
};
/* This will fail in terms without "TERM_PROGRAM_VERSION" */
switch termEnv {
| "iTerm.app" =>
int_of_string(
Js.String.split(".", safeGetEnv("TERM_PROGRAM_VERSION"))[0]
)
>= 3 ?
3 : 2
| "Hyper" => 3
| "Apple_Terminal" => 2
| _ => 0
} :
2;
};
Expand Down Expand Up @@ -85,7 +86,7 @@ let isColorCompatibleCi = () => {
0;
};

let supportsColors = List.fold_left(Pervasives.max, 0);
let findMax = List.fold_left(Pervasives.max, 0);

let detectList = [
isColorCompatibleCi(),
Expand All @@ -96,4 +97,4 @@ let detectList = [
isFancyTerminal()
];

let support = supportsColors(detectList);
let support = findMax(detectList);

0 comments on commit c04834e

Please sign in to comment.