forked from williamkapke/node-compat-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract.js
43 lines (37 loc) · 925 Bytes
/
extract.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
var es6 = require(process.argv[2])
var tests = es6.tests
var testers = {}
var category
function deindent (fn) {
var indent = /(?:^|\n)([\t ]+)[^\n]+/.exec(fn)
return indent ? fn.replace(new RegExp('\n' + indent[1], 'g'), '\n') : fn
}
tests.forEach(function (test) {
if (category !== test.category) {
category = test.category
}
var name = [category, test.name]
var info = {
spec: test.spec
}
if (test.subtests) {
test.subtests.forEach(function (subtest) {
name[2] = subtest.name
testers[name.join('›').replace(/<[^>]+>/g, '')] = {
...info,
code: getScript(subtest.exec)
}
})
} else {
testers[name.join('›').replace(/<[^>]+>/g, '')] = {
...info,
code: getScript(test.exec)
}
}
function getScript (fn) {
return deindent(fn + '').split('\n').slice(1, -1).join('\n')
}
})
console.log(
JSON.stringify(testers, null, 2)
)