forked from compat-table/compat-table
-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.js
68 lines (60 loc) · 2.02 KB
/
node.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* global Symbol */
// run `npm install` to install deps first, then `node ./` to execute
var fs = require('fs');
var chalk = require('chalk');
var path = require('path');
var cheerio = require('cheerio');
var page = fs.readFileSync(path.join(__dirname, String(process.argv[2] || 'es6').toLowerCase(), 'index.html')).toString().replace(/data-source="[^"]*"/g,'');
var $ = cheerio.load(page);
var results = {};
var desc = {};
global.__script_executed = {};
$('#body tbody tr').each(function (index) {
if ($(this).find('.separator')[0]) {
return;
}
var scripts = $(this).find('script');
var i = 0;
var scr;
global.test = function test(expression) {
results[index] = results[index] || expression;
};
global.asyncPassed = function asyncPassed() {
results[index] = true;
};
global.__createIterableObject = function (arr, methods) {
methods = methods || {};
if (typeof Symbol !== 'function' || !Symbol.iterator)
return {};
arr.length++;
var iterator = {
next: function() {
return { value: arr.shift(), done: arr.length <= 0 };
},
'return': methods['return'],
'throw': methods['throw']
};
var iterable = {};
iterable[Symbol.iterator] = function(){ return iterator; };
return iterable;
};
results[index] = null;
desc[index] = $(this).find('td>span:first-child').text();
// can be multiple scripts
for (; scripts[i] && scripts[i].children && scripts[i].children.length; i++) {
scr = scripts[i].children[0].data.trim()
.replace(/global\.__asyncPassedFn && __asyncPassedFn\(".*?"\)/g, "asyncPassed");
eval(scr);
}
});
process.on('exit', function(){
Object.keys(results).forEach(function(test) {
var result = results[test];
var name = desc[test];
if (result === null) {
console.log('\u25BC\t' + name.replace('§',''));
} else {
console.log(chalk[result === "Strict" ? 'cyan' : result ? 'green' : 'red']((result ? '\u2714' : '\u2718') + '\t' + (name[0]!== '§' ? '\t' + name : name.slice(1)) + '\t'));
}
});
});