2 module.exports = function ( grunt ) {
3 grunt.loadNpmTasks( 'grunt-contrib-jshint' );
4 grunt.loadNpmTasks( 'grunt-contrib-watch' );
5 grunt.loadNpmTasks( 'grunt-banana-checker' );
6 grunt.loadNpmTasks( 'grunt-jscs' );
7 grunt.loadNpmTasks( 'grunt-jsonlint' );
8 grunt.loadNpmTasks( 'grunt-karma' );
10 var wgServer = process.env.MW_SERVER,
11 wgScriptPath = process.env.MW_SCRIPT_PATH;
14 pkg: grunt.file.readJSON( 'package.json' ),
21 '{includes,languages,resources,skins,tests}/**/*.js'
27 // Auto-generated file with JSON (double quotes)
28 '!tests/qunit/data/mediawiki.jqueryMsg.data.js',
29 // Skip functions are stored as script files but wrapped in a function when
30 // executed. node-jscs trips on the would-be "Illegal return statement".
31 '!resources/src/*-skip.js'
33 // Exclude all files ignored by jshint
34 ].concat( grunt.file.read( '.jshintignore' ).split( '\n' ).reduce( function ( patterns, pattern ) {
35 // Filter out empty lines
36 if ( pattern.length && pattern[0] !== '#' ) {
37 patterns.push( '!' + pattern );
45 '{languages,maintenance,resources}/**/*.json',
50 core: 'languages/i18n/',
51 api: 'includes/api/i18n/',
52 installer: 'includes/installer/i18n/'
57 '<%= jsonlint.all %>',
65 proxies: ( function () {
67 // Set up a proxy for requests to relative urls inside wgScriptPath. Uses a
68 // property accessor instead of plain obj[wgScriptPath] assignment as throw if
69 // unset. Running grunt normally (e.g. npm test), should not fail over this.
70 // This ensures 'npm test' works out of the box, statically, on a git clone
71 // without MediaWiki fully installed or some environment variables set.
72 Object.defineProperty( obj, wgScriptPath, {
76 grunt.fail.fatal( 'MW_SERVER is not set' );
78 if ( !wgScriptPath ) {
79 grunt.fail.fatal( 'MW_SCRIPT_PATH is not set' );
81 return wgServer + wgScriptPath;
87 pattern: wgServer + wgScriptPath + '/index.php?title=Special:JavaScriptTest/qunit/export',
92 frameworks: [ 'qunit' ],
93 reporters: [ 'dots' ],
98 browsers: [ 'Chrome' ]
101 browsers: [ 'Chrome', 'Firefox' ]
106 grunt.registerTask( 'lint', ['jshint', 'jscs', 'jsonlint', 'banana'] );
107 grunt.registerTask( 'qunit', 'karma:main' );
109 grunt.registerTask( 'test', ['lint'] );
110 grunt.registerTask( 'default', 'test' );