-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
103 lines (89 loc) · 2.76 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
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
var Promise = require( "bluebird" );
var path = require( "path" );
var fs = Promise.promisifyAll( require( "fs-extra" ) );
var promiseBatcher = require( "./lib/promise-batcher" );
module.exports = function( grunt ) {
grunt.loadNpmTasks( "grunt-simple-mocha" );
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON( "package.json" ),
simplemocha: {
options: {
reporter: "list"
},
server: {
src: [
"test/*.js",
"test/*/*.js"
]
}
},
watch: {
server: {
files: [
"server/*.js",
"server/*/*.js",
"test/server/*.js"
],
tasks: [ "simplemocha" ]
}
}
});
// Default task(s).
grunt.registerTask( "default", [ "ckupdate" ]);
grunt.registerTask( "test", [ "simplemocha" ]);
grunt.registerTask( "prepare-tests", "Prepare the unit tests by running npm install", function() {
var casesRoot = "./test/server/cases/";
var done = this.async();
fs.readdirAsync( "./test/server/cases/" )
.then( function( files ) {
var testDirs = [];
for ( var i = 0; i < files.length; i++ ) {
var path = casesRoot + files[ i ];
if ( fs.lstatSync( path ).isDirectory() ) {
testDirs.push( path );
}
}
return testDirs;
})
.then( function( testDirs ) {
return promiseBatcher.batch( 1, testDirs, null, cleanAndNpmInstall );
})
.done( done );
});
grunt.registerTask( "ckupdate", "Execute the ckupdate tool", function() {
var done = this.async();
var childProcess = require( "child_process" );
var worker = childProcess.spawn( "node", [ "ckupdate.js" ] );
worker.stdout.pipe( process.stdout );
worker.stderr.pipe( process.stderr );
done();
});
};
function cleanAndNpmInstall( testDir ) {
var cwd = process.cwd();
console.log( "Working directory: " + cwd );
console.log( "Removing directory: " + testDir + "/node_modules/" );
return fs.removeAsync( testDir + "/node_modules/" )
.then( function() {
var promise = new Promise( function( resolve, reject ) {
console.log( "Changing dir to: " + testDir );
process.chdir( testDir );
var childProcess = require( "child_process" );
console.log( "Running npm install" );
var worker = childProcess.exec( "npm install" );
worker.stdout.pipe( process.stdout );
worker.stderr.pipe( process.stderr );
worker.on( "close", function() {
console.log( "On close -- changing directory to: " + cwd );
process.chdir( cwd );
resolve();
});
worker.on( "error", function() {
console.log( "On error -- changing directory to: " + cwd );
process.chdir( cwd );
});
});
return promise;
});
}