Tests: fix dimensions tests in testswarm
[jquery.git] / Gruntfile.js
blob94c2cdb8924afaba518dbbce33d85cca8b13cd5e
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                                         "test/jquery.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.*", included: false, served: true },
209                                         { pattern: "src/**", included: false, served: true },
210                                         { pattern: "external/**", included: false, served: true },
211                                         {
212                                                 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
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                         "ie-debug": {
244                                 browsers: [ "IE" ],
245                                 singleRun: false
246                         }
247                 },
248                 watch: {
249                         files: [ "<%= eslint.dev.src %>" ],
250                         tasks: [ "dev" ]
251                 },
252                 uglify: {
253                         all: {
254                                 files: {
255                                         "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
256                                                 "dist/<%= grunt.option('filename') %>"
257                                 },
258                                 options: {
259                                         preserveComments: false,
260                                         sourceMap: true,
261                                         sourceMapName:
262                                                 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
263                                         report: "min",
264                                         output: {
265                                                 "ascii_only": true,
267                                                 // Support: Android 4.0 only
268                                                 // UglifyJS 3 breaks Android 4.0 if this option is not enabled.
269                                                 // This is in lieu of setting ie8 for all of mangle, compress, and output
270                                                 "ie8": true
271                                         },
272                                         banner: "/*! jQuery v<%= pkg.version %> | " +
273                                                 "(c) JS Foundation and other contributors | jquery.org/license */",
274                                         compress: {
275                                                 "hoist_funs": false,
276                                                 loops: false,
278                                                 // Support: IE <11
279                                                 // typeofs transformation is unsafe for IE9-10
280                                                 // See https://github.com/mishoo/UglifyJS2/issues/2198
281                                                 typeofs: false
282                                         }
283                                 }
284                         }
285                 }
286         } );
288         // Load grunt tasks from NPM packages
289         require( "load-grunt-tasks" )( grunt );
291         // Integrate jQuery specific tasks
292         grunt.loadTasks( "build/tasks" );
294         grunt.registerTask( "lint", [
295                 "jsonlint",
297                 // Running the full eslint task without breaking it down to targets
298                 // would run the dist target first which would point to errors in the built
299                 // file, making it harder to fix them. We want to check the built file only
300                 // if we already know the source files pass the linter.
301                 "eslint:dev",
302                 "eslint:dist"
303         ] );
305         grunt.registerTask( "lint:newer", [
306                 "newer:jsonlint",
308                 // Don't replace it with just the task; see the above comment.
309                 "newer:eslint:dev",
310                 "newer:eslint:dist"
311         ] );
313         grunt.registerTask( "test:fast", "node_smoke_tests" );
314         grunt.registerTask( "test:slow", "promises_aplus_tests" );
316         grunt.registerTask( "test", [
317                 "test:fast",
318                 "test:slow"
319         ] );
321         grunt.registerTask( "dev", [
322                 "build:*:*",
323                 "newer:eslint:dev",
324                 "newer:uglify",
325                 "remove_map_comment",
326                 "dist:*",
327                 "qunit_fixture",
328                 "compare_size"
329         ] );
331         grunt.registerTask( "default", [
332                 "eslint:dev",
333                 "build:*:*",
334                 "uglify",
335                 "remove_map_comment",
336                 "dist:*",
337                 "qunit_fixture",
338                 "eslint:dist",
339                 "test:fast",
340                 "compare_size"
341         ] );