-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
92 lines (88 loc) · 3.23 KB
/
index.js
File metadata and controls
92 lines (88 loc) · 3.23 KB
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
/*!
*
* Author: CheMingjun
*/
'use strict';
/**
* define a file annotations
*/
var util = require('util'),fs = require('fs'),path = require('path');
require('at-js').define('test.\\S+', {
scope: 'file', build: function () {
var start = null, step = [], finish = null;
return {
which: {
'test.start': function (_ctx, _argAry) {
start = "function*(){return " + (_ctx.refType==='generator' ? 'yield ' : '') + _ctx.refName + "();}";
}, 'test.step': function (_ctx, _argAry) {
step.push("function*(){return " + (_ctx.refType==='generator' ? 'yield ' : '') + _ctx.refName + "();}");
}, 'test.finish': function (_ctx, _argAry) {
finish = "function*(){return " + (_ctx.refType==='generator' ? 'yield ' : '') + _ctx.refName + "();}";
}
}, script: function () {
return "module.exports = {" + (start ? ("start:" + start + "," ) : '') + "step:[" + step.join(',') + "]" + (finish ? (",finish:" + finish) : '') + "}";
}
}
}
})
/**
* test files
* @param _v ['./test/t0.js','./test/t1.js']
* @returns {{then: then}}
*/
module.exports = {
run:function (_v) {
_v = _v||'test.js$';
var comp = null,pro = function(_v){
var gen = require('./lib/exe')(_v);
require('co')(gen).then(function (_report) {
comp && comp(null,_report);
}, function (_err) {
comp && comp(_err);
})
};
if(util.isArray(_v)){//test files in array
pro(_v);
}else if(typeof _v ==='string'){//test files by ext name
var bsFilePath = (function () {
let pt = module.parent, rtn = pt ? pt.filename : __filename;
while (pt != null) {
rtn = pt ? pt.filename : __filename;
pt = pt.parent;
}
if (!rtn) {
throw new Error('Toybricks init error.');
}
return rtn;
})();
var dirPath = path.dirname(bsFilePath);
var ts = './', tp = path.join(dirPath, ts + 'package.json');
while (tp != '' && !fs.existsSync(tp)) {
ts += '../';
tp = path.join(dirPath, ts + 'package.json')
}
//------------------------------------------------------------------------------
var fAry = [],reg = new RegExp(_v),parse = function(mdPath){
let dirs = fs.readdirSync(mdPath);
dirs.forEach(function (filename, _index) {
let tp = path.join(mdPath, filename);
let _stats = fs.statSync(tp);
if (_stats.isDirectory()&&filename!=='node_modules') {
parse(tp);
}else if(reg.test(filename)){
fAry.push(tp)
}
});
}
parse(path.dirname(tp));
if(fAry.length>0){
pro(fAry);
}
}
return {
finish: function (_comp) {
comp = _comp;
}
}
}
};