3 module.exports = function( grunt ) {
4 function readOptionalJSON( filepath ) {
5 const stripJSONComments = require( "strip-json-comments" );
8 data = JSON.parse( stripJSONComments(
9 fs.readFileSync( filepath, { encoding: "utf8" } )
15 const fs = require( "fs" );
16 const gzip = require( "gzip-js" );
17 const nodeV14OrNewer = !/^v1[0-3]\./.test( process.version );
18 const nodeV17OrNewer = !/^v1[0-6]\./.test( process.version );
19 const customBrowsers = process.env.BROWSERS && process.env.BROWSERS.split( "," );
21 // Support: Node.js <14
22 // Skip running tasks that dropped support for Node.js 10 or 12
23 // in this Node version.
24 function runIfNewNode( task ) {
25 return nodeV14OrNewer ? task : "print_old_node_message:" + task;
28 if ( nodeV14OrNewer ) {
29 const playwright = require( "playwright-webkit" );
30 process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath();
33 if ( !grunt.option( "filename" ) ) {
34 grunt.option( "filename", "jquery.js" );
38 pkg: grunt.file.readJSON( "package.json" ),
39 dst: readOptionalJSON( "dist/.destination.json" ),
41 files: [ "dist/jquery.js", "dist/jquery.min.js" ],
44 gz: function( contents ) {
45 return gzip.zip( contents, {} ).length;
48 cache: "build/.sizecache.json"
55 plugins: [ "@babel/transform-for-of" ]
59 "test/data/core/jquery-iterability-transpiled.js":
60 "test/data/core/jquery-iterability-transpiled-es6.js"
66 dest: "dist/jquery.js",
71 // Exclude specified modules if the module matching the key is removed
73 ajax: [ "manipulation/_evalUrl", "deprecated/ajax-event-alias" ],
74 callbacks: [ "deferred" ],
75 css: [ "effects", "dimensions", "offset" ],
76 "css/showHide": [ "effects" ],
78 remove: [ "ajax", "effects", "queue", "core/ready" ],
79 include: [ "core/ready-no-deferred" ]
81 event: [ "deprecated/ajax-event-alias", "deprecated/event" ],
82 selector: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
89 destPrefix: "external"
92 "core-js-bundle/core-js-bundle.js": "core-js-bundle/minified.js",
93 "core-js-bundle/LICENSE": "core-js-bundle/LICENSE",
95 "npo/npo.js": "native-promise-only/lib/npo.src.js",
97 "qunit/qunit.js": "qunit/qunit/qunit.js",
98 "qunit/qunit.css": "qunit/qunit/qunit.css",
99 "qunit/LICENSE.txt": "qunit/LICENSE.txt",
101 "requirejs/require.js": "requirejs/require.js",
103 "sinon/sinon.js": "sinon/pkg/sinon.js",
104 "sinon/LICENSE.txt": "sinon/LICENSE"
110 src: [ "package.json" ]
118 // We have to explicitly declare "src" property otherwise "newer"
119 // task wouldn't work properly :/
121 src: [ "dist/jquery.js", "dist/jquery.min.js" ]
130 // Ignore files from .eslintignore
131 // See https://github.com/sindresorhus/grunt-eslint/issues/119
133 .readFileSync( `${ __dirname }/.eslintignore`, "utf-8" )
135 .filter( filePath => filePath )
136 .map( filePath => filePath[ 0 ] === "!" ?
137 filePath.slice( 1 ) :
141 // Explicitly ignore `dist/` as it could be unignored by
142 // the above `.eslintignore` parsing.
150 // A special module with basic tests, meant for not fully
151 // supported environments like jsdom. We run it everywhere,
152 // though, to make sure tests are not broken.
179 customContextFile: "test/karma.context.html",
180 customDebugFile: "test/karma.debug.html",
182 ChromeHeadlessNoSandbox: {
183 base: "ChromeHeadless",
184 flags: [ "--no-sandbox" ]
187 frameworks: [ "qunit" ],
188 middleware: [ "mockserver" ],
192 "middleware:mockserver": [
194 require( "./test/middleware-mockserver.js" )
201 // We're running `QUnit.start()` ourselves via `loadTests()`
207 "test/data/jquery-1.9.1.js",
208 "external/sinon/sinon.js",
209 "external/npo/npo.js",
210 "external/requirejs/require.js",
211 "test/data/testinit.js",
216 pattern: "dist/jquery.*",
228 { pattern: "external/**", included: false, served: true },
230 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
236 reporters: [ "dots" ],
239 // 2 minutes; has to be longer than QUnit.config.testTimeout
240 browserNoActivityTimeout: 120e3,
243 captureTimeout: 20 * 1000,
247 browsers: customBrowsers ||
248 [ "ChromeHeadless", "FirefoxHeadless", "WebkitHeadless" ]
251 browsers: customBrowsers || [ "ChromeHeadless" ],
256 // We're running `QUnit.start()` ourselves via `loadTests()`
269 "test/data/jquery-1.9.1.js",
270 "test/data/testinit-jsdom.js",
272 // We don't support various loading methods like esmodules,
273 // choosing a version etc. for jsdom.
276 // A partial replacement for testinit.js#loadTests()
277 "test/data/testrunner.js",
279 // jsdom only runs basic tests
280 "test/unit/basic.js",
283 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
289 browsers: [ "jsdom" ]
292 // To debug tests with Karma:
293 // 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
294 // (any karma subtask that has singleRun=false)
295 // 2. Press "Debug" in the opened browser window to start
296 // the tests. Unlike the other karma tasks, the debug task will
297 // keep the browser window open.
299 browsers: [ "Chrome" ],
303 browsers: [ "Firefox" ],
312 files: [ "<%= eslint.dev.src %>" ],
318 "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
319 "dist/<%= grunt.option('filename') %>"
324 filename: "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>"
329 preamble: "/*! jQuery v<%= pkg.version %> | " +
330 "(c) OpenJS Foundation and other contributors | " +
331 "jquery.org/license */"
342 // Load grunt tasks from NPM packages
343 require( "load-grunt-tasks" )( grunt, {
344 pattern: nodeV14OrNewer ? [ "grunt-*" ] : [ "grunt-*", "!grunt-eslint" ]
347 // Integrate jQuery specific tasks
348 grunt.loadTasks( "build/tasks" );
350 grunt.registerTask( "print_old_node_message", ( ...args ) => {
351 var task = args.join( ":" );
352 grunt.log.writeln( "Old Node.js detected, running the task \"" + task + "\" skipped..." );
355 grunt.registerTask( "print_jsdom_message", () => {
356 grunt.log.writeln( "Node.js 17 or newer detected, skipping jsdom tests..." );
359 grunt.registerTask( "lint", [
362 // Running the full eslint task without breaking it down to targets
363 // would run the dist target first which would point to errors in the built
364 // file, making it harder to fix them. We want to check the built file only
365 // if we already know the source files pass the linter.
366 runIfNewNode( "eslint:dev" ),
367 runIfNewNode( "eslint:dist" )
370 grunt.registerTask( "lint:newer", [
373 // Don't replace it with just the task; see the above comment.
374 runIfNewNode( "newer:eslint:dev" ),
375 runIfNewNode( "newer:eslint:dist" )
378 grunt.registerTask( "test:fast", runIfNewNode( "node_smoke_tests" ) );
379 grunt.registerTask( "test:slow", [
380 runIfNewNode( "promises_aplus_tests" ),
382 // Support: Node.js 17+
383 // jsdom fails to connect to the Karma server in Node 17+.
384 // Until we figure out a fix, skip jsdom tests there.
385 nodeV17OrNewer ? "print_jsdom_message" : runIfNewNode( "karma:jsdom" )
388 grunt.registerTask( "test:prepare", [
394 grunt.registerTask( "test", [
400 grunt.registerTask( "dev", [
402 runIfNewNode( "newer:eslint:dev" ),
404 "remove_map_comment",
410 grunt.registerTask( "default", [
411 runIfNewNode( "eslint:dev" ),
414 "remove_map_comment",
417 runIfNewNode( "eslint:dist" ),