forked from stuartlangridge/sorttable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
143 lines (126 loc) · 4.55 KB
/
Gruntfile.js
File metadata and controls
143 lines (126 loc) · 4.55 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
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
143
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
// define the files to lint
files: ['gruntfile.js', 'sorttable.js'],
// configure JSHint (documented at http://www.jshint.com/docs/)
options: {
// more options here if you want to override JSHint defaults
globals: {
console: true,
module: true
}
}
},
casperjs: {
options: {
async: {
parallel: false
}
},
files: ['tests/casperjs/**/*.js']
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('build-tests',
'Actually build the HTML test files', function() {
var fs = require("fs"), Mustache=require("mustache");
var rootdir = __dirname + "/tests/";
var done = this.async();
grunt.log.write("Deleting existing tests\n");
fs.readdirSync(rootdir).forEach(function(fn) {
if (fn.match(/^test-.*\.html$/)) {
fs.unlinkSync(rootdir + fn);
}
});
grunt.log.write("Reading JSON description of tests\n");
fs.readFile(rootdir + "test-definitions.json", "utf8", function(err, data) {
if (err) { return done(false); }
fs.readFile(rootdir + "template.html", "utf8", function(err, template) {
if (err) { return done(false); }
var testdata = JSON.parse(data);
var suitelist = [];
for (var suite in testdata.tests) {
suitelist.push(suite);
}
function next() {
var suite = suitelist.shift();
if (!suite) {
done();
return;
}
console.log("Processing suite", suite);
var suite_rows = testdata.tests[suite].rows;
var sortresults = testdata.tests[suite].expected_column_1_after_sort_by_column_n;
var columns = []; // should be range(0, columncount)
for (var i=0; i<sortresults.length; i++) {
columns.push(i);
}
var rows = [];
suite_rows.forEach(function(suite_row) {
rows.push({row: suite_row});
});
var template_data = {
columns: columns,
rows: rows,
suite: suite,
json_sortresults: JSON.stringify(sortresults)
};
var html = Mustache.render(template, template_data);
fs.writeFile(rootdir + "test-" + suite + ".html", html, function(err) {
if (err) throw(err);
next();
});
}
next();
});
});
});
grunt.registerTask('run-tests-with-wru',
'Execute all the test files with wru', function() {
var fs = require("fs"),
rootdir = __dirname + "/tests/";
var done = this.async();
fs.readdir(rootdir, function(err, files) {
var testFiles = [];
files.forEach(function(fn) {
if (fn.match(/^test-.*\.html$/)) {
testFiles.push(fn);
}
});
function next() {
var fn = testFiles.shift();
if (!fn) {
done();
return;
}
console.log("=== Testing: ", fn);
var ffn = rootdir + fn;
grunt.util.spawn({
cmd: "phantomjs",
args: [
rootdir + "wru-phantom.js",
ffn
]
}, function(err, result, code) {
console.log(result.stdout);
if (err) {
console.log("TESTS FAILED");
throw(err);
}
next();
});
}
next();
});
});
// Default task(s).
grunt.registerTask('test', [
'build-tests',
'run-tests-with-wru',
'jshint'
]);
grunt.registerTask('default', ['test']);
};