StatusValue: Add a getter for MessageSpecifier list
[mediawiki.git] / Gruntfile.js
blobcd0fe8784f1f71b2cca3280bf1ff39485d880692
1 'use strict';
2 module.exports = function ( grunt ) {
3         grunt.loadNpmTasks( 'grunt-banana-checker' );
4         grunt.loadNpmTasks( 'grunt-eslint' );
5         grunt.loadNpmTasks( 'grunt-karma' );
6         grunt.loadNpmTasks( 'grunt-stylelint' );
8         const fs = require( 'fs' );
9         const wgServer = process.env.MW_SERVER;
10         const wgScriptPath = process.env.MW_SCRIPT_PATH;
11         const karmaProxy = {};
13         let qunitURL = wgServer + wgScriptPath + '/index.php?title=Special:JavaScriptTest/qunit/export';
15         // "MediaWiki" for core, or extension/skin name (e.g. "GrowthExperiments")
16         const qunitComponent = grunt.option( 'qunit-component' );
17         const qunitWatch = grunt.option( 'qunit-watch' ) || false;
18         const qunitWatchFiles = [];
19         if ( qunitComponent ) {
20                 qunitURL = qunitURL + '&component=' + qunitComponent;
21         }
22         if ( qunitWatch ) {
23                 if ( !qunitComponent || qunitComponent === 'MediaWiki' ) {
24                         // MediaWiki core
25                         qunitWatchFiles.push( 'tests/qunit/**' );
26                         qunitWatchFiles.push( 'resources/**' );
27                 } else {
28                         // one extension or skin
29                         const extPath = __dirname + '/extensions/' + qunitComponent + '/extension.json';
30                         const skinPath = __dirname + '/skins/' + qunitComponent + '/skin.json';
31                         // eslint-disable-next-line security/detect-non-literal-fs-filename
32                         if ( fs.existsSync( extPath ) ) {
33                                 qunitWatchFiles.push( 'extensions/' + qunitComponent + '/extension.json' );
34                                 qunitWatchFiles.push( 'extensions/' + qunitComponent + '/{modules,resources,tests}/**' );
35                         }
36                         // eslint-disable-next-line security/detect-non-literal-fs-filename
37                         if ( fs.existsSync( skinPath ) ) {
38                                 qunitWatchFiles.push( 'skins/' + qunitComponent + '/skin.json' );
39                                 qunitWatchFiles.push( 'skins/' + qunitComponent + '/{modules,resources,tests}/**' );
40                         }
41                 }
42         }
44         karmaProxy[ wgScriptPath ] = {
45                 target: wgServer + wgScriptPath,
46                 changeOrigin: true
47         };
49         grunt.initConfig( {
50                 eslint: {
51                         options: {
52                                 extensions: [ '.js', '.json', '.vue' ],
53                                 cache: true,
54                                 fix: grunt.option( 'fix' )
55                         },
56                         all: '.'
57                 },
58                 banana: {
59                         options: {
60                                 requireLowerCase: false,
61                                 disallowBlankTranslations: false
62                         },
63                         core: 'languages/i18n/',
64                         exif: 'languages/i18n/exif/',
65                         api: 'includes/api/i18n/',
66                         rest: 'includes/Rest/i18n/',
67                         installer: 'includes/installer/i18n/',
68                         paramvalidator: 'includes/libs/ParamValidator/i18n/'
69                 },
70                 stylelint: {
71                         options: {
72                                 reportNeedlessDisables: true
73                         },
74                         resources: 'resources/src/**/*.{css,less,vue}',
75                         config: 'mw-config/**/*.css'
76                 },
77                 watch: {
78                         files: [
79                                 '.{stylelintrc,eslintrc}.json',
80                                 '**/*',
81                                 '!{extensions,node_modules,skins,vendor}/**'
82                         ],
83                         tasks: 'test'
84                 },
85                 karma: {
86                         options: {
87                                 plugins: [
88                                         '@wikimedia/karma-firefox-launcher',
89                                         'karma-*'
90                                 ],
91                                 customLaunchers: {
92                                         ChromeCustom: {
93                                                 base: 'ChromeHeadless',
94                                                 // Chrome requires --no-sandbox in Docker/CI.
95                                                 // WMF CI images expose CHROMIUM_FLAGS which sets that.
96                                                 flags: process.env.CHROMIUM_FLAGS ? ( process.env.CHROMIUM_FLAGS || '' ).split( ' ' ) : []
97                                         }
98                                 },
99                                 proxies: karmaProxy,
100                                 files: [ {
101                                         pattern: qunitURL,
102                                         type: 'js',
103                                         watched: false,
104                                         included: true,
105                                         served: false
106                                 }, ...qunitWatchFiles.map( ( file ) => ( {
107                                         pattern: file,
108                                         type: 'js',
109                                         watched: true,
110                                         included: false,
111                                         served: false
112                                 } ) ) ],
113                                 logLevel: ( process.env.ZUUL_PROJECT ? 'DEBUG' : 'INFO' ),
114                                 frameworks: [ 'qunit' ],
115                                 // Disable autostart because we load modules asynchronously.
116                                 client: {
117                                         qunit: {
118                                                 autostart: false
119                                         }
120                                 },
121                                 reporters: [ 'mocha' ],
122                                 singleRun: !qunitWatch,
123                                 autoWatch: qunitWatch,
124                                 // Some tests in extensions don't yield for more than the default 10s (T89075)
125                                 browserNoActivityTimeout: 60 * 1000,
126                                 // Karma requires Same-Origin (or CORS) by default since v1.1.1
127                                 // for better stacktraces. But we load the first request from wgServer
128                                 crossOriginAttribute: false
129                         },
130                         main: {
131                                 browsers: [ 'ChromeCustom' ]
132                         },
133                         firefox: {
134                                 browsers: [ 'FirefoxHeadless' ]
135                         }
136                 }
137         } );
139         grunt.registerTask( 'assert-mw-env', function () {
140                 let ok = true;
141                 if ( !process.env.MW_SERVER ) {
142                         grunt.log.error( 'Environment variable MW_SERVER must be set.\n' +
143                                 'Set this like $wgServer, e.g. "http://localhost"'
144                         );
145                         ok = false;
146                 }
147                 if ( !process.env.MW_SCRIPT_PATH ) {
148                         grunt.log.error( 'Environment variable MW_SCRIPT_PATH must be set.\n' +
149                                 'Set this like $wgScriptPath, e.g. "/w"' );
150                         ok = false;
151                 }
152                 return ok;
153         } );
155         grunt.registerTask( 'lint', [ 'eslint', 'banana', 'stylelint' ] );
156         grunt.registerTask( 'qunit', [ 'assert-mw-env', 'karma:main' ] );