-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (48 loc) · 1.24 KB
/
index.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
// @ts-check
"use strict";
const tape = require("tape");
const { EOL } = require("os");
const { inspect } = require("util");
const { stdout } = process;
const inspectOptions = {
"breakLength": Infinity,
"compact": true
};
let tests = 0;
let assertions = 0;
let failures = 0;
tape.
createStream({ "objectMode": true }).
on("data", (data) => {
if (data.type === "test") {
tests++;
stdout.write(`${data.name}${EOL}`);
} else if (typeof data.id !== "undefined") {
assertions++;
if (!data.ok) {
failures++;
const lines = [
` ${data.file}`,
` Message: ${data.name}`,
` Operator: ${data.operator}`
];
if (Object.prototype.hasOwnProperty.call(data, "expected")) {
lines.push(` Expected: ${inspect(data.expected, inspectOptions)}`);
}
if (Object.prototype.hasOwnProperty.call(data, "actual")) {
lines.push(` Actual: ${inspect(data.actual, inspectOptions)}`);
}
lines.push("");
stdout.write(lines.join(EOL));
}
}
}).
on("close", () => {
stdout.write([
"",
`Tests: ${tests}`,
`Asserts: ${assertions}`,
`Failures: ${failures}`,
""
].join(EOL));
});