CSS: Correctly detect scrollbox support with non-default zoom
[jquery.git] / Gruntfile.js
blobfbf9b56717a49ebcf940f54c544899752ba644b7
1 module.exports = function( grunt ) {
2         "use strict";
4         function readOptionalJSON( filepath ) {
5                 var stripJSONComments = require( "strip-json-comments" ),
6                         data = {};
7                 try {
8                         data = JSON.parse( stripJSONComments(
9                                 fs.readFileSync( filepath, { encoding: "utf8" } )
10                         ) );
11                 } catch ( e ) {}
12                 return data;
13         }
15         var fs = require( "fs" ),
16                 gzip = require( "gzip-js" ),
17                 isTravis = process.env.TRAVIS;
19         if ( !grunt.option( "filename" ) ) {
20                 grunt.option( "filename", "jquery.js" );
21         }
23         grunt.initConfig( {
24                 pkg: grunt.file.readJSON( "package.json" ),
25                 dst: readOptionalJSON( "dist/.destination.json" ),
26                 "compare_size": {
27                         files: [ "dist/jquery.js", "dist/jquery.min.js" ],
28                         options: {
29                                 compress: {
30                                         gz: function( contents ) {
31                                                 return gzip.zip( contents, {} ).length;
32                                         }
33                                 },
34                                 cache: "build/.sizecache.json"
35                         }
36                 },
37                 babel: {
38                         options: {
39                                 sourceMap: "inline",
40                                 retainLines: true,
41                                 plugins: [ "transform-es2015-for-of" ]
42                         },
43                         nodeSmokeTests: {
44                                 files: {
45                                         "test/node_smoke_tests/lib/ensure_iterability.js":
46                                                 "test/node_smoke_tests/lib/ensure_iterability_es6.js"
47                                 }
48                         }
49                 },
50                 build: {
51                         all: {
52                                 dest: "dist/jquery.js",
53                                 minimum: [
54                                         "core",
55                                         "selector"
56                                 ],
58                                 // Exclude specified modules if the module matching the key is removed
59                                 removeWith: {
60                                         ajax: [ "manipulation/_evalUrl", "event/ajax" ],
61                                         callbacks: [ "deferred" ],
62                                         css: [ "effects", "dimensions", "offset" ],
63                                         "css/showHide": [ "effects" ],
64                                         deferred: {
65                                                 remove: [ "ajax", "effects", "queue", "core/ready" ],
66                                                 include: [ "core/ready-no-deferred" ]
67                                         },
68                                         sizzle: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
69                                 }
70                         }
71                 },
72                 npmcopy: {
73                         all: {
74                                 options: {
75                                         destPrefix: "external"
76                                 },
77                                 files: {
78                                         "sizzle/dist": "sizzle/dist",
79                                         "sizzle/LICENSE.txt": "sizzle/LICENSE.txt",
81                                         "npo/npo.js": "native-promise-only/npo.js",
83                                         "qunit/qunit.js": "qunitjs/qunit/qunit.js",
84                                         "qunit/qunit.css": "qunitjs/qunit/qunit.css",
85                                         "qunit/LICENSE.txt": "qunitjs/LICENSE.txt",
87                                         "qunit-assert-step/qunit-assert-step.js":
88                                         "qunit-assert-step/qunit-assert-step.js",
89                                         "qunit-assert-step/MIT-LICENSE.txt":
90                                         "qunit-assert-step/MIT-LICENSE.txt",
92                                         "requirejs/require.js": "requirejs/require.js",
94                                         "sinon/sinon.js": "sinon/pkg/sinon.js",
95                                         "sinon/LICENSE.txt": "sinon/LICENSE"
96                                 }
97                         }
98                 },
99                 jsonlint: {
100                         pkg: {
101                                 src: [ "package.json" ]
102                         }
103                 },
104                 eslint: {
105                         options: {
107                                 // See https://github.com/sindresorhus/grunt-eslint/issues/119
108                                 quiet: true
109                         },
111                         // We have to explicitly declare "src" property otherwise "newer"
112                         // task wouldn't work properly :/
113                         dist: {
114                                 src: "dist/jquery.js"
115                         },
116                         dev: {
117                                 src: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ]
118                         }
119                 },
120                 testswarm: {
121                         tests: [
123                                 // A special module with basic tests, meant for
124                                 // not fully supported environments like Android 2.3,
125                                 // jsdom or PhantomJS. We run it everywhere, though,
126                                 // to make sure tests are not broken.
127                                 "basic",
129                                 "ajax",
130                                 "animation",
131                                 "attributes",
132                                 "callbacks",
133                                 "core",
134                                 "css",
135                                 "data",
136                                 "deferred",
137                                 "deprecated",
138                                 "dimensions",
139                                 "effects",
140                                 "event",
141                                 "manipulation",
142                                 "offset",
143                                 "queue",
144                                 "selector",
145                                 "serialize",
146                                 "support",
147                                 "traversing",
148                                 "tween"
149                         ]
150                 },
151                 karma: {
152                         options: {
153                                 customContextFile: "test/karma.context.html",
154                                 customDebugFile: "test/karma.debug.html",
155                                 customLaunchers: {
156                                         ChromeHeadlessNoSandbox: {
157                                                 base: "ChromeHeadless",
158                                                 flags: [ "--no-sandbox" ]
159                                         }
160                                 },
161                                 frameworks: [ "qunit" ],
162                                 middleware: [ "mockserver" ],
163                                 plugins: [
164                                         "karma-*",
165                                         {
166                                                 "middleware:mockserver": [
167                                                         "factory",
168                                                         require( "./test/middleware-mockserver.js" )
169                                                 ]
170                                         }
171                                 ],
172                                 files: [
173                                         "test/data/jquery-1.9.1.js",
174                                         "external/qunit-assert-step/qunit-assert-step.js",
175                                         "external/sinon/sinon.js",
176                                         "external/npo/npo.js",
177                                         "external/requirejs/require.js",
178                                         "test/data/testinit.js",
180                                         "dist/jquery.min.js",
182                                         // Replacement for testinit.js#loadTests()
183                                         "test/data/testrunner.js",
184                                         "test/unit/basic.js",
185                                         "test/unit/core.js",
186                                         "test/unit/callbacks.js",
187                                         "test/unit/deferred.js",
188                                         "test/unit/deprecated.js",
189                                         "test/unit/support.js",
190                                         "test/unit/data.js",
191                                         "test/unit/queue.js",
192                                         "test/unit/attributes.js",
193                                         "test/unit/event.js",
194                                         "test/unit/selector.js",
195                                         "test/unit/traversing.js",
196                                         "test/unit/manipulation.js",
197                                         "test/unit/wrap.js",
198                                         "test/unit/css.js",
199                                         "test/unit/serialize.js",
200                                         "test/unit/ajax.js",
201                                         "test/unit/effects.js",
202                                         "test/unit/offset.js",
203                                         "test/unit/dimensions.js",
204                                         "test/unit/animation.js",
205                                         "test/unit/tween.js",
206                                         "test/unit/ready.js",
208                                         { pattern: "dist/jquery.js", included: false, served: true },
209                                         { pattern: "dist/*.map", included: false, served: true },
210                                         { pattern: "external/qunit/qunit.css", included: false, served: true },
211                                         {
212                                                 pattern: "test/**/*.@(js|css|jpg|html|xml)",
213                                                 included: false,
214                                                 served: true
215                                         }
216                                 ],
217                                 reporters: [ "dots" ],
218                                 autoWatch: false,
219                                 concurrency: 3,
220                                 captureTimeout: 20 * 1000,
221                                 singleRun: true
222                         },
223                         main: {
225                                 // The Chrome sandbox doesn't work on Travis.
226                                 browsers: [ isTravis ? "ChromeHeadlessNoSandbox" : "ChromeHeadless" ]
227                         },
229                         // To debug tests with Karma:
230                         // 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
231                         //    (any karma subtask that has singleRun=false)
232                         // 2. Press "Debug" in the opened browser window to start
233                         //    the tests. Unlike the other karma tasks, the debug task will
234                         //    keep the browser window open.
235                         "chrome-debug": {
236                                 browsers: [ "Chrome" ],
237                                 singleRun: false
238                         },
239                         "firefox-debug": {
240                                 browsers: [ "Firefox" ],
241                                 singleRun: false
242                         }
243                 },
244                 watch: {
245                         files: [ "<%= eslint.dev.src %>" ],
246                         tasks: [ "dev" ]
247                 },
248                 uglify: {
249                         all: {
250                                 files: {
251                                         "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
252                                                 "dist/<%= grunt.option('filename') %>"
253                                 },
254                                 options: {
255                                         preserveComments: false,
256                                         sourceMap: true,
257                                         sourceMapName:
258                                                 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
259                                         report: "min",
260                                         output: {
261                                                 "ascii_only": true,
263                                                 // Support: Android 4.0 only
264                                                 // UglifyJS 3 breaks Android 4.0 if this option is not enabled.
265                                                 // This is in lieu of setting ie8 for all of mangle, compress, and output
266                                                 "ie8": true
267                                         },
268                                         banner: "/*! jQuery v<%= pkg.version %> | " +
269                                                 "(c) JS Foundation and other contributors | jquery.org/license */",
270                                         compress: {
271                                                 "hoist_funs": false,
272                                                 loops: false,
274                                                 // Support: IE <11
275                                                 // typeofs transformation is unsafe for IE9-10
276                                                 // See https://github.com/mishoo/UglifyJS2/issues/2198
277                                                 typeofs: false
278                                         }
279                                 }
280                         }
281                 }
282         } );
284         // Load grunt tasks from NPM packages
285         require( "load-grunt-tasks" )( grunt );
287         // Integrate jQuery specific tasks
288         grunt.loadTasks( "build/tasks" );
290         grunt.registerTask( "lint", [
291                 "jsonlint",
293                 // Running the full eslint task without breaking it down to targets
294                 // would run the dist target first which would point to errors in the built
295                 // file, making it harder to fix them. We want to check the built file only
296                 // if we already know the source files pass the linter.
297                 "eslint:dev",
298                 "eslint:dist"
299         ] );
301         grunt.registerTask( "lint:newer", [
302                 "newer:jsonlint",
304                 // Don't replace it with just the task; see the above comment.
305                 "newer:eslint:dev",
306                 "newer:eslint:dist"
307         ] );
309         grunt.registerTask( "test:fast", "node_smoke_tests" );
310         grunt.registerTask( "test:slow", "promises_aplus_tests" );
312         grunt.registerTask( "test", [
313                 "test:fast",
314                 "test:slow"
315         ] );
317         grunt.registerTask( "dev", [
318                 "build:*:*",
319                 "newer:eslint:dev",
320                 "newer:uglify",
321                 "remove_map_comment",
322                 "dist:*",
323                 "qunit_fixture",
324                 "compare_size"
325         ] );
327         grunt.registerTask( "default", [
328                 "eslint:dev",
329                 "build:*:*",
330                 "uglify",
331                 "remove_map_comment",
332                 "dist:*",
333                 "qunit_fixture",
334                 "eslint:dist",
335                 "test:fast",
336                 "compare_size"
337         ] );