2022-02-07 16:09:22 +00:00
|
|
|
'use strict';
|
2014-01-31 02:03:11 +00:00
|
|
|
module.exports = function ( grunt ) {
|
2016-11-15 21:02:04 +00:00
|
|
|
grunt.loadNpmTasks( 'grunt-banana-checker' );
|
|
|
|
|
grunt.loadNpmTasks( 'grunt-eslint' );
|
|
|
|
|
grunt.loadNpmTasks( 'grunt-karma' );
|
|
|
|
|
grunt.loadNpmTasks( 'grunt-stylelint' );
|
|
|
|
|
|
2022-02-02 12:31:27 +00:00
|
|
|
const fs = require( 'fs' );
|
2022-02-02 10:00:12 +00:00
|
|
|
const wgServer = process.env.MW_SERVER;
|
|
|
|
|
const wgScriptPath = process.env.MW_SCRIPT_PATH;
|
|
|
|
|
const karmaProxy = {};
|
|
|
|
|
|
2024-03-08 20:48:11 +00:00
|
|
|
let qunitURL = wgServer + wgScriptPath + '/index.php?title=Special:JavaScriptTest/qunit/export';
|
2022-02-02 10:00:12 +00:00
|
|
|
|
|
|
|
|
// "MediaWiki" for core, or extension/skin name (e.g. "GrowthExperiments")
|
2022-02-02 12:31:27 +00:00
|
|
|
const qunitComponent = grunt.option( 'qunit-component' );
|
|
|
|
|
const qunitWatch = grunt.option( 'qunit-watch' ) || false;
|
2023-02-20 17:58:19 +00:00
|
|
|
const qunitWatchFiles = [];
|
2022-02-02 10:00:12 +00:00
|
|
|
if ( qunitComponent ) {
|
2024-03-08 20:48:11 +00:00
|
|
|
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}/**' );
|
2022-02-02 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-02 10:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
2016-12-20 15:46:20 +00:00
|
|
|
karmaProxy[ wgScriptPath ] = {
|
|
|
|
|
target: wgServer + wgScriptPath,
|
|
|
|
|
changeOrigin: true
|
|
|
|
|
};
|
2014-12-10 05:58:31 +00:00
|
|
|
|
2014-01-31 02:03:11 +00:00
|
|
|
grunt.initConfig( {
|
2016-11-15 21:02:04 +00:00
|
|
|
eslint: {
|
2018-12-14 14:22:26 +00:00
|
|
|
options: {
|
2020-03-31 01:10:31 +00:00
|
|
|
extensions: [ '.js', '.json', '.vue' ],
|
2020-05-14 21:14:42 +00:00
|
|
|
cache: true,
|
|
|
|
|
fix: grunt.option( 'fix' )
|
2018-12-14 14:22:26 +00:00
|
|
|
},
|
2020-04-22 18:15:13 +00:00
|
|
|
all: '.'
|
2014-04-17 03:42:57 +00:00
|
|
|
},
|
2014-04-10 00:25:21 +00:00
|
|
|
banana: {
|
2015-09-07 23:42:21 +00:00
|
|
|
options: {
|
2019-04-30 20:26:02 +00:00
|
|
|
requireLowerCase: false,
|
2015-10-12 18:13:48 +00:00
|
|
|
disallowBlankTranslations: false
|
2015-09-07 23:42:21 +00:00
|
|
|
},
|
2014-04-10 00:25:21 +00:00
|
|
|
core: 'languages/i18n/',
|
2024-07-01 20:34:27 +00:00
|
|
|
codex: 'languages/i18n/codex/',
|
2018-09-05 12:16:50 +00:00
|
|
|
exif: 'languages/i18n/exif/',
|
2024-04-22 04:50:10 +00:00
|
|
|
preferences: 'languages/i18n/preferences/',
|
2014-10-29 20:07:10 +00:00
|
|
|
api: 'includes/api/i18n/',
|
2019-09-22 03:30:59 +00:00
|
|
|
rest: 'includes/Rest/i18n/',
|
2019-09-12 17:44:11 +00:00
|
|
|
installer: 'includes/installer/i18n/',
|
|
|
|
|
paramvalidator: 'includes/libs/ParamValidator/i18n/'
|
2014-04-10 00:25:21 +00:00
|
|
|
},
|
2016-05-19 14:41:15 +00:00
|
|
|
stylelint: {
|
2020-11-19 22:44:55 +00:00
|
|
|
options: {
|
|
|
|
|
reportNeedlessDisables: true
|
|
|
|
|
},
|
2023-12-12 15:54:29 +00:00
|
|
|
resources: 'resources/src/**/*.{css,less,vue}',
|
|
|
|
|
config: 'mw-config/**/*.css'
|
2016-05-19 14:41:15 +00:00
|
|
|
},
|
2014-01-31 02:03:11 +00:00
|
|
|
watch: {
|
|
|
|
|
files: [
|
2023-07-04 19:32:23 +00:00
|
|
|
'.{stylelintrc,eslintrc}.json',
|
2015-07-10 03:33:09 +00:00
|
|
|
'**/*',
|
2022-07-26 22:31:50 +00:00
|
|
|
'!{extensions,node_modules,skins,vendor}/**'
|
2014-01-31 02:03:11 +00:00
|
|
|
],
|
2014-06-04 03:02:55 +00:00
|
|
|
tasks: 'test'
|
2014-12-10 05:58:31 +00:00
|
|
|
},
|
|
|
|
|
karma: {
|
|
|
|
|
options: {
|
2024-02-09 13:46:06 +00:00
|
|
|
plugins: [
|
|
|
|
|
'@wikimedia/karma-firefox-launcher',
|
|
|
|
|
'karma-*'
|
|
|
|
|
],
|
2019-01-23 23:51:49 +00:00
|
|
|
customLaunchers: {
|
|
|
|
|
ChromeCustom: {
|
|
|
|
|
base: 'ChromeHeadless',
|
|
|
|
|
// Chrome requires --no-sandbox in Docker/CI.
|
2020-03-18 18:25:17 +00:00
|
|
|
// WMF CI images expose CHROMIUM_FLAGS which sets that.
|
2023-04-25 17:15:15 +00:00
|
|
|
flags: process.env.CHROMIUM_FLAGS ? ( process.env.CHROMIUM_FLAGS || '' ).split( ' ' ) : []
|
2019-01-23 23:51:49 +00:00
|
|
|
}
|
|
|
|
|
},
|
2015-01-30 05:29:15 +00:00
|
|
|
proxies: karmaProxy,
|
2014-12-10 05:58:31 +00:00
|
|
|
files: [ {
|
2024-03-08 20:48:11 +00:00
|
|
|
pattern: qunitURL,
|
2022-02-02 10:19:51 +00:00
|
|
|
type: 'js',
|
2014-12-10 05:58:31 +00:00
|
|
|
watched: false,
|
|
|
|
|
included: true,
|
|
|
|
|
served: false
|
2024-03-08 20:48:11 +00:00
|
|
|
}, ...qunitWatchFiles.map( ( file ) => ( {
|
|
|
|
|
pattern: file,
|
|
|
|
|
type: 'js',
|
|
|
|
|
watched: true,
|
|
|
|
|
included: false,
|
|
|
|
|
served: false
|
|
|
|
|
} ) ) ],
|
2019-09-24 16:46:53 +00:00
|
|
|
logLevel: ( process.env.ZUUL_PROJECT ? 'DEBUG' : 'INFO' ),
|
2014-12-10 05:58:31 +00:00
|
|
|
frameworks: [ 'qunit' ],
|
2024-02-10 16:48:03 +00:00
|
|
|
// Disable autostart because we load modules asynchronously.
|
|
|
|
|
client: {
|
|
|
|
|
qunit: {
|
|
|
|
|
autostart: false
|
|
|
|
|
}
|
|
|
|
|
},
|
2017-03-06 20:13:04 +00:00
|
|
|
reporters: [ 'mocha' ],
|
2022-02-02 12:31:27 +00:00
|
|
|
singleRun: !qunitWatch,
|
|
|
|
|
autoWatch: qunitWatch,
|
2015-03-20 08:26:41 +00:00
|
|
|
// Some tests in extensions don't yield for more than the default 10s (T89075)
|
2017-03-20 19:25:36 +00:00
|
|
|
browserNoActivityTimeout: 60 * 1000,
|
|
|
|
|
// Karma requires Same-Origin (or CORS) by default since v1.1.1
|
|
|
|
|
// for better stacktraces. But we load the first request from wgServer
|
|
|
|
|
crossOriginAttribute: false
|
2014-12-10 05:58:31 +00:00
|
|
|
},
|
|
|
|
|
main: {
|
2023-08-10 17:31:06 +00:00
|
|
|
browsers: [ 'FirefoxHeadless' ]
|
2016-12-20 15:38:09 +00:00
|
|
|
},
|
2018-02-13 01:34:26 +00:00
|
|
|
firefox: {
|
2019-01-23 23:51:49 +00:00
|
|
|
browsers: [ 'FirefoxHeadless' ]
|
2023-08-10 17:31:06 +00:00
|
|
|
},
|
|
|
|
|
chrome: {
|
|
|
|
|
browsers: [ 'ChromeCustom' ]
|
2014-12-10 05:58:31 +00:00
|
|
|
}
|
2014-01-31 02:03:11 +00:00
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
|
2024-06-11 18:00:44 +00:00
|
|
|
grunt.registerTask( 'assert-mw-env', () => {
|
2022-02-07 16:09:22 +00:00
|
|
|
let ok = true;
|
2015-03-20 02:09:17 +00:00
|
|
|
if ( !process.env.MW_SERVER ) {
|
|
|
|
|
grunt.log.error( 'Environment variable MW_SERVER must be set.\n' +
|
|
|
|
|
'Set this like $wgServer, e.g. "http://localhost"'
|
|
|
|
|
);
|
2020-03-18 18:25:17 +00:00
|
|
|
ok = false;
|
2015-03-20 02:09:17 +00:00
|
|
|
}
|
2023-08-10 17:31:06 +00:00
|
|
|
// MW_SCRIPT_PATH= empty string is valid, e.g. for docroot installs
|
|
|
|
|
// This includes "composer serve" (Quickstart)
|
|
|
|
|
if ( process.env.MW_SCRIPT_PATH === undefined ) {
|
2015-03-20 02:09:17 +00:00
|
|
|
grunt.log.error( 'Environment variable MW_SCRIPT_PATH must be set.\n' +
|
2015-09-03 20:13:33 +00:00
|
|
|
'Set this like $wgScriptPath, e.g. "/w"' );
|
2020-03-18 18:25:17 +00:00
|
|
|
ok = false;
|
2015-03-20 02:09:17 +00:00
|
|
|
}
|
2020-03-18 18:25:17 +00:00
|
|
|
return ok;
|
2015-03-20 02:09:17 +00:00
|
|
|
} );
|
|
|
|
|
|
2016-11-15 21:02:04 +00:00
|
|
|
grunt.registerTask( 'lint', [ 'eslint', 'banana', 'stylelint' ] );
|
2023-08-10 17:31:06 +00:00
|
|
|
grunt.registerTask( 'qunit', [ 'assert-mw-env', 'karma:firefox' ] );
|
2014-01-31 02:03:11 +00:00
|
|
|
};
|