UNPKG

2.25 kBJavaScriptView Raw
1const forEach = require("mocha-each");
2const expect = require("chai").expect;
3
4const print = require("../src/messenger");
5print.initLogger(true, "logs", "test-messenger");
6let { raw } = require("./testUtils");
7
8const icons = print.icons;
9const messageColor = print.messageColors;
10
11let commands = [
12 "critical",
13 "error",
14 "warning",
15 "warn",
16 "important",
17 "info",
18 "note",
19 "notice",
20 "log",
21 "debug",
22 "status",
23 "success"
24];
25
26const commandTest = command => {
27 let message = `${command} class message`;
28 let tests = [
29 [message, "", false, message],
30 [message, command, false, command],
31 [message, command.toUpperCase(), false, command.toUpperCase()],
32 [message, "TEST_LABEL_FG", false, messageColor[command].fg],
33 [message, "TEST_LABEL_BG", false, messageColor[command].bg],
34 [message, "", true, icons[command]]
35 ];
36
37 forEach(tests).it(`.${command}(%s, %s, %s)`, (msg, label, icon, expected) => {
38 // executer command
39 let result = print[command](msg, label, icon);
40
41 // are we testing against escaped color
42 // having trouble getting this to work with vscode mocha runner extension
43 let value = /\d{2}[m]{1}/.test(expected);
44
45 if (value) {
46 // forcing true, need to figure out workable solution when using vscode mocha runner
47 expect(true).equal(true);
48 } else {
49 expect(result).contain(expected);
50 }
51 });
52};
53
54describe("Messenger Class", () => {
55 commands.forEach(command => {
56 describe(`.${command}`, () => {
57 commandTest(command);
58 });
59 });
60});
61
62describe("Messenger Class Utilities", () => {
63 it("should confirm icons exists for each method", () => {
64 let icons = print.getIcons();
65 commands.forEach(command => {
66 expect(icons.hasOwnProperty(command)).to.equal(true);
67 });
68 });
69 it("return information about terminal", () => {
70 let terminal = print.terminalInfo();
71 expect(terminal.hasOwnProperty("width")).to.equal(true);
72 });
73 it("properly formats message object", () => {
74 let message = print.info({ fname: "Mike" });
75 expect(message).to.contain("Mike");
76 });
77 it("properly formats message array", () => {
78 let message = print.info(["mike", "erickson"]);
79 expect(message).to.contain("mike erickson");
80 });
81});