This repository has been archived by the owner on Jul 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGruntfile.js
155 lines (131 loc) · 5.01 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
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
144
145
146
147
148
149
150
151
152
153
154
155
"use strict";
var child_process = require('child_process'),
exec = child_process.exec,
spawn = child_process.spawn,
path = require("path"),
os = require("os");
var tests = __dirname + "/test",
clientTests = tests + "/client",
sharedTests = tests + "/shared",
webpackDevServerBin = path.join(__dirname, "node_modules", "webpack-dev-server", "bin", "webpack-dev-server.js");
module.exports = function (grunt) {
grunt.initConfig({
simplemocha : {
all : {
src : ["test/server/**/*.test.js", "test/shared/**/*.test.js", "test/core/**/*.test.js"],
options : {
globals : ['should'],
timeout : 3000,
ignoreLeaks : false,
ui : 'bdd',
reporter : 'spec'
}
},
nyan : {
src : ["test/server/**/*.test.js", "test/shared/**/*.test.js", "test/core/**/*.test.js"],
options : {
globals : ['should'],
timeout : 3000,
ignoreLeaks : false,
ui : 'bdd',
reporter : 'nyan'
}
},
shared : {
src : 'test/shared/**/*.test.js',
options : {
globals : ['should'],
timeout : 3000,
ignoreLeaks : false,
ui : 'bdd',
reporter : 'spec'
}
},
server : {
src : 'test/server/**/*.test.js',
options : {
globals : ['should'],
timeout : 3000,
ignoreLeaks : false,
ui : 'bdd',
reporter : 'spec'
}
},
core : {
src : 'test/core/**/*.test.js',
options : {
globals : ['should'],
timeout : 3000,
ignoreLeaks : false,
ui : 'bdd',
reporter : 'spec'
}
},
jenkins : {
src : ["test/server/**/*.test.js", "test/shared/**/*.test.js", "test/core/**/*.test.js"],
options : {
globals : ['should'],
timeout : 3000,
ignoreLeaks : false,
ui : 'bdd',
reporter : 'xunit-file'
}
}
}
});
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.registerTask("enable-testing-mode", "sets env to testing to keep the console quiet", function () {
var env = process.env;
env.env = "testing"; //logger be quiet!
});
grunt.registerTask("freshNpmInstall", "deletes the node_modules folder and does npm install afterwards", function () {
var done = this.async();
var rmNodeModulesProcess = exec("rm -r -f " + __dirname + "/node_modules ",
function (error, stdout, stderr) {
if (error !== null) {
done(error);
return;
}
var npmInstall = spawn("npm", ["install"]);
//awesome pipeing!
npmInstall.stdout.pipe(process.stdout);
npmInstall.stderr.pipe(process.stderr);
npmInstall.on('exit', function (code) {
if (code === 0) {
done(null);
}
else {
done(new Error("NPM Install error!"));
}
});
});
});
grunt.registerTask("test-client", "Browser tests", function testClient() {
this.async();
runWebpackDevServer(clientTests);
});
grunt.registerTask("test-shared-browser", "Shared browser-tests", function testSharedBrowser() {
this.async();
runWebpackDevServer(sharedTests);
});
grunt.registerTask("test-all-browser", "Browsers tests for client- and shared-lib", function testClientShared() {
this.async();
runWebpackDevServer(tests);
});
//mocha server tests
grunt.registerTask("test-server", ["enable-testing-mode", "simplemocha:server"]);
grunt.registerTask("test-core", ["enable-testing-mode", "simplemocha:core"]);
grunt.registerTask("test-shared", ["enable-testing-mode", "simplemocha:shared"]);
grunt.registerTask('test-all', ["enable-testing-mode", "simplemocha:all"]);
grunt.registerTask("test-jenkins", ["enable-testing-mode", "simplemocha:jenkins"]);
};
function runWebpackDevServer(cwd) {
var webpackProcess = exec("node " + webpackDevServerBin, { cwd: cwd }, function (error, stdout, stderr) {
if (error) {
console.error("(alamid) Error running webpack-dev-server: " + error);
}
});
// awesome piping
webpackProcess.stdout.pipe(process.stdout);
webpackProcess.stderr.pipe(process.stderr);
}