forked from SDITools/Airlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
73 lines (64 loc) · 1.87 KB
/
Gruntfile.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
module.exports = function (grunt) {
var pkg = grunt.file.readJSON('package.json');
grunt.initConfig({
pkg: pkg,
watch: {
test: {
files: ['airlock.js', 'tests/actions/*.js', 'tests/actionTester.js'],
tasks: ['casperjs']
}
},
casperjs: {
options: {
casperjsOptions: [
'--concise',
'--port=' + pkg.config.testPort,
'--includes=tests/actionTester.js'
]
},
files: ['tests/actions/']
},
uglify: {
deploy: {
options: {
banner: '/* | <%= pkg.name %> - v<%= pkg.version %>' + '\n' +
' | <%= pkg.homepage %> */' + '\n'
},
files: {
'airlock.min.js': ['airlock.js']
}
}
}
});
grunt.loadNpmTasks('grunt-casperjs');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('test', ['server', 'casperjs', 'watch:test']);
grunt.registerTask('testOnce', ['server', 'casperjs']);
grunt.registerTask('deploy', ['uglify:deploy']);
grunt.registerTask('server', 'Server HTML test runner', function () {
var fs = require('fs');
var http = require('http');
var WebServer = function (file) {
var server = function(req, res) {
var html = __dirname + '/tests/runner.html',
js = __dirname + '/airlock.js',
file;
if (req.url === '/') { file = html; }
if (/\.js$/.test(req.url)) { file = js; }
if (!file) { return; }
fs.readFile(file, function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading ' + file);
}
res.writeHead(200);
res.end(data);
});
};
return http.createServer(server);
};
var server = new WebServer();
server.listen(pkg.config.testPort);
});
};