diff options
author | Timo Tijhof <krinkle@fastmail.com> | 2024-03-08 20:48:11 +0000 |
---|---|---|
committer | Krinkle <krinkle@fastmail.com> | 2024-03-27 02:08:08 +0000 |
commit | 4d7244a4664ae07f73daa28fd13a0a7c65c91178 (patch) | |
tree | adb0b3423a6ded187776262cffdcb24f115bf289 /Gruntfile.js | |
parent | 8e10138d93f93b78102e788c23a10608505f8ad7 (diff) | |
download | mediawikicore-4d7244a4664ae07f73daa28fd13a0a7c65c91178.tar.gz mediawikicore-4d7244a4664ae07f73daa28fd13a0a7c65c91178.zip |
build: Simplify --qunit-watch logic
* Remove limitation to `.js` files, so that edits to Resources.php
and any .json files are considered as well.
* Add watching of the skin.json and extension.json file itself.
* Allow `--qunit-watch` to work without `--qunit-component`,
defaulting to watching MediaWiki core.
I would have liked to widen this to simply watch `extensions/**` and
`skins/**` by default (and when component != MediaWiki core), because
that way it will also re-run automatically after changes in an
extension dependency (e.g. from core to an extension, or
from a dependency like EventLogging to NavigationTiming). However,
Karma uses the popular "chokadir" which ironically chokes and runs out
of available operating system file handles in an attempt to crawl and
watch every file recursively. This unlike qunit-cli which uses
node-watch and the Node.js 12+ native file watcher API. Perhaps for
something to revisit in the future.
Change-Id: I2bb7f0df510f84872a2381bdebe3f2b59cc80705
Diffstat (limited to 'Gruntfile.js')
-rw-r--r-- | Gruntfile.js | 75 |
1 files changed, 29 insertions, 46 deletions
diff --git a/Gruntfile.js b/Gruntfile.js index 4bc509561611..cd0fe8784f1f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -6,61 +6,38 @@ module.exports = function ( grunt ) { grunt.loadNpmTasks( 'grunt-stylelint' ); const fs = require( 'fs' ); - const path = require( 'path' ); const wgServer = process.env.MW_SERVER; const wgScriptPath = process.env.MW_SCRIPT_PATH; const karmaProxy = {}; - let qunitPattern = wgServer + wgScriptPath + '/index.php?title=Special:JavaScriptTest/qunit/export'; + let qunitURL = wgServer + wgScriptPath + '/index.php?title=Special:JavaScriptTest/qunit/export'; // "MediaWiki" for core, or extension/skin name (e.g. "GrowthExperiments") const qunitComponent = grunt.option( 'qunit-component' ); const qunitWatch = grunt.option( 'qunit-watch' ) || false; const qunitWatchFiles = []; if ( qunitComponent ) { - let qunitWatchSourcePattern; - let qunitWatchTestPattern; - qunitPattern = qunitPattern + '&component=' + qunitComponent; - if ( qunitWatch ) { - // Special-case MediaWiki core. - if ( qunitComponent === 'MediaWiki' ) { - qunitWatchTestPattern = 'tests/qunit/**/*.js'; - qunitWatchSourcePattern = 'resources/**/*.js'; - } else { - let settingsJson, - basePath; - try { - basePath = 'extensions'; - // eslint-disable-next-line security/detect-non-literal-fs-filename - settingsJson = fs.readFileSync( - path.resolve( __dirname + '/' + basePath + '/' + qunitComponent + '/extension.json' ) - ); - } catch ( e ) { - basePath = 'skins'; - // eslint-disable-next-line security/detect-non-literal-fs-filename - settingsJson = fs.readFileSync( - path.resolve( __dirname + '/' + basePath + '/' + qunitComponent + '/skin.json' ) - ); - } - settingsJson = JSON.parse( settingsJson ); - qunitWatchSourcePattern = - path.resolve( __dirname + '/' + basePath + '/' + qunitComponent + '/' + settingsJson.ResourceFileModulePaths.localBasePath + '/**/*.js' ); - qunitWatchTestPattern = path.resolve( __dirname + '/' + basePath + '/' + qunitComponent + '/tests/qunit/**/*.js' ); + qunitURL = qunitURL + '&component=' + qunitComponent; + } + if ( qunitWatch ) { + if ( !qunitComponent || qunitComponent === 'MediaWiki' ) { + // MediaWiki core + qunitWatchFiles.push( 'tests/qunit/**' ); + qunitWatchFiles.push( 'resources/**' ); + } else { + // one extension or skin + const extPath = __dirname + '/extensions/' + qunitComponent + '/extension.json'; + const skinPath = __dirname + '/skins/' + qunitComponent + '/skin.json'; + // eslint-disable-next-line security/detect-non-literal-fs-filename + if ( fs.existsSync( extPath ) ) { + qunitWatchFiles.push( 'extensions/' + qunitComponent + '/extension.json' ); + qunitWatchFiles.push( 'extensions/' + qunitComponent + '/{modules,resources,tests}/**' ); + } + // eslint-disable-next-line security/detect-non-literal-fs-filename + if ( fs.existsSync( skinPath ) ) { + qunitWatchFiles.push( 'skins/' + qunitComponent + '/skin.json' ); + qunitWatchFiles.push( 'skins/' + qunitComponent + '/{modules,resources,tests}/**' ); } - qunitWatchFiles.push( { - pattern: qunitWatchSourcePattern, - type: 'js', - watched: true, - included: false, - served: false - } ); - qunitWatchFiles.push( { - pattern: qunitWatchTestPattern, - type: 'js', - watched: true, - included: false, - served: false - } ); } } @@ -121,12 +98,18 @@ module.exports = function ( grunt ) { }, proxies: karmaProxy, files: [ { - pattern: qunitPattern, + pattern: qunitURL, type: 'js', watched: false, included: true, served: false - }, ...qunitWatchFiles ], + }, ...qunitWatchFiles.map( ( file ) => ( { + pattern: file, + type: 'js', + watched: true, + included: false, + served: false + } ) ) ], logLevel: ( process.env.ZUUL_PROJECT ? 'DEBUG' : 'INFO' ), frameworks: [ 'qunit' ], // Disable autostart because we load modules asynchronously. |