forked from murat-dogan/node-datachannel
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
104 lines (89 loc) · 3.33 KB
/
index.ts
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
import ndc from '../../src/lib/index'
import wptTestList from './wpt-test-list';
import { runWptTests, WptTestResult } from './wpt';
import { runChromeTests, isTestForChromeFailed } from './chrome-failed-tests';
// Set the log level, for debugging purposes
// ndc.initLogger('Debug');
// Catch unhandled exceptions
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
process.exit(1);
});
async function run(): Promise<void> {
// Run tests for Chrome
console.log('# Running tests for Chrome...');
await runChromeTests(wptTestList);
// Run tests for node-datachannel
console.log('');
console.log('# Running tests for node-datachannel...');
const results: WptTestResult[] = await runWptTests(wptTestList);
// Calc total number of tests
let totalTests = 0;
results.forEach((result) => {
totalTests += result.result.length;
});
// Compare results
// Filter failed tests for node-datachannel
const failedTestsLibrary: WptTestResult[] = [];
results.forEach((result) => {
if (result.result.some((test) => test.status === 1)) {
failedTestsLibrary.push({
test: result.test,
result: result.result.filter((test) => test.status === 1),
});
}
});
let totalFailedTestsLibrary = 0;
failedTestsLibrary.forEach((result) => {
totalFailedTestsLibrary += result.result.length;
});
// Filter out any failed tests that also failed in Chrome
const failedTests: WptTestResult[] = [];
failedTestsLibrary.forEach((result) => {
if (result.result.some((test) => !isTestForChromeFailed(result.test, test.name))) {
failedTests.push({
test: result.test,
result: result.result.filter((test) => !isTestForChromeFailed(result.test, test.name)),
});
}
});
let totalFailedTests = 0;
failedTests.forEach((result) => {
totalFailedTests += result.result.length;
});
// console.log(JSON.stringify(failedTests, null, 2));
// Print Report
// Print Test Names
console.log('');
console.log('# Tests Report');
// Total number of tests
console.log('Total Tests [Library]: ', totalTests);
// Number of passed tests
console.log('Passed Tests: ', totalTests - totalFailedTestsLibrary, ' ');
// Number of failed tests for chrome + node-datachannel
console.log(
'Failed Tests (Chrome + Library): ',
totalFailedTestsLibrary - totalFailedTests,
" (We don't care about these tests) ",
);
// Number of failed tests
console.log('Failed Tests: ', totalFailedTests, ' ');
// Print Failed Tests
console.log('');
console.log('## Failed Tests');
for (let i = 0; i < failedTests.length; i++) {
console.log(`### ${failedTests[i].test}`);
for (let j = 0; j < failedTests[i].result.length; j++) {
console.log(`- name: ${failedTests[i].result[j].name} `);
console.log(` message: ${failedTests[i].result[j].message} `);
}
}
// Sometimes failed tests are not cleaned up
// This can prevent the process from exiting
ndc.cleanup();
console.log('End of tests');
}
run().catch((error) => {
console.error(error);
process.exit(1);
});