1 |
|
2 |
|
3 |
|
4 | var fs = require("fs"),
|
5 | _ = require("lodash"),
|
6 | gulp = require("gulp"),
|
7 | jshint = require("gulp-jshint"),
|
8 |
|
9 |
|
10 | karma = require("gulp-karma"),
|
11 | mocha = require("gulp-mocha"),
|
12 | jade = require("gulp-jade"),
|
13 | rename = require("gulp-rename"),
|
14 | mdox = require("gulp-mdox"),
|
15 | rimraf = require("gulp-rimraf");
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var SAUCE_ENVS = {
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | sl_chrome: {
|
29 | base: "SauceLabs",
|
30 | browserName: "chrome"
|
31 | },
|
32 | sl_safari: {
|
33 | base: "SauceLabs",
|
34 | browserName: "safari",
|
35 | platform: "OS X 10.9"
|
36 | },
|
37 | sl_ie_9: {
|
38 | base: "SauceLabs",
|
39 | browserName: "internet explorer",
|
40 | platform: "Windows 7",
|
41 | version: "9"
|
42 | },
|
43 | sl_ie_10: {
|
44 | base: "SauceLabs",
|
45 | browserName: "internet explorer",
|
46 | platform: "Windows 7",
|
47 | version: "10"
|
48 | },
|
49 | sl_ie_11: {
|
50 | base: "SauceLabs",
|
51 | browserName: "internet explorer",
|
52 | platform: "Windows 7",
|
53 | version: "11"
|
54 | }
|
55 |
|
56 | };
|
57 |
|
58 |
|
59 | var SAUCE_BRANCH = process.env.TRAVIS_BRANCH || "local";
|
60 | var SAUCE_TAG = process.env.SAUCE_USERNAME + "@" + SAUCE_BRANCH;
|
61 |
|
62 |
|
63 | var KARMA_COV = {
|
64 | reporters: ["mocha", "coverage"],
|
65 | preprocessors: {
|
66 | "chai-jq.js": ["coverage"]
|
67 | },
|
68 | coverageReporter: {
|
69 | reporters: [
|
70 | { type: "json", file: "coverage.json" },
|
71 | { type: "lcov" }
|
72 | ],
|
73 | dir: "coverage/"
|
74 | }
|
75 | };
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | var _jshintCfg = function (name) {
|
82 | var raw = fs.readFileSync(name).toString();
|
83 | return JSON.parse(raw.replace(/\/\/.*\n/g, ""));
|
84 | };
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | gulp.task("jshint:frontend", function () {
|
90 | gulp
|
91 | .src([
|
92 | "test/js/adapters/karma.js",
|
93 | "*.js",
|
94 | "!gulpfile.js"
|
95 | ])
|
96 | .pipe(jshint(_jshintCfg(".jshintrc-frontend.json")))
|
97 | .pipe(jshint.reporter("default"))
|
98 | .pipe(jshint.reporter("fail"));
|
99 | });
|
100 |
|
101 | gulp.task("jshint:test", function () {
|
102 | gulp
|
103 | .src([
|
104 | "test/js/spec/**/*.js"
|
105 | ])
|
106 | .pipe(jshint(_.merge(_jshintCfg(".jshintrc-frontend.json"), {
|
107 | expr: true
|
108 | })))
|
109 | .pipe(jshint.reporter("default"))
|
110 | .pipe(jshint.reporter("fail"));
|
111 | });
|
112 |
|
113 | gulp.task("jshint:backend", function () {
|
114 | gulp
|
115 | .src([
|
116 | "*.js",
|
117 | "tasks/**/*.js",
|
118 | "test/js/adapters/node.js"
|
119 | ])
|
120 | .pipe(jshint(_jshintCfg(".jshintrc-backend.json")))
|
121 | .pipe(jshint.reporter("default"))
|
122 | .pipe(jshint.reporter("fail"));
|
123 | });
|
124 |
|
125 | gulp.task("jshint", ["jshint:frontend", "jshint:test", "jshint:backend"]);
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | process.env.PHANTOMJS_BIN = "./node_modules/.bin/phantomjs";
|
132 |
|
133 |
|
134 | var testFrontend = function () {
|
135 | var files = [
|
136 |
|
137 | "test/js/lib/sinon.js",
|
138 | "test/js/lib/jquery.js",
|
139 | "test/js/lib/chai.js",
|
140 | "chai-jq.js",
|
141 |
|
142 |
|
143 | "test/adapters/karma.js",
|
144 |
|
145 |
|
146 | "test/js/spec/chai-jq.spec.js"
|
147 | ];
|
148 |
|
149 | var opts = _.extend.apply(_, [{
|
150 | frameworks: ["mocha"],
|
151 | port: 9999,
|
152 | reporters: ["mocha"],
|
153 | client: {
|
154 | mocha: {
|
155 | ui: "bdd"
|
156 | }
|
157 | }
|
158 | }].concat(_.toArray(arguments)));
|
159 |
|
160 | return function () {
|
161 | return gulp
|
162 | .src(files)
|
163 | .pipe(karma(opts))
|
164 | .on("error", function (err) {
|
165 | throw err;
|
166 | });
|
167 | };
|
168 | };
|
169 |
|
170 | gulp.task("test:frontend:dev", testFrontend({
|
171 | singleRun: true,
|
172 | browsers: ["PhantomJS"]
|
173 | }, KARMA_COV));
|
174 |
|
175 | gulp.task("test:frontend:ci", testFrontend({
|
176 | singleRun: true,
|
177 | browsers: ["PhantomJS", "Firefox"]
|
178 | }, KARMA_COV, {
|
179 | reporters: ["mocha", "coverage", "coveralls"]
|
180 | }));
|
181 |
|
182 | gulp.task("test:frontend:sauce", testFrontend({
|
183 | singleRun: true,
|
184 | reporters: ["mocha", "saucelabs"],
|
185 | sauceLabs: {
|
186 | testName: "chai-jq - Frontend Unit Tests",
|
187 | tags: [SAUCE_TAG],
|
188 | public: "public"
|
189 | },
|
190 |
|
191 |
|
192 | captureTimeout: 0,
|
193 | customLaunchers: SAUCE_ENVS,
|
194 | browsers: Object.keys(SAUCE_ENVS)
|
195 | }));
|
196 |
|
197 | gulp.task("test:frontend:all", testFrontend({
|
198 | port: 9998,
|
199 | browsers: ["PhantomJS", "Firefox", "Chrome", "Safari"]
|
200 | }));
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | gulp.task("test:backend", function () {
|
206 | gulp
|
207 | .src("test/adapters/node.js")
|
208 | .pipe(mocha({
|
209 | ui: "bdd",
|
210 | reporter: "spec"
|
211 | }))
|
212 | .on("error", function (err) {
|
213 | throw err;
|
214 | });
|
215 | });
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | gulp.task("docs:api", function () {
|
221 | gulp
|
222 | .src("chai-jq.js")
|
223 | .pipe(mdox({
|
224 | src: "README.md",
|
225 | name: "README.md",
|
226 | start: "## Plugin API",
|
227 | end: "## Contributions"
|
228 | }))
|
229 | .pipe(gulp.dest("./"));
|
230 | });
|
231 |
|
232 | gulp.task("templates", function () {
|
233 | gulp
|
234 | .src("_templates/**/*.jade")
|
235 | .pipe(jade({
|
236 | pretty: true
|
237 | }))
|
238 | .pipe(gulp.dest("./"));
|
239 | });
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | gulp.task("copy", function () {
|
245 | gulp
|
246 | .src([
|
247 | "bower_components/mocha/mocha.js",
|
248 | "bower_components/mocha/mocha.css",
|
249 | "bower_components/chai/chai.js",
|
250 | "bower_components/jquery/dist/jquery.js",
|
251 | "bower_components/requirejs/require.js",
|
252 | "bower_components/pure/pure-min.css"
|
253 | ])
|
254 | .pipe(gulp.dest("./test/js/lib"));
|
255 |
|
256 | gulp
|
257 | .src([
|
258 | "bower_components/sinon/index.js"
|
259 | ])
|
260 | .pipe(rename({
|
261 | basename: "sinon"
|
262 | }))
|
263 | .pipe(gulp.dest("./test/js/lib"));
|
264 | });
|
265 |
|
266 |
|
267 |
|
268 |
|
269 | gulp.task("watch", function () {
|
270 | gulp.watch([
|
271 | "_templates/**/*.jade",
|
272 | "*.md",
|
273 | "chai-jq.js"
|
274 | ], ["docs:api", "templates"]);
|
275 | });
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | gulp.task("clean", function () {
|
281 | gulp
|
282 | .src([
|
283 | "coverage"
|
284 | ], { read: false })
|
285 | .pipe(rimraf());
|
286 | });
|
287 |
|
288 |
|
289 |
|
290 |
|
291 | gulp.task("check:dev", ["jshint", "test:backend", "test:frontend:dev"]);
|
292 | gulp.task("check:ci", ["jshint", "test:backend", "test:frontend:ci"]);
|
293 | gulp.task("check:all", ["jshint", "test:backend", "test:frontend:all"]);
|
294 | gulp.task("check", ["check:dev"]);
|
295 |
|
296 | gulp.task("build", ["copy", "docs:api", "templates"]);
|
297 |
|
298 | gulp.task("default", ["clean", "check", "build"]);
|