-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtas_list.js
64 lines (57 loc) · 1.94 KB
/
tas_list.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
var fs = require('fs');
var vm = require('vm');
// set predefined variables, to deal with
// https://github.com/joyent/node/issues/9211
global.require = require;
global.__dirname = __dirname;
global.__filename = 'Gruntfile.js';
global.module = module;
vm.runInThisContext(fs.readFileSync('./Gruntfile.js', 'utf8'));
// override exports, provide our function and task
module.exports = function(grunt) {
// load grunt config from enyo-tests
grunt.initConfig(gruntConfig);
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task.
grunt.registerTask('default', 'tas_list:simplemocha:all');
grunt.registerTask('tas_list', function() {
var taskConfig = grunt.config(this.args.join('.'));
var expanded = grunt.task.normalizeMultiTaskFiles(taskConfig);
var result = [];
var tasObj = {"name": "Enyo tests",
"path": [
"enyo"
],
"requires": {
"enyo_env": {}
}};
expanded.forEach(function(files) {
files.src.forEach(function(file) {
var contents = fs.readFileSync(file,'utf8');
var titleIndex = contents.indexOf("title =");
var titleBeginIndex = contents.indexOf("'",titleIndex);
var titleEndIndex = contents.indexOf(",",titleIndex);
var fileTitle = contents.substring(titleBeginIndex+1, titleEndIndex-1);
var testBegin = file.lastIndexOf("/");
var testEnd = file.lastIndexOf("-");
var filename = file.substring(testBegin + 1, testEnd);
result.push({
"arguments": {
'test': filename,
'title': fileTitle
},
"file": "run_enyo_test.py"
});
});
});
tasObj.tests = result;
var destfile = grunt.option('destfile') || 'tas_list.json';
fs.writeFileSync(destfile, JSON.stringify(tasObj, null, 2));
console.log('Saved result to ' + destfile);
});
};