-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbunny.js
139 lines (129 loc) · 3.54 KB
/
bunny.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env node
const colors = require("colors");
const success = ` | ̄ ̄ ̄ ̄ ̄|
| SUCCESS |
| I <3 U |
|_____|
(\\__/) ||
(•ㅅ•) ||
/ づ`;
const failure = ` | ̄ ̄ ̄ ̄ ̄|
| FAILURE |
| I H8 U |
|_____|
(\\__/) ||
(${"•".red}ㅅ${"•".red}) ||
/ づ`;
// const bunny = () => {
// const readStream = process.openStdin();
//
// let fileContent = "";
//
// readStream.on("data", chunk => {
// fileContent += chunk;
// });
//
// readStream.on("end", () => {
// if (fileContent === "") return process.stdout.write("\nERROR".red + "\n");
// var arr = fileContent.toString().split("\n");
// // console.log(arr);
//
// displayErrors(arr);
// formatLines(arr);
// addBunny(arr);
// process.stdout.write("\n\n");
// });
// };
const addBunny = arr => {
// console.log(arr);
if (arr[arr.length - 3].includes("ok")) {
process.stdout.write(success);
} else {
process.stdout.write(failure);
}
};
const formatLines = arr => {
let b = false;
arr.map((line, i) => {
if (line.charAt(0) == "#" && i < arr.length - 6) {
const formatted = line.slice(2).bold;
process.stdout.write("\n " + formatted + "\n");
} else if (line.slice(0, 2) == "ok") {
const prefix = line.split(" ")[1] + ". ";
const formatted = prefix.bold.green + line.slice(5).green;
process.stdout.write(" " + formatted + "\n");
} else if (line.slice(0, 3) == "not") {
const prefix = line.split(" ")[2] + ". ";
const formatted = prefix.bold.red + line.slice(9).red;
process.stdout.write(" " + formatted + "\n");
} else if (line.slice(0, 7) == "# tests" && i > arr.length - 7) {
const formatted = " Tests: ".cyan.bold + line.slice(7).bold.blue;
process.stdout.write("\n" + formatted + "\n");
} else if (line.slice(0, 6) == "# pass" && i > arr.length - 7) {
const formatted = " Passed:".cyan.bold + line.slice(7).green.bold;
process.stdout.write(formatted + "\n");
} else if (i == arr.length - 3) {
let num = "0";
if (line.slice(0, 6) == "# fail") num = line.slice(8);
const formatted = " Failed: ".cyan.bold + num.red.bold;
process.stdout.write(formatted + "\n");
} else if (
line.slice(0, 11) != "TAP version" &&
line != "" &&
line.slice(1, 3) != ".."
) {
if (line === " ---") {
b = true;
}
if (b === false) {
process.stdout.write(line.italic.yellow + "\n");
}
if (line === " ...") {
b = false;
}
}
});
process.stdout.write("\n");
};
const displayErrors = arr => {
let errors = [];
arr.map((line, i) => {
if (line.slice(0, 5) == " ---") {
let b = false;
let e = [];
for (let j = i - 1; arr[j] != " ..."; j++) {
if (arr[j] != " ---") e.push(arr[j]);
}
errors.push(e);
}
});
// console.log(errors);
errors.map(arr => {
const title = arr.shift().slice(7).underline.bold;
process.stdout.write(title + "\n");
arr.map(line => {
const formatted = line.slice(2).yellow;
process.stdout.write(formatted + "\n");
});
process.stdout.write("\n");
});
};
const errorBunny = () => {
let error = ` | ̄ ̄ ̄ ̄ ̄|
| ${"ERROR:".red} |
| ${"U ARE A".yellow} |
| ${"TERRIBLE".yellow} |
| ${"PERSON".yellow} |
|_____|
(\\__/) ||
(•ㅅ•) ||
/ づ`;
process.stdout.write("\n" + error + "\n\n");
};
// bunny();
module.exports = {
displayErrors,
formatLines,
addBunny,
errorBunny
};