-
Notifications
You must be signed in to change notification settings - Fork 42
/
test.js
122 lines (108 loc) · 3.21 KB
/
test.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
var finder = require('./finder.js');
var ROOT = __dirname;
var path = require('path');
var fs = require('fs');
var async = require('async');
var spawn = require('child_process').spawn;
var util = require('util');
var argv = process.argv;
var hash = require('object-hash');
var assign = require('object-assign');
if (argv.length < 3) {
console.log('Please specify modules to be tested.\nFor example: `node test.js "modules/jquery-*.js"`');
process.exit(1);
}
function mixin(a, b) {
if (a && b) {
for (var key in b) {
a[key] = b[key];
}
}
return a;
}
function loadConfig(path) {
var list = require(path);
var map = {};
if (Array.isArray(list)) {
list.forEach(function(item) {
map[item.version] = item;
if (item.extend) {
if (!map[item.extend]) {
throw new Error('Extend `'+item.extend+'` is not defined.');
}
var copySelf = mixin({}, item)
mixin(item, map[item.extend]);
mixin(item, copySelf);
delete item.extend;
}
});
} else {
var pkg = list;
list = [];
var tags = pkg.tags;
tags.forEach(function(tag) {
var data = assign({}, pkg, tag);
delete data.tags;
delete data.__hash;
var hashvalue = hash(data);
if (hashvalue === tag.__hash) {
return;
}
if (data.mapping) {
data.mapping = data.mapping.map(function(subitem) {
var clone = assign({}, subitem);
var reg = new RegExp(subitem.reg, "i");
clone.reg = reg;
return clone;
});
}
list.push(data);
});
}
return list;
}
var files = argv.slice(2);
files = finder(__dirname, files)
.map(function(i) {
return i.relative;
})
.filter(function(p) {
if (p.indexOf('modules') == -1 && p.indexOf('packages') == -1) {
return false;
}
return /\.js(?:on)?$/.test(p);
});
files.forEach(function(name) {
var list = loadConfig(path.join(ROOT, name));
var isFromJson = /\.json$/.test(name);
name = name.replace(/(?:modules|packages)\//, '')
.replace(/\.js(?:on)?$/, '');
var basename = path.basename(name);
var queue = [];
list.forEach(function(r) {
// console.log(r.mapping);process.exit(1);
queue.push(function(cb) {
var h = spawn('bash', [
path.join(ROOT, 'test.sh'),
basename,
r.repos,
r.build || '',
r.version,
r.build_dest || '',
r.tag || r.version,
name.substr(0, name.length - basename.length),
isFromJson ? 'true' : false
], {
cwd: __dirname
});
h.stdout.on('end', function() {
cb();
});
h.stdout.pipe(process.stdout);
h.stderr.pipe(process.stderr);
});
});
async.series(queue, function() {
console.log('done');
});
});