3 module.exports = function( grunt ) {
4 const nodeV16OrNewer = !/^v1[0-5]\./.test( process.version );
5 const nodeV17OrNewer = !/^v1[0-6]\./.test( process.version );
6 const customBrowsers = process.env.BROWSERS && process.env.BROWSERS.split( "," );
8 // Support: Node.js <16
9 // Skip running tasks that dropped support for old Node.js in these Node versions.
10 function runIfNewNode( task ) {
11 return nodeV16OrNewer ? task : "print_old_node_message:" + task;
14 if ( nodeV16OrNewer ) {
15 const playwright = require( "playwright-webkit" );
16 process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath();
19 if ( !grunt.option( "filename" ) ) {
20 grunt.option( "filename", "jquery.js" );
24 pkg: grunt.file.readJSON( "package.json" ),
28 // A special module with basic tests, meant for not fully
29 // supported environments like jsdom. We run it everywhere,
30 // though, to make sure tests are not broken.
57 customContextFile: "test/karma.context.html",
58 customDebugFile: "test/karma.debug.html",
60 ChromeHeadlessNoSandbox: {
61 base: "ChromeHeadless",
62 flags: [ "--no-sandbox" ]
65 frameworks: [ "qunit" ],
66 middleware: [ "mockserver" ],
70 "middleware:mockserver": [
72 require( "./test/middleware-mockserver.cjs" )
79 // We're running `QUnit.start()` ourselves via `loadTests()`
85 "test/data/jquery-1.9.1.js",
86 "external/sinon/sinon.js",
87 "external/npo/npo.js",
88 "external/requirejs/require.js",
89 "test/data/testinit.js",
93 pattern: "external/**",
99 pattern: "dist/jquery.*",
112 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
118 reporters: [ "dots" ],
121 // 2 minutes; has to be longer than QUnit.config.testTimeout
122 browserNoActivityTimeout: 120e3,
125 captureTimeout: 20 * 1000,
129 browsers: customBrowsers ||
130 [ "ChromeHeadless", "FirefoxHeadless", "WebkitHeadless" ]
133 browsers: customBrowsers || [ "ChromeHeadless" ],
138 // We're running `QUnit.start()` ourselves via `loadTests()`
151 "test/data/jquery-1.9.1.js",
152 "test/data/testinit-jsdom.js",
154 // We don't support various loading methods like esmodules,
155 // choosing a version etc. for jsdom.
158 // A partial replacement for testinit.js#loadTests()
159 "test/data/testrunner.js",
161 // jsdom only runs basic tests
162 "test/unit/basic.js",
165 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
171 browsers: [ "jsdom" ]
174 // To debug tests with Karma:
175 // 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
176 // (any karma subtask that has singleRun=false)
177 // 2. Press "Debug" in the opened browser window to start
178 // the tests. Unlike the other karma tasks, the debug task will
179 // keep the browser window open.
181 browsers: [ "Chrome" ],
185 browsers: [ "Firefox" ],
195 // Load grunt tasks from NPM packages
196 require( "load-grunt-tasks" )( grunt, {
197 pattern: [ "grunt-*" ]
200 // Integrate jQuery specific tasks
201 grunt.loadTasks( "build/grunt-tasks" );
203 grunt.registerTask( "print_old_node_message", ( ...args ) => {
204 var task = args.join( ":" );
205 grunt.log.writeln( "Old Node.js detected, running the task \"" + task + "\" skipped..." );
208 grunt.registerTask( "print_jsdom_message", () => {
209 grunt.log.writeln( "Node.js 17 or newer detected, skipping jsdom tests..." );
212 grunt.registerTask( "test:jsdom", [
214 // Support: Node.js 17+
215 // jsdom fails to connect to the Karma server in Node 17+.
216 // Until we figure out a fix, skip jsdom tests there.
217 nodeV17OrNewer ? "print_jsdom_message" : runIfNewNode( "karma:jsdom" )
220 grunt.registerTask( "test", [
224 grunt.registerTask( "default", [