-
Notifications
You must be signed in to change notification settings - Fork 0
/
fillTests.js
143 lines (137 loc) · 4.81 KB
/
fillTests.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env node
var path = require ('path');
var async = require ('async');
var fs = require ('graceful-fs');
var child_process = require ('child_process');
var argv = require ('minimist')(process.argv, {
default: { html:false },
string: [ 'test' ],
boolean: [ 'html' ]
});
function killDir (dir, callback) {
var tries = 0;
fs.readdir (dir, function (err, list) {
if (err) return callback (err);
async.each (list, function (filename, callback) {
var fullpath = path.join (dir, filename);
fs.stat (fullpath, function (err, stats) {
if (err) return callback (err);
if (stats.isFile())
return fs.unlink (fullpath, callback);
killDir (fullpath, callback);
});
}, function tryToRemove (err) {
if (err) return callback (err);
if (++tries > 5)
return callback (new Error ('failed to clear directory'));
fs.rmdir (dir, function (err) {
if (err) {
if (err.code == 'ENOTEMPTY')
return setTimeout (tryToRemove, 100);
callback (err);
}
callback();
});
});
});
}
var ARGUMENTS = {
"NodeParsing.js": "--parse node --root test",
"NodeParsingWithoutRoot.js": "--parse node",
"JSParsing.js": "--parse js",
"JSParsingWithRoot.js": "--parse js --root test",
"ES6Parsing.js": "--parse js",
"LocalsAll.js": "--parse node --root test --locals all",
"LocalsComments.js": "--parse node --root test --locals comments",
"LocalsNone.js": "--parse node --root test",
"__proto__.js": "--parse node --root test",
"Prototype.js": "--parse node --root test",
"Overrides.js": "--parse node --root test",
"JSInheritence.js": "--parse node --root test",
"Skeleton.js": "--parse node --root skeleton --with node",
"SyntaxParsingChallenges.js": "--parse node --root test"
};
var SKIP = [
"NodeParseModule.js",
"NodeParseModules",
"ES6Modules",
"Fauxsync.js",
"skl",
"challenges"
];
async.parallel ([
function (callback) {
if (argv.test)
killDir (path.resolve ('test/out/'+argv.test), callback);
else
killDir (path.resolve ('test/out'), callback);
},
function (callback) {
if (argv.test)
killDir (path.resolve ('test/compare/'+argv.test), callback);
else
killDir (path.resolve ('test/compare'), callback);
}
], function (err) {
if (err && err.code != 'ENOENT') {
console.log (err.stack);
return process.exit (1);
}
fs.readdir ('test/tests', function (err, list) {
if (err) {
console.log (err.stack);
return process.exit (1);
}
async.eachSeries (list, function (testName, callback) {
if (SKIP.indexOf (testName) >= 0)
return callback();
if (argv.test && testName !== argv.test)
return callback();
var targetStr =
testName
+ ' --out test/compare/'
+ testName.slice (0, -3)
;
var htmlCommand =
'node ./cli.js --with browser-strict --date "june 5 2020" --in test/tests/'
+ targetStr
;
var jsonCommand =
'node ./cli.js --json --with browser-strict --date "june 5 2020" --in test/tests/'
+ targetStr
;
if (ARGUMENTS[testName]) {
htmlCommand += ' ' + ARGUMENTS[testName];
jsonCommand += ' ' + ARGUMENTS[testName];
}
async.parallel ([
function (callback) {
if (!argv.html)
return callback();
child_process.exec (
htmlCommand,
{ maxBuffer: 5 * 1024 * 1024 },
callback
);
},
function (callback) {
child_process.exec (
jsonCommand,
{ maxBuffer: 5 * 1024 * 1024 },
callback
);
}
], function (err) {
if (err) return callback (err);
console.log ('finished with '+testName);
callback();
});
}, function (err) {
if (err) {
console.log (err.stack);
return process.exit (1);
}
console.log ('done');
});
});
});