1 | const TestFilePrototype = {
|
2 | [Symbol.iterator]() {
|
3 | return this.failureList[Symbol.iterator]();
|
4 | },
|
5 | incrementSuccess() {
|
6 | this.success++;
|
7 | },
|
8 | incrementFailure() {
|
9 | this.failure++;
|
10 | },
|
11 | incrementSkip() {
|
12 | this.skip++;
|
13 | },
|
14 | writeLine() {
|
15 | this.out.clearLine(0);
|
16 | this.out.cursorTo(0);
|
17 |
|
18 | const statusSymbol = (this.failure > 0 ? ' ✖' : (this.skip > 0 ? ' ⚠' : ' ✔'));
|
19 | const style = (this.failure > 0 ? 'failureBadge' : (this.skip > 0 ? 'skipBadge' : 'successBadge'));
|
20 |
|
21 | let summaryString = `${this.success}/${this.total} `;
|
22 |
|
23 | summaryString = `${statusSymbol}${summaryString.padStart(8)}`;
|
24 |
|
25 | this.out.writeLine(`${this.out[style](summaryString)} ${this.out.path(this.file)}`, 1);
|
26 | },
|
27 | goIn(path) {
|
28 | this.path.push(path);
|
29 | },
|
30 | goOut() {
|
31 | this.path.pop();
|
32 | },
|
33 | addFailure(data) {
|
34 | const path = [...this.path];
|
35 | this.failureList.push({path, data});
|
36 | }
|
37 | };
|
38 |
|
39 | exports.testFile = (file, out) => {
|
40 | let success = 0;
|
41 | let failure = 0;
|
42 | let skip = 0;
|
43 | const path = [file];
|
44 | const failureList = [];
|
45 |
|
46 | return Object.create(TestFilePrototype, {
|
47 | file: {
|
48 | value: file
|
49 | },
|
50 | out: {
|
51 | value: out
|
52 | },
|
53 | total: {
|
54 | get() {
|
55 | return success + failure + skip;
|
56 | }
|
57 | },
|
58 | success: {
|
59 | get() {
|
60 | return success;
|
61 | },
|
62 | set(val) {
|
63 | success = val;
|
64 | }
|
65 | },
|
66 | failure: {
|
67 | get() {
|
68 | return failure;
|
69 | },
|
70 | set(val) {
|
71 | failure = val;
|
72 | }
|
73 | },
|
74 | skip: {
|
75 | get() {
|
76 | return skip;
|
77 | },
|
78 | set(val) {
|
79 | skip = val;
|
80 | }
|
81 | },
|
82 | path: {value: path},
|
83 | failureList: {value: failureList}
|
84 | });
|
85 | }; |
\ | No newline at end of file |