Tests: Make Android Browser 4.0-4.3 dimensions tests green
[jquery.git] / Gruntfile.js
blob7fa324399b084f04b22457701470589744ddb570
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;
15 var fs = require( "fs" ),
16 gzip = require( "gzip-js" ),
17 isTravis = process.env.TRAVIS,
18 oldNode = /^v6\./.test( process.version );
20 // Support: Node.js <8
21 // Skip running tasks that dropped support for Node.js 6
22 // in those Node versions.
23 function runIfNewNode( task ) {
24 return oldNode ? "print_old_node_message:" + task : task;
27 if ( !grunt.option( "filename" ) ) {
28 grunt.option( "filename", "jquery.js" );
31 grunt.initConfig( {
32 pkg: grunt.file.readJSON( "package.json" ),
33 dst: readOptionalJSON( "dist/.destination.json" ),
34 "compare_size": {
35 files: [ "dist/jquery.js", "dist/jquery.min.js" ],
36 options: {
37 compress: {
38 gz: function( contents ) {
39 return gzip.zip( contents, {} ).length;
42 cache: "build/.sizecache.json"
45 babel: {
46 options: {
47 sourceMap: "inline",
48 retainLines: true,
49 plugins: [ "@babel/transform-for-of" ]
51 nodeSmokeTests: {
52 files: {
53 "test/data/core/jquery-iterability-transpiled.js":
54 "test/data/core/jquery-iterability-transpiled-es6.js"
58 build: {
59 all: {
60 dest: "dist/jquery.js",
61 minimum: [
62 "core",
63 "selector"
66 // Exclude specified modules if the module matching the key is removed
67 removeWith: {
68 ajax: [ "manipulation/_evalUrl", "event/ajax" ],
69 callbacks: [ "deferred" ],
70 css: [ "effects", "dimensions", "offset" ],
71 "css/showHide": [ "effects" ],
72 deferred: {
73 remove: [ "ajax", "effects", "queue", "core/ready" ],
74 include: [ "core/ready-no-deferred" ]
76 sizzle: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
80 npmcopy: {
81 all: {
82 options: {
83 destPrefix: "external"
85 files: {
86 "sizzle/dist": "sizzle/dist",
87 "sizzle/LICENSE.txt": "sizzle/LICENSE.txt",
89 "npo/npo.js": "native-promise-only/npo.js",
91 "qunit/qunit.js": "qunit/qunit/qunit.js",
92 "qunit/qunit.css": "qunit/qunit/qunit.css",
93 "qunit/LICENSE.txt": "qunit/LICENSE.txt",
95 "requirejs/require.js": "requirejs/require.js",
97 "sinon/sinon.js": "sinon/pkg/sinon.js",
98 "sinon/LICENSE.txt": "sinon/LICENSE"
102 jsonlint: {
103 pkg: {
104 src: [ "package.json" ]
107 eslint: {
108 options: {
110 // See https://github.com/sindresorhus/grunt-eslint/issues/119
111 quiet: true
114 // We have to explicitly declare "src" property otherwise "newer"
115 // task wouldn't work properly :/
116 dist: {
117 src: "dist/jquery.js"
119 dev: {
120 src: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ]
123 testswarm: {
124 tests: [
126 // A special module with basic tests, meant for
127 // not fully supported environments like Android 2.3,
128 // jsdom or PhantomJS. We run it everywhere, though,
129 // to make sure tests are not broken.
130 "basic",
132 "ajax",
133 "animation",
134 "attributes",
135 "callbacks",
136 "core",
137 "css",
138 "data",
139 "deferred",
140 "deprecated",
141 "dimensions",
142 "effects",
143 "event",
144 "manipulation",
145 "offset",
146 "queue",
147 "selector",
148 "serialize",
149 "support",
150 "traversing",
151 "tween"
154 karma: {
155 options: {
156 customContextFile: "test/karma.context.html",
157 customDebugFile: "test/karma.debug.html",
158 customLaunchers: {
159 ChromeHeadlessNoSandbox: {
160 base: "ChromeHeadless",
161 flags: [ "--no-sandbox" ]
164 frameworks: [ "qunit" ],
165 middleware: [ "mockserver" ],
166 plugins: [
167 "karma-*",
169 "middleware:mockserver": [
170 "factory",
171 require( "./test/middleware-mockserver.js" )
175 files: [
176 "test/data/jquery-1.9.1.js",
177 "external/sinon/sinon.js",
178 "external/npo/npo.js",
179 "external/requirejs/require.js",
180 "test/data/testinit.js",
182 "test/jquery.js",
184 // Replacement for testinit.js#loadTests()
185 "test/data/testrunner.js",
186 "test/unit/basic.js",
187 "test/unit/core.js",
188 "test/unit/callbacks.js",
189 "test/unit/deferred.js",
190 "test/unit/deprecated.js",
191 "test/unit/support.js",
192 "test/unit/data.js",
193 "test/unit/queue.js",
194 "test/unit/attributes.js",
195 "test/unit/event.js",
196 "test/unit/selector.js",
197 "test/unit/traversing.js",
198 "test/unit/manipulation.js",
199 "test/unit/wrap.js",
200 "test/unit/css.js",
201 "test/unit/serialize.js",
202 "test/unit/ajax.js",
203 "test/unit/effects.js",
204 "test/unit/offset.js",
205 "test/unit/dimensions.js",
206 "test/unit/animation.js",
207 "test/unit/tween.js",
208 "test/unit/ready.js",
210 { pattern: "dist/jquery.*", included: false, served: true },
211 { pattern: "src/**", included: false, served: true },
212 { pattern: "external/**", included: false, served: true },
214 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
215 included: false,
216 served: true
219 reporters: [ "dots" ],
220 autoWatch: false,
221 concurrency: 3,
222 captureTimeout: 20 * 1000,
223 singleRun: true
225 main: {
227 // The Chrome sandbox doesn't work on Travis.
228 browsers: [ isTravis ? "ChromeHeadlessNoSandbox" : "ChromeHeadless" ]
231 jsdom: {
232 options: {
233 files: [
234 "test/data/jquery-1.9.1.js",
235 "test/data/testinit-jsdom.js",
237 // We don't support various loading methods like AMD,
238 // choosing a version etc. for jsdom.
239 "dist/jquery.js",
241 // Replacement for testinit.js#loadTests()
242 "test/data/testrunner.js",
244 // jsdom only runs basic tests
245 "test/unit/basic.js",
247 { pattern: "external/**", included: false, served: true },
249 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
250 included: false,
251 served: true
255 browsers: [ "jsdom" ]
258 // To debug tests with Karma:
259 // 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
260 // (any karma subtask that has singleRun=false)
261 // 2. Press "Debug" in the opened browser window to start
262 // the tests. Unlike the other karma tasks, the debug task will
263 // keep the browser window open.
264 "chrome-debug": {
265 browsers: [ "Chrome" ],
266 singleRun: false
268 "firefox-debug": {
269 browsers: [ "Firefox" ],
270 singleRun: false
272 "ie-debug": {
273 browsers: [ "IE" ],
274 singleRun: false
277 watch: {
278 files: [ "<%= eslint.dev.src %>" ],
279 tasks: [ "dev" ]
281 uglify: {
282 all: {
283 files: {
284 "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
285 "dist/<%= grunt.option('filename') %>"
287 options: {
288 preserveComments: false,
289 sourceMap: true,
290 sourceMapName:
291 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
292 report: "min",
293 output: {
294 "ascii_only": true,
296 // Support: Android 4.0 only
297 // UglifyJS 3 breaks Android 4.0 if this option is not enabled.
298 // This is in lieu of setting ie8 for all of mangle, compress, and output
299 "ie8": true
301 banner: "/*! jQuery v<%= pkg.version %> | " +
302 "(c) JS Foundation and other contributors | jquery.org/license */",
303 compress: {
304 "hoist_funs": false,
305 loops: false,
307 // Support: IE <11
308 // typeofs transformation is unsafe for IE9-10
309 // See https://github.com/mishoo/UglifyJS2/issues/2198
310 typeofs: false
315 } );
317 // Load grunt tasks from NPM packages
318 require( "load-grunt-tasks" )( grunt );
320 // Integrate jQuery specific tasks
321 grunt.loadTasks( "build/tasks" );
323 // Support: Node.js <8
324 // Print a message on Node.js <8 notifying the task is skipped there.
325 grunt.registerTask( "print_old_node_message", function() {
326 var task = [].slice.call( arguments ).join( ":" );
327 grunt.log.writeln( "Old Node.js detected, running the task \"" + task + "\" skipped..." );
328 } );
330 grunt.registerTask( "lint", [
331 "jsonlint",
333 // Running the full eslint task without breaking it down to targets
334 // would run the dist target first which would point to errors in the built
335 // file, making it harder to fix them. We want to check the built file only
336 // if we already know the source files pass the linter.
337 "eslint:dev",
338 "eslint:dist"
339 ] );
341 grunt.registerTask( "lint:newer", [
342 "newer:jsonlint",
344 // Don't replace it with just the task; see the above comment.
345 "newer:eslint:dev",
346 "newer:eslint:dist"
347 ] );
349 grunt.registerTask( "test:fast", "node_smoke_tests" );
350 grunt.registerTask( "test:slow", [
351 "promises_aplus_tests",
353 // Support: Node.js <8
354 // Karma no longer supports Node.js <8 as it relies on async-await internally.
355 runIfNewNode( "karma:jsdom" )
356 ] );
358 grunt.registerTask( "test", [
359 "test:fast",
360 "test:slow"
361 ] );
363 grunt.registerTask( "dev", [
364 "build:*:*",
365 "newer:eslint:dev",
366 "newer:uglify",
367 "remove_map_comment",
368 "dist:*",
369 "qunit_fixture",
370 "compare_size"
371 ] );
373 grunt.registerTask( "default", [
374 "eslint:dev",
375 "build:*:*",
376 "uglify",
377 "remove_map_comment",
378 "dist:*",
379 "qunit_fixture",
380 "eslint:dist",
381 "test:fast",
382 "compare_size"
383 ] );