|
17 | 17 |
|
18 | 18 |
|
19 | 19 | /** |
20 | | - * @fileoverview Basic test classes. |
| 20 | + * @fileoverview Basic abstract test classes. |
21 | 21 | * |
22 | 22 | * @author [email protected] (Volker Sorge) |
23 | 23 | */ |
24 | 24 |
|
25 | 25 | /* globals System: true */ |
26 | 26 |
|
27 | | -let fs = require('fs'); |
28 | | - |
29 | 27 | export class Test { |
30 | 28 |
|
31 | | - failedTests = []; |
32 | | - failed = false; |
33 | | - time = 0; |
34 | | - |
35 | | - constructor() { |
36 | | - /** |
37 | | - * @type {Object.<string, number>} |
38 | | - */ |
39 | | - this.runningTests = {}; |
40 | | - |
41 | | - /** |
42 | | - * @type {Object.<string, number>} |
43 | | - */ |
44 | | - this.concludedTests = {}; |
45 | | - |
46 | | - // this.createStream(); |
47 | | - } |
48 | | - |
49 | | - |
50 | | - /** |
51 | | - * @param {string} name The name of the test. |
52 | | - * @private |
53 | | - */ |
54 | | - startTest(name) { |
55 | | - this.concludedTests[name] = (new Date()).getTime(); |
56 | | - } |
57 | | - |
58 | | - /** |
59 | | - * @param {string} name The name of the test. |
60 | | - * @private |
61 | | - */ |
62 | | - registerTest(name) { |
63 | | - this.runningTests[name] = true; |
64 | | - } |
65 | | - |
66 | | - stopTest(name) { |
67 | | - this.concludedTests[name] = |
68 | | - (new Date()).getTime() - this.concludedTests[name]; |
69 | | - delete this.runningTests[name]; |
70 | | - } |
71 | | - |
72 | | - |
73 | | - printTime() { |
74 | | - if (Object.keys(this.runningTests).length) { |
75 | | - setTimeout(this.printTime.bind(this), 100); |
76 | | - return; |
77 | | - } |
78 | | - for (var test in this.concludedTests) { |
79 | | - this.time += this.concludedTests[test]; |
80 | | - delete this.concludedTests[test]; |
81 | | - } |
82 | | - process.stdout.write(this.name + ': ' + this.time + 'ms\n'); |
83 | | - } |
84 | | - |
85 | | - test(name, func) { |
86 | | - this.registerTest(name); |
87 | | - test(name, function(t) { |
88 | | - this.startTest(name); |
89 | | - t.plan(1); |
90 | | - func(t); |
91 | | - this.stopTest(name); |
92 | | - }.bind(this)); |
93 | | - } |
94 | | - |
95 | | - createStream() { |
96 | | - test.createStream({ objectMode: true }).on('data', result => { |
97 | | - if (result.type !== 'assert') return; |
98 | | - process.stdout.write('Running test ' + result.name + '\t' + |
99 | | - (result.ok ? |
100 | | - ('\u001B\u005B\u0033\u0032\u006D' + 'PASS' + |
101 | | - '\u001B\u005B\u0033\u0037\u006D') : |
102 | | - ('\u001B\u005B\u0033\u0031\u006D' + 'FAIL' + |
103 | | - '\u001B\u005B\u0033\u0037\u006D')) + |
104 | | - '\n'); |
105 | | - if (result.ok) return; |
106 | | - this.failed = true; |
107 | | - this.failedTests.push(result.name); |
108 | | - process.stdout.write('Actual: \n'); |
109 | | - process.stdout.write(JSON.stringify(result.actual) + '\n'); |
110 | | - process.stdout.write('Expected: \n'); |
111 | | - process.stdout.write(JSON.stringify(result.expected) + '\n'); |
112 | | - }); |
113 | | - } |
114 | | - |
115 | 29 | runTest(name, input, expected, rest) {} |
116 | 30 |
|
117 | 31 | } |
@@ -141,7 +55,6 @@ export class JsonTest extends Test { |
141 | 55 | for (const [name, {input, expected, ...rest}] of Object.entries(this.tests)) { |
142 | 56 | this.runTest(name, input, expected, rest); |
143 | 57 | }}); |
144 | | - // this.printTime(); |
145 | 58 | } |
146 | 59 |
|
147 | 60 | } |
0 commit comments