3 module.exports = function ( grunt ) {
4 grunt.loadNpmTasks( 'grunt-banana-checker' );
5 grunt.loadNpmTasks( 'grunt-contrib-copy' );
6 grunt.loadNpmTasks( 'grunt-eslint' );
7 grunt.loadNpmTasks( 'grunt-karma' );
8 grunt.loadNpmTasks( 'grunt-stylelint' );
10 const wgServer = process.env.MW_SERVER;
11 const wgScriptPath = process.env.MW_SCRIPT_PATH;
12 const karmaProxy = {};
14 let qunitPattern = wgServer + wgScriptPath + '/index.php?title=Special:JavaScriptTest/qunit/export';
16 // "MediaWiki" for core, or extension/skin name (e.g. "GrowthExperiments")
17 const qunitComponent = grunt.option( 'qunit-component' ) || null;
18 if ( qunitComponent ) {
19 qunitPattern = qunitPattern + '&component=' + qunitComponent;
22 karmaProxy[ wgScriptPath ] = {
23 target: wgServer + wgScriptPath,
30 extensions: [ '.js', '.json', '.vue' ],
32 fix: grunt.option( 'fix' )
38 requireLowerCase: false,
39 disallowBlankTranslations: false
41 core: 'languages/i18n/',
42 exif: 'languages/i18n/exif/',
43 api: 'includes/api/i18n/',
44 rest: 'includes/Rest/i18n/',
45 installer: 'includes/installer/i18n/',
46 paramvalidator: 'includes/libs/ParamValidator/i18n/'
50 reportNeedlessDisables: true
52 src: '{resources/src,mw-config}/**/*.{css,less,vue}'
56 '.{stylelintrc,eslintrc.json}',
58 '!{docs,extensions,node_modules,skins,vendor}/**'
66 base: 'ChromeHeadless',
67 // Chrome requires --no-sandbox in Docker/CI.
68 // WMF CI images expose CHROMIUM_FLAGS which sets that.
69 flags: ( process.env.CHROMIUM_FLAGS || '' ).split( ' ' )
74 pattern: qunitPattern,
80 logLevel: ( process.env.ZUUL_PROJECT ? 'DEBUG' : 'INFO' ),
81 frameworks: [ 'qunit' ],
82 reporters: [ 'mocha' ],
85 // Some tests in extensions don't yield for more than the default 10s (T89075)
86 browserNoActivityTimeout: 60 * 1000,
87 // Karma requires Same-Origin (or CORS) by default since v1.1.1
88 // for better stacktraces. But we load the first request from wgServer
89 crossOriginAttribute: false
92 browsers: [ 'ChromeCustom' ]
95 browsers: [ 'FirefoxHeadless' ]
100 src: 'resources/**/*',
101 dest: 'docs/js/modules',
103 rename: function ( dest, src ) {
104 return require( 'path' ).join( dest, src.replace( 'resources/', '' ) );
110 grunt.registerTask( 'assert-mw-env', function () {
112 if ( !process.env.MW_SERVER ) {
113 grunt.log.error( 'Environment variable MW_SERVER must be set.\n' +
114 'Set this like $wgServer, e.g. "http://localhost"'
118 if ( !process.env.MW_SCRIPT_PATH ) {
119 grunt.log.error( 'Environment variable MW_SCRIPT_PATH must be set.\n' +
120 'Set this like $wgScriptPath, e.g. "/w"' );
126 grunt.registerTask( 'lint', [ 'eslint', 'banana', 'stylelint' ] );
127 grunt.registerTask( 'qunit', [ 'assert-mw-env', 'karma:main' ] );