ManualLogEntry::getComment() should always return string
[mediawiki.git] / Gruntfile.js
blob95c703bb2982a0cddfa2e4559fb9f72bc5f96294
1 'use strict';
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;
20         }
22         karmaProxy[ wgScriptPath ] = {
23                 target: wgServer + wgScriptPath,
24                 changeOrigin: true
25         };
27         grunt.initConfig( {
28                 eslint: {
29                         options: {
30                                 extensions: [ '.js', '.json', '.vue' ],
31                                 cache: true,
32                                 fix: grunt.option( 'fix' )
33                         },
34                         all: '.'
35                 },
36                 banana: {
37                         options: {
38                                 requireLowerCase: false,
39                                 disallowBlankTranslations: false
40                         },
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/'
47                 },
48                 stylelint: {
49                         options: {
50                                 reportNeedlessDisables: true
51                         },
52                         src: '{resources/src,mw-config}/**/*.{css,less,vue}'
53                 },
54                 watch: {
55                         files: [
56                                 '.{stylelintrc,eslintrc.json}',
57                                 '**/*',
58                                 '!{docs,extensions,node_modules,skins,vendor}/**'
59                         ],
60                         tasks: 'test'
61                 },
62                 karma: {
63                         options: {
64                                 customLaunchers: {
65                                         ChromeCustom: {
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( ' ' )
70                                         }
71                                 },
72                                 proxies: karmaProxy,
73                                 files: [ {
74                                         pattern: qunitPattern,
75                                         type: 'js',
76                                         watched: false,
77                                         included: true,
78                                         served: false
79                                 } ],
80                                 logLevel: ( process.env.ZUUL_PROJECT ? 'DEBUG' : 'INFO' ),
81                                 frameworks: [ 'qunit' ],
82                                 reporters: [ 'mocha' ],
83                                 singleRun: true,
84                                 autoWatch: false,
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
90                         },
91                         main: {
92                                 browsers: [ 'ChromeCustom' ]
93                         },
94                         firefox: {
95                                 browsers: [ 'FirefoxHeadless' ]
96                         }
97                 },
98                 copy: {
99                         jsduck: {
100                                 src: 'resources/**/*',
101                                 dest: 'docs/js/modules',
102                                 expand: true,
103                                 rename: function ( dest, src ) {
104                                         return require( 'path' ).join( dest, src.replace( 'resources/', '' ) );
105                                 }
106                         }
107                 }
108         } );
110         grunt.registerTask( 'assert-mw-env', function () {
111                 let ok = true;
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"'
115                         );
116                         ok = false;
117                 }
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"' );
121                         ok = false;
122                 }
123                 return ok;
124         } );
126         grunt.registerTask( 'lint', [ 'eslint', 'banana', 'stylelint' ] );
127         grunt.registerTask( 'qunit', [ 'assert-mw-env', 'karma:main' ] );