/
testinator.js
78 lines (71 loc) · 2.42 KB
/
testinator.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
var sys = require("sys"),
http = require("http"),
fs = require('fs'),
jsdom = require('jsdom'),
util = require('util'),
url = require('url');
var agrs = process.argv;
var specUrl = agrs[3];
var pUrl = url.parse(specUrl);
console.log(util.inspect(pUrl));
var options = {
host: pUrl.host,
port: pUrl.port === undefined? 80 : pUrl.port,
path: (pUrl.pathname === undefined ? '' : pUrl.pathname)+(pUrl.search === undefined ? '' : pUrl.search)+(pUrl.hash === undefined ? '' : pUrl.hash)
};
console.log(util.inspect(options));
var generateTestFile = function(tests){
var objectsToString = function(testCaseObject){
var testCaseString = '\t{\n';
testCaseString += '\t\tid:'+testCaseObject.id+',\n';
testCaseString += '\t\tname:"'+testCaseObject.name +'",\n';
testCaseString += '\t\tdefinedInSpecs:["'+testCaseObject.definedInSpecs+'"],\n';
testCaseString += '\t\ttest:function(t){\n';
testCaseString += '\t\t\t//\tadd the test here\n';
testCaseString += '\t\t}\n';
testCaseString += '\t},\n';
return testCaseString;
};
var testString = 'var testCases = [\n';
for (var i = 0; i < tests.length; i += 1){
testString += objectsToString(tests[i]);
}
testString += '];';
var filename = agrs[4];
fs.writeFile(filename, testString, function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
};
var selectParser = agrs[2];
try {
var parserModule = require('./parser/'+selectParser);
} catch (err) {
console.log('there is no parser module for '+selectParser);
process.exit(0);
}
if (typeof parserModule.SpecParser === 'function'){
http.get(options, function(response){
var responseData;
response.on('data', function (chunk){
responseData += chunk;
});
response.on('end', function () {
var parser = new parserModule.SpecParser();
var tests = [];
parser.on('onTest', function(testCaseObject){
tests.push(testCaseObject);
});
parser.on('end', function(){
generateTestFile(tests);
});
parser.parseSpec(responseData, specUrl);
});
console.log("Got response: " + response.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
}
else {
console.log('there is no parser module for '+selectParser);
}