Tests: update npo.js and include unminified source instead
[jquery.git] / Gruntfile.js
blob6f9643f466201be56b3953cb0b0d3395ce54baa9
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: [ "@babel/transform-for-of" ]
42                         },
43                         nodeSmokeTests: {
44                                 files: {
45                                         "test/data/core/jquery-iterability-transpiled.js":
46                                                 "test/data/core/jquery-iterability-transpiled-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                                 }
69                         }
70                 },
71                 npmcopy: {
72                         all: {
73                                 options: {
74                                         destPrefix: "external"
75                                 },
76                                 files: {
77                                         "npo/npo.js": "native-promise-only/lib/npo.src.js",
79                                         "qunit/qunit.js": "qunit/qunit/qunit.js",
80                                         "qunit/qunit.css": "qunit/qunit/qunit.css",
81                                         "qunit/LICENSE.txt": "qunit/LICENSE.txt",
83                                         "requirejs/require.js": "requirejs/require.js",
85                                         "sinon/sinon.js": "sinon/pkg/sinon.js",
86                                         "sinon/LICENSE.txt": "sinon/LICENSE"
87                                 }
88                         }
89                 },
90                 jsonlint: {
91                         pkg: {
92                                 src: [ "package.json" ]
93                         }
94                 },
95                 eslint: {
96                         options: {
98                                 // See https://github.com/sindresorhus/grunt-eslint/issues/119
99                                 quiet: true
100                         },
102                         // We have to explicitly declare "src" property otherwise "newer"
103                         // task wouldn't work properly :/
104                         dist: {
105                                 src: "dist/jquery.js"
106                         },
107                         dev: {
108                                 src: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ]
109                         }
110                 },
111                 testswarm: {
112                         tests: [
114                                 // A special module with basic tests, meant for not fully
115                                 // supported environments like jsdom. We run it everywhere,
116                                 // though, to make sure tests are not broken.
117                                 "basic",
119                                 "ajax",
120                                 "animation",
121                                 "attributes",
122                                 "callbacks",
123                                 "core",
124                                 "css",
125                                 "data",
126                                 "deferred",
127                                 "deprecated",
128                                 "dimensions",
129                                 "effects",
130                                 "event",
131                                 "manipulation",
132                                 "offset",
133                                 "queue",
134                                 "selector",
135                                 "serialize",
136                                 "support",
137                                 "traversing",
138                                 "tween"
139                         ]
140                 },
141                 karma: {
142                         options: {
143                                 customContextFile: "test/karma.context.html",
144                                 customDebugFile: "test/karma.debug.html",
145                                 customLaunchers: {
146                                         ChromeHeadlessNoSandbox: {
147                                                 base: "ChromeHeadless",
148                                                 flags: [ "--no-sandbox" ]
149                                         }
150                                 },
151                                 frameworks: [ "qunit" ],
152                                 middleware: [ "mockserver" ],
153                                 plugins: [
154                                         "karma-*",
155                                         {
156                                                 "middleware:mockserver": [
157                                                         "factory",
158                                                         require( "./test/middleware-mockserver.js" )
159                                                 ]
160                                         }
161                                 ],
162                                 files: [
163                                         "test/data/jquery-1.9.1.js",
164                                         "external/sinon/sinon.js",
165                                         "external/npo/npo.js",
166                                         "external/requirejs/require.js",
167                                         "test/data/testinit.js",
169                                         "test/jquery.js",
171                                         // Replacement for testinit.js#loadTests()
172                                         "test/data/testrunner.js",
173                                         "test/unit/basic.js",
174                                         "test/unit/core.js",
175                                         "test/unit/callbacks.js",
176                                         "test/unit/deferred.js",
177                                         "test/unit/deprecated.js",
178                                         "test/unit/support.js",
179                                         "test/unit/data.js",
180                                         "test/unit/queue.js",
181                                         "test/unit/attributes.js",
182                                         "test/unit/event.js",
183                                         "test/unit/selector.js",
184                                         "test/unit/traversing.js",
185                                         "test/unit/manipulation.js",
186                                         "test/unit/wrap.js",
187                                         "test/unit/css.js",
188                                         "test/unit/serialize.js",
189                                         "test/unit/ajax.js",
190                                         "test/unit/effects.js",
191                                         "test/unit/offset.js",
192                                         "test/unit/dimensions.js",
193                                         "test/unit/animation.js",
194                                         "test/unit/tween.js",
195                                         "test/unit/ready.js",
197                                         { pattern: "dist/jquery.*", included: false, served: true },
198                                         { pattern: "src/**", included: false, served: true },
199                                         { pattern: "external/**", included: false, served: true },
200                                         {
201                                                 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
202                                                 included: false,
203                                                 served: true
204                                         }
205                                 ],
206                                 reporters: [ "dots" ],
207                                 autoWatch: false,
208                                 concurrency: 3,
209                                 captureTimeout: 20 * 1000,
210                                 singleRun: true
211                         },
212                         main: {
214                                 // The Chrome sandbox doesn't work on Travis.
215                                 browsers: [ isTravis ? "ChromeHeadlessNoSandbox" : "ChromeHeadless" ]
216                         },
218                         jsdom: {
219                                 options: {
220                                         files: [
221                                                 "test/data/jquery-1.9.1.js",
222                                                 "test/data/testinit-jsdom.js",
224                                                 // We don't support various loading methods like AMD,
225                                                 // choosing a version etc. for jsdom.
226                                                 "dist/jquery.js",
228                                                 // Replacement for testinit.js#loadTests()
229                                                 "test/data/testrunner.js",
231                                                 // jsdom only runs basic tests
232                                                 "test/unit/basic.js",
234                                                 { pattern: "external/**", included: false, served: true },
235                                                 {
236                                                         pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
237                                                         included: false,
238                                                         served: true
239                                                 }
240                                         ]
241                                 },
242                                 browsers: [ "jsdom" ]
243                         },
245                         // To debug tests with Karma:
246                         // 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
247                         //    (any karma subtask that has singleRun=false)
248                         // 2. Press "Debug" in the opened browser window to start
249                         //    the tests. Unlike the other karma tasks, the debug task will
250                         //    keep the browser window open.
251                         "chrome-debug": {
252                                 browsers: [ "Chrome" ],
253                                 singleRun: false
254                         },
255                         "firefox-debug": {
256                                 browsers: [ "Firefox" ],
257                                 singleRun: false
258                         },
259                         "ie-debug": {
260                                 browsers: [ "IE" ],
261                                 singleRun: false
262                         }
263                 },
264                 watch: {
265                         files: [ "<%= eslint.dev.src %>" ],
266                         tasks: [ "dev" ]
267                 },
268                 uglify: {
269                         all: {
270                                 files: {
271                                         "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
272                                                 "dist/<%= grunt.option('filename') %>"
273                                 },
274                                 options: {
275                                         preserveComments: false,
276                                         sourceMap: true,
277                                         sourceMapName:
278                                                 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
279                                         report: "min",
280                                         output: {
281                                                 "ascii_only": true
282                                         },
283                                         banner: "/*! jQuery v<%= pkg.version %> | " +
284                                                 "(c) JS Foundation and other contributors | jquery.org/license */",
285                                         compress: {
286                                                 "hoist_funs": false,
287                                                 loops: false
288                                         }
289                                 }
290                         }
291                 }
292         } );
294         // Load grunt tasks from NPM packages
295         require( "load-grunt-tasks" )( grunt );
297         // Integrate jQuery specific tasks
298         grunt.loadTasks( "build/tasks" );
300         grunt.registerTask( "lint", [
301                 "jsonlint",
303                 // Running the full eslint task without breaking it down to targets
304                 // would run the dist target first which would point to errors in the built
305                 // file, making it harder to fix them. We want to check the built file only
306                 // if we already know the source files pass the linter.
307                 "eslint:dev",
308                 "eslint:dist"
309         ] );
311         grunt.registerTask( "lint:newer", [
312                 "newer:jsonlint",
314                 // Don't replace it with just the task; see the above comment.
315                 "newer:eslint:dev",
316                 "newer:eslint:dist"
317         ] );
319         grunt.registerTask( "test:fast", "node_smoke_tests" );
320         grunt.registerTask( "test:slow", [
321                 "promises_aplus_tests",
322                 "karma:jsdom"
323         ] );
325         grunt.registerTask( "test", [
326                 "test:fast",
327                 "test:slow"
328         ] );
330         grunt.registerTask( "dev", [
331                 "build:*:*",
332                 "newer:eslint:dev",
333                 "newer:uglify",
334                 "remove_map_comment",
335                 "dist:*",
336                 "qunit_fixture",
337                 "compare_size"
338         ] );
340         grunt.registerTask( "default", [
341                 "eslint:dev",
342                 "build:*:*",
343                 "uglify",
344                 "remove_map_comment",
345                 "dist:*",
346                 "qunit_fixture",
347                 "eslint:dist",
348                 "test:fast",
349                 "compare_size"
350         ] );