2019-10-08 22:17:55 +00:00
|
|
|
"use strict";
|
2012-10-16 14:10:17 +00:00
|
|
|
|
2019-10-08 22:17:55 +00:00
|
|
|
module.exports = function( grunt ) {
|
2023-07-10 17:14:08 +00:00
|
|
|
const nodeV16OrNewer = !/^v1[0-5]\./.test( process.version );
|
2023-01-23 22:49:44 +00:00
|
|
|
const nodeV17OrNewer = !/^v1[0-6]\./.test( process.version );
|
|
|
|
const customBrowsers = process.env.BROWSERS && process.env.BROWSERS.split( "," );
|
|
|
|
|
2023-07-10 17:14:08 +00:00
|
|
|
// Support: Node.js <16
|
|
|
|
// Skip running tasks that dropped support for old Node.js in these Node versions.
|
2021-10-29 21:43:13 +00:00
|
|
|
function runIfNewNode( task ) {
|
2023-07-10 17:14:08 +00:00
|
|
|
return nodeV16OrNewer ? task : "print_old_node_message:" + task;
|
2021-10-29 21:43:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-10 17:14:08 +00:00
|
|
|
if ( nodeV16OrNewer ) {
|
2023-01-23 22:49:44 +00:00
|
|
|
const playwright = require( "playwright-webkit" );
|
|
|
|
process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath();
|
|
|
|
}
|
2013-04-09 16:48:34 +00:00
|
|
|
|
2015-11-12 18:18:59 +00:00
|
|
|
if ( !grunt.option( "filename" ) ) {
|
|
|
|
grunt.option( "filename", "jquery.js" );
|
|
|
|
}
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
grunt.initConfig( {
|
2013-11-09 22:12:06 +00:00
|
|
|
pkg: grunt.file.readJSON( "package.json" ),
|
2012-12-13 01:19:18 +00:00
|
|
|
testswarm: {
|
2014-07-17 17:25:59 +00:00
|
|
|
tests: [
|
2015-07-29 22:54:00 +00:00
|
|
|
|
2019-04-29 20:56:09 +00:00
|
|
|
// A special module with basic tests, meant for not fully
|
|
|
|
// supported environments like jsdom. We run it everywhere,
|
|
|
|
// though, to make sure tests are not broken.
|
2015-07-29 22:54:00 +00:00
|
|
|
"basic",
|
|
|
|
|
2014-07-17 17:25:59 +00:00
|
|
|
"ajax",
|
2015-05-19 21:48:42 +00:00
|
|
|
"animation",
|
2014-07-17 17:25:59 +00:00
|
|
|
"attributes",
|
|
|
|
"callbacks",
|
|
|
|
"core",
|
|
|
|
"css",
|
|
|
|
"data",
|
|
|
|
"deferred",
|
2015-10-20 16:30:01 +00:00
|
|
|
"deprecated",
|
2014-07-17 17:25:59 +00:00
|
|
|
"dimensions",
|
|
|
|
"effects",
|
|
|
|
"event",
|
|
|
|
"manipulation",
|
|
|
|
"offset",
|
|
|
|
"queue",
|
|
|
|
"selector",
|
|
|
|
"serialize",
|
|
|
|
"support",
|
2015-05-18 21:11:21 +00:00
|
|
|
"traversing",
|
|
|
|
"tween"
|
2014-07-17 17:25:59 +00:00
|
|
|
]
|
2012-12-13 01:19:18 +00:00
|
|
|
},
|
2017-08-01 16:52:45 +00:00
|
|
|
karma: {
|
|
|
|
options: {
|
|
|
|
customContextFile: "test/karma.context.html",
|
|
|
|
customDebugFile: "test/karma.debug.html",
|
2018-03-19 17:12:23 +00:00
|
|
|
customLaunchers: {
|
|
|
|
ChromeHeadlessNoSandbox: {
|
|
|
|
base: "ChromeHeadless",
|
|
|
|
flags: [ "--no-sandbox" ]
|
|
|
|
}
|
|
|
|
},
|
2017-08-01 16:52:45 +00:00
|
|
|
frameworks: [ "qunit" ],
|
|
|
|
middleware: [ "mockserver" ],
|
|
|
|
plugins: [
|
|
|
|
"karma-*",
|
|
|
|
{
|
|
|
|
"middleware:mockserver": [
|
|
|
|
"factory",
|
2023-07-10 17:14:08 +00:00
|
|
|
require( "./test/middleware-mockserver.cjs" )
|
2017-08-01 16:52:45 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2019-12-16 18:33:49 +00:00
|
|
|
client: {
|
|
|
|
qunit: {
|
|
|
|
|
|
|
|
// We're running `QUnit.start()` ourselves via `loadTests()`
|
|
|
|
// in test/jquery.js
|
|
|
|
autostart: false
|
|
|
|
}
|
|
|
|
},
|
2017-08-01 16:52:45 +00:00
|
|
|
files: [
|
|
|
|
"test/data/jquery-1.9.1.js",
|
2021-03-24 22:36:25 +00:00
|
|
|
"external/sinon/sinon.js",
|
|
|
|
"external/npo/npo.js",
|
|
|
|
"external/requirejs/require.js",
|
2017-08-01 16:52:45 +00:00
|
|
|
"test/data/testinit.js",
|
2018-09-07 14:14:01 +00:00
|
|
|
"test/jquery.js",
|
2017-08-01 16:52:45 +00:00
|
|
|
|
2023-09-18 16:39:00 +00:00
|
|
|
{
|
|
|
|
pattern: "external/**",
|
|
|
|
included: false,
|
|
|
|
served: true,
|
|
|
|
nocache: true
|
|
|
|
},
|
2020-01-07 23:35:55 +00:00
|
|
|
{
|
|
|
|
pattern: "dist/jquery.*",
|
|
|
|
included: false,
|
|
|
|
served: true,
|
|
|
|
nocache: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "src/**",
|
|
|
|
type: "module",
|
|
|
|
included: false,
|
|
|
|
served: true,
|
|
|
|
nocache: true
|
|
|
|
},
|
2017-08-01 16:52:45 +00:00
|
|
|
{
|
2018-05-14 17:36:30 +00:00
|
|
|
pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
|
2017-08-01 16:52:45 +00:00
|
|
|
included: false,
|
2020-01-07 23:35:55 +00:00
|
|
|
served: true,
|
|
|
|
nocache: true
|
2017-08-01 16:52:45 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
reporters: [ "dots" ],
|
|
|
|
autoWatch: false,
|
2021-10-29 22:56:31 +00:00
|
|
|
|
|
|
|
// 2 minutes; has to be longer than QUnit.config.testTimeout
|
|
|
|
browserNoActivityTimeout: 120e3,
|
|
|
|
|
2017-08-01 16:52:45 +00:00
|
|
|
concurrency: 3,
|
|
|
|
captureTimeout: 20 * 1000,
|
2018-01-12 18:09:42 +00:00
|
|
|
singleRun: true
|
2017-08-01 16:52:45 +00:00
|
|
|
},
|
|
|
|
main: {
|
2023-01-23 22:49:44 +00:00
|
|
|
browsers: customBrowsers ||
|
|
|
|
[ "ChromeHeadless", "FirefoxHeadless", "WebkitHeadless" ]
|
2017-08-01 16:52:45 +00:00
|
|
|
},
|
2019-12-16 18:33:49 +00:00
|
|
|
esmodules: {
|
2023-01-23 22:49:44 +00:00
|
|
|
browsers: customBrowsers || [ "ChromeHeadless" ],
|
2019-12-16 18:33:49 +00:00
|
|
|
options: {
|
|
|
|
client: {
|
|
|
|
qunit: {
|
|
|
|
|
|
|
|
// We're running `QUnit.start()` ourselves via `loadTests()`
|
|
|
|
// in test/jquery.js
|
|
|
|
autostart: false,
|
|
|
|
|
|
|
|
esmodules: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-01-12 18:09:42 +00:00
|
|
|
|
2019-03-11 19:03:54 +00:00
|
|
|
jsdom: {
|
|
|
|
options: {
|
|
|
|
files: [
|
|
|
|
"test/data/jquery-1.9.1.js",
|
|
|
|
"test/data/testinit-jsdom.js",
|
|
|
|
|
2020-05-05 12:30:14 +00:00
|
|
|
// We don't support various loading methods like esmodules,
|
2019-03-11 19:03:54 +00:00
|
|
|
// choosing a version etc. for jsdom.
|
|
|
|
"dist/jquery.js",
|
|
|
|
|
2019-12-16 18:33:49 +00:00
|
|
|
// A partial replacement for testinit.js#loadTests()
|
2019-03-11 19:03:54 +00:00
|
|
|
"test/data/testrunner.js",
|
|
|
|
|
|
|
|
// jsdom only runs basic tests
|
|
|
|
"test/unit/basic.js",
|
|
|
|
|
|
|
|
{
|
|
|
|
pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
|
|
|
|
included: false,
|
|
|
|
served: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
browsers: [ "jsdom" ]
|
|
|
|
},
|
|
|
|
|
2018-01-12 18:09:42 +00:00
|
|
|
// To debug tests with Karma:
|
|
|
|
// 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
|
|
|
|
// (any karma subtask that has singleRun=false)
|
|
|
|
// 2. Press "Debug" in the opened browser window to start
|
|
|
|
// the tests. Unlike the other karma tasks, the debug task will
|
|
|
|
// keep the browser window open.
|
|
|
|
"chrome-debug": {
|
|
|
|
browsers: [ "Chrome" ],
|
|
|
|
singleRun: false
|
2017-08-01 16:52:45 +00:00
|
|
|
},
|
2018-01-12 18:09:42 +00:00
|
|
|
"firefox-debug": {
|
|
|
|
browsers: [ "Firefox" ],
|
|
|
|
singleRun: false
|
2018-11-12 16:49:44 +00:00
|
|
|
},
|
|
|
|
"ie-debug": {
|
|
|
|
browsers: [ "IE" ],
|
|
|
|
singleRun: false
|
2017-08-01 16:52:45 +00:00
|
|
|
}
|
2012-10-11 13:38:44 +00:00
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2012-04-18 20:07:35 +00:00
|
|
|
|
2012-12-19 04:02:50 +00:00
|
|
|
// Load grunt tasks from NPM packages
|
2021-10-29 21:43:13 +00:00
|
|
|
require( "load-grunt-tasks" )( grunt, {
|
2023-09-18 16:39:00 +00:00
|
|
|
pattern: [ "grunt-*" ]
|
2021-10-29 21:43:13 +00:00
|
|
|
} );
|
2013-08-16 13:48:00 +00:00
|
|
|
|
|
|
|
// Integrate jQuery specific tasks
|
2023-09-18 16:39:00 +00:00
|
|
|
grunt.loadTasks( "build/grunt-tasks" );
|
2012-12-19 04:02:50 +00:00
|
|
|
|
2021-10-29 21:43:13 +00:00
|
|
|
grunt.registerTask( "print_old_node_message", ( ...args ) => {
|
|
|
|
var task = args.join( ":" );
|
|
|
|
grunt.log.writeln( "Old Node.js detected, running the task \"" + task + "\" skipped..." );
|
|
|
|
} );
|
|
|
|
|
2022-03-14 16:58:41 +00:00
|
|
|
grunt.registerTask( "print_jsdom_message", () => {
|
|
|
|
grunt.log.writeln( "Node.js 17 or newer detected, skipping jsdom tests..." );
|
|
|
|
} );
|
|
|
|
|
2024-01-23 02:08:16 +00:00
|
|
|
grunt.registerTask( "authors", async function() {
|
|
|
|
const done = this.async();
|
|
|
|
const { getAuthors } = require( "./build/release/authors.js" );
|
|
|
|
const authors = await getAuthors();
|
|
|
|
console.log( authors.join( "\n" ) );
|
|
|
|
done();
|
|
|
|
} );
|
|
|
|
|
2023-09-18 16:39:00 +00:00
|
|
|
grunt.registerTask( "test:jsdom", [
|
2022-03-14 16:58:41 +00:00
|
|
|
|
|
|
|
// Support: Node.js 17+
|
|
|
|
// jsdom fails to connect to the Karma server in Node 17+.
|
|
|
|
// Until we figure out a fix, skip jsdom tests there.
|
|
|
|
nodeV17OrNewer ? "print_jsdom_message" : runIfNewNode( "karma:jsdom" )
|
2019-03-11 19:03:54 +00:00
|
|
|
] );
|
2016-07-25 23:53:57 +00:00
|
|
|
|
|
|
|
grunt.registerTask( "test", [
|
2023-09-18 16:39:00 +00:00
|
|
|
"test:jsdom"
|
2016-07-25 23:53:57 +00:00
|
|
|
] );
|
2014-09-11 20:18:34 +00:00
|
|
|
|
2016-07-11 17:21:57 +00:00
|
|
|
grunt.registerTask( "default", [
|
2023-09-18 16:39:00 +00:00
|
|
|
"test"
|
2016-07-11 17:21:57 +00:00
|
|
|
] );
|
2012-04-18 20:07:35 +00:00
|
|
|
};
|