-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathwpt.js
50 lines (42 loc) · 1.7 KB
/
wpt.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
// RUn WPT manually before calling this script
// Example: ./wpt serve
// Example: node test/wpt.js
import { JSDOM } from 'jsdom';
import nodeDataChannel from '../lib/index.js';
const WPT_SERVER_URL = 'http://web-platform.test:8000';
const WPT_TEST_PATH_LIST = ['/webrtc/RTCPeerConnection-addIceCandidate.html', '/webrtc/RTCDataChannel-send.html'];
// call runTest for each test path
for (let i = 0; i < WPT_TEST_PATH_LIST.length; i++) {
let result = await runTest(`${WPT_SERVER_URL}${WPT_TEST_PATH_LIST[i]}`);
console.log(result);
// sleep for 1 second
await new Promise((resolve) => setTimeout(resolve, 1000));
}
function runTest(filePath) {
// return new promise
return new Promise((resolve, reject) => {
JSDOM.fromURL(filePath, {
runScripts: 'dangerously',
resources: 'usable',
}).then((dom) => {
const { window } = dom;
// Assign the data channel polyfill to the window object
Object.assign(window, nodeDataChannel);
const returnObject = [];
window.addEventListener('load', () => {
window.add_result_callback((test) => {
// Meaning of status
// 0: PASS (test passed)
// 1: FAIL (test failed)
// 2: TIMEOUT (test timed out)
// 3: PRECONDITION_FAILED (test skipped)
returnObject.push({ name: test.name, message: test.message, status: test.status });
});
window.add_completion_callback(() => {
window.close();
return resolve(returnObject);
});
});
});
});
}