CSS: Fix reliableTrDimensions support test for initially hidden iframes
[jquery.git] / Gruntfile.cjs
blobf2f04d53601af197ac69c64f2ea613a0852450cc
1 "use strict";
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;
12         }
14         if ( nodeV16OrNewer ) {
15                 const playwright = require( "playwright-webkit" );
16                 process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath();
17         }
19         if ( !grunt.option( "filename" ) ) {
20                 grunt.option( "filename", "jquery.js" );
21         }
23         grunt.initConfig( {
24                 pkg: grunt.file.readJSON( "package.json" ),
25                 testswarm: {
26                         tests: [
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.
31                                 "basic",
33                                 "ajax",
34                                 "animation",
35                                 "attributes",
36                                 "callbacks",
37                                 "core",
38                                 "css",
39                                 "data",
40                                 "deferred",
41                                 "deprecated",
42                                 "dimensions",
43                                 "effects",
44                                 "event",
45                                 "manipulation",
46                                 "offset",
47                                 "queue",
48                                 "selector",
49                                 "serialize",
50                                 "support",
51                                 "traversing",
52                                 "tween"
53                         ]
54                 },
55                 karma: {
56                         options: {
57                                 customContextFile: "test/karma.context.html",
58                                 customDebugFile: "test/karma.debug.html",
59                                 customLaunchers: {
60                                         ChromeHeadlessNoSandbox: {
61                                                 base: "ChromeHeadless",
62                                                 flags: [ "--no-sandbox" ]
63                                         }
64                                 },
65                                 frameworks: [ "qunit" ],
66                                 middleware: [ "mockserver" ],
67                                 plugins: [
68                                         "karma-*",
69                                         {
70                                                 "middleware:mockserver": [
71                                                         "factory",
72                                                         require( "./test/middleware-mockserver.cjs" )
73                                                 ]
74                                         }
75                                 ],
76                                 client: {
77                                         qunit: {
79                                                 // We're running `QUnit.start()` ourselves via `loadTests()`
80                                                 // in test/jquery.js
81                                                 autostart: false
82                                         }
83                                 },
84                                 files: [
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",
90                                         "test/jquery.js",
92                                         {
93                                                 pattern: "external/**",
94                                                 included: false,
95                                                 served: true,
96                                                 nocache: true
97                                         },
98                                         {
99                                                 pattern: "dist/jquery.*",
100                                                 included: false,
101                                                 served: true,
102                                                 nocache: true
103                                         },
104                                         {
105                                                 pattern: "src/**",
106                                                 type: "module",
107                                                 included: false,
108                                                 served: true,
109                                                 nocache: true
110                                         },
111                                         {
112                                                 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
113                                                 included: false,
114                                                 served: true,
115                                                 nocache: true
116                                         }
117                                 ],
118                                 reporters: [ "dots" ],
119                                 autoWatch: false,
121                                 // 2 minutes; has to be longer than QUnit.config.testTimeout
122                                 browserNoActivityTimeout: 120e3,
124                                 concurrency: 3,
125                                 captureTimeout: 20 * 1000,
126                                 singleRun: true
127                         },
128                         main: {
129                                 browsers: customBrowsers ||
130                                         [ "ChromeHeadless", "FirefoxHeadless", "WebkitHeadless" ]
131                         },
132                         esmodules: {
133                                 browsers: customBrowsers || [ "ChromeHeadless" ],
134                                 options: {
135                                         client: {
136                                                 qunit: {
138                                                         // We're running `QUnit.start()` ourselves via `loadTests()`
139                                                         // in test/jquery.js
140                                                         autostart: false,
142                                                         esmodules: true
143                                                 }
144                                         }
145                                 }
146                         },
148                         jsdom: {
149                                 options: {
150                                         files: [
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.
156                                                 "dist/jquery.js",
158                                                 // A partial replacement for testinit.js#loadTests()
159                                                 "test/data/testrunner.js",
161                                                 // jsdom only runs basic tests
162                                                 "test/unit/basic.js",
164                                                 {
165                                                         pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
166                                                         included: false,
167                                                         served: true
168                                                 }
169                                         ]
170                                 },
171                                 browsers: [ "jsdom" ]
172                         },
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.
180                         "chrome-debug": {
181                                 browsers: [ "Chrome" ],
182                                 singleRun: false
183                         },
184                         "firefox-debug": {
185                                 browsers: [ "Firefox" ],
186                                 singleRun: false
187                         },
188                         "ie-debug": {
189                                 browsers: [ "IE" ],
190                                 singleRun: false
191                         }
192                 }
193         } );
195         // Load grunt tasks from NPM packages
196         require( "load-grunt-tasks" )( grunt, {
197                 pattern: [ "grunt-*" ]
198         } );
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..." );
206         } );
208         grunt.registerTask( "print_jsdom_message", () => {
209                 grunt.log.writeln( "Node.js 17 or newer detected, skipping jsdom tests..." );
210         } );
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" )
218         ] );
220         grunt.registerTask( "test", [
221                 "test:jsdom"
222         ] );
224         grunt.registerTask( "default", [
225                 "test"
226         ] );