forked from ibm-js/requirejs-dplugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
181 lines (156 loc) · 3.79 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
"use strict";
module.exports = function (grunt) {
var filesList = [
"*.js",
"*.json",
"i18n/*.js",
"tests/*.js"
];
// Project configuration.
grunt.initConfig({
jshint: {
all: filesList,
options: {
jshintrc: ".jshintrc"
}
},
lineending: {
all: {
options: {
eol: "crlf",
overwrite: true
},
files: {
"": filesList
}
}
},
jsbeautifier: {
files: filesList,
options: {
config: ".jshintrc",
js: {
jslintHappy: true,
indentWithTabs: true
}
}
},
intern: {
remote: {
options: {
runType: "runner",
config: "tests/intern",
reporters: ["runner"]
}
},
local: {
options: {
runType: "runner", // defaults to "client"
config: "tests/intern.local",
reporters: ["runner"]
}
}
},
clean: {
// Delete files created by the "testBuild" target.
testBuild: [
"tests/functional/jqueryApp/{bower_components,node_modules,build,tmp}",
"tests/functional/cssApp/{bower_components,node_modules,build,tmp}"
]
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-jsbeautifier");
grunt.loadNpmTasks("grunt-lineending");
grunt.loadNpmTasks("intern");
// By default, lint and run all tests.
grunt.registerTask("default", ["jshint", "test:remote"]);
// Just lint
grunt.registerTask("lint", ["jshint"]);
// Travis build
grunt.registerTask("travis", ["jshint", "test:remote"]);
grunt.registerTask("testBuild", "Run the build used by the functional test", function (test) {
var done = this.async();
var appRootDir = "tests/functional/" + test + "App";
function npmInstall(error, bowerResults) {
if (error !== null) {
grunt.log.writeln(bowerResults.stdout);
done(error);
return;
}
grunt.util.spawn({
cmd: "npm",
args: ["install"],
opts: {
cwd: appRootDir
}
}, startBuild);
}
function startBuild(error, npmResults) {
if (error !== null) {
grunt.log.writeln(npmResults.stdout);
done(error);
return;
}
grunt.util.spawn({
cmd: "grunt",
args: ["build"],
opts: {
cwd: appRootDir
}
}, finish);
}
function finish(error, buildResults) {
if (error !== null) {
grunt.log.writeln(buildResults.stdout);
done(error);
return;
}
done(true);
}
grunt.util.spawn({
cmd: "bower",
args: ["install"],
opts: {
cwd: appRootDir
}
}, npmInstall);
});
// Testing.
// Always specify the target e.g. grunt test:remote, grunt test:remote
// then add on any other flags afterwards e.g. console, lcovhtml.
var testTaskDescription = "Run this task instead of the intern task directly! \n" +
"Always specify the test target e.g. \n" +
"grunt test:local\n" +
"grunt test:remote\n\n" +
"Add any optional reporters via a flag e.g. \n" +
"grunt test:local:console\n" +
"grunt test:local:lcovhtml\n" +
"grunt test:local:console:lcovhtml";
grunt.registerTask("test", testTaskDescription, function (target) {
function addReporter(reporter) {
var property = "intern." + target + ".options.reporters",
value = grunt.config.get(property);
if (value.indexOf(reporter) !== -1) {
return;
}
value.push(reporter);
grunt.config.set(property, value);
}
if (this.flags.lcovhtml) {
addReporter("lcovhtml");
}
if (this.flags.console) {
addReporter("console");
}
// First create the test builds. These are referenced from the intern tests.
grunt.task.run("testBuild:css");
grunt.task.run("testBuild:jquery");
// Then run the intern tests.
grunt.task.run("intern:" + target);
// Finally, delete the test builds so that they don't show up in "git status" as "untracked files".
grunt.task.run("clean:testBuild");
});
};