6 module.exports = function ( grunt ) {
7 grunt.loadNpmTasks( 'grunt-contrib-jshint' );
8 grunt.loadNpmTasks( 'grunt-contrib-watch' );
9 grunt.loadNpmTasks( 'grunt-banana-checker' );
10 grunt.loadNpmTasks( 'grunt-jscs' );
11 grunt.loadNpmTasks( 'grunt-jsonlint' );
12 grunt.loadNpmTasks( 'grunt-karma' );
14 grunt.file.setBase( __dirname + '/../..' );
16 var wgServer = process.env.MW_SERVER,
17 wgScriptPath = process.env.MW_SCRIPT_PATH;
20 pkg: grunt.file.readJSON( __dirname + '/package.json' ),
27 '{includes,languages,resources,skins,tests}/**/*.js'
33 // Auto-generated file with JSON (double quotes)
34 '!tests/qunit/data/mediawiki.jqueryMsg.data.js',
35 // Skip functions are stored as script files but wrapped in a function when
36 // executed. node-jscs trips on the would-be "Illegal return statement".
37 '!resources/src/*-skip.js'
39 // Exclude all files ignored by jshint
40 ].concat( grunt.file.read( '.jshintignore' ).split( '\n' ).reduce( function ( patterns, pattern ) {
41 // Filter out empty lines
42 if ( pattern.length && pattern[0] !== '#' ) {
43 patterns.push( '!' + pattern );
51 '{languages,maintenance,resources}/**/*.json',
52 'tests/frontend/package.json'
56 core: 'languages/i18n/',
57 api: 'includes/api/i18n/',
58 installer: 'includes/installer/i18n/'
63 '<%= jsonlint.all %>',
71 proxies: ( function () {
73 // Set up a proxy for requests to relative urls inside wgScriptPath. Uses a
74 // property accessor instead of plain obj[wgScriptPath] assignment as throw if
75 // unset. Running grunt normally (e.g. npm test), should not fail over this.
76 // This ensures 'npm test' works out of the box, statically, on a git clone
77 // without MediaWiki fully installed or some environment variables set.
78 Object.defineProperty( obj, wgScriptPath, {
82 grunt.fail.fatal( 'MW_SERVER is not set' );
84 if ( !wgScriptPath ) {
85 grunt.fail.fatal( 'MW_SCRIPT_PATH is not set' );
87 return wgServer + wgScriptPath;
93 pattern: wgServer + wgScriptPath + '/index.php?title=Special:JavaScriptTest/qunit/export',
98 frameworks: [ 'qunit' ],
99 reporters: [ 'dots' ],
104 browsers: [ 'Chrome' ]
107 browsers: [ 'Chrome', 'Firefox' ]
112 grunt.registerTask( 'lint', ['jshint', 'jscs', 'jsonlint', 'banana'] );
113 grunt.registerTask( 'qunit', 'karma:main' );
115 grunt.registerTask( 'test', ['lint'] );
116 grunt.registerTask( 'default', 'test' );