Implement extension registration from an extension.json file
[mediawiki.git] / tests / frontend / Gruntfile.js
blobfd89e56bfe1a96c3ca4b778285544bb01d1b93c9
1 /*!
2  * Grunt file
3  */
5 /*jshint node:true */
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;
19         grunt.initConfig( {
20                 pkg: grunt.file.readJSON( __dirname + '/package.json' ),
21                 jshint: {
22                         options: {
23                                 jshintrc: true
24                         },
25                         all: [
26                                 '*.js',
27                                 '{includes,languages,resources,skins,tests}/**/*.js'
28                         ]
29                 },
30                 jscs: {
31                         all: [
32                                 '<%= jshint.all %>',
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 );
44                                 }
45                                 return patterns;
46                         }, [] ) )
47                 },
48                 jsonlint: {
49                         all: [
50                                 '.jscsrc',
51                                 '{languages,maintenance,resources}/**/*.json',
52                                 'tests/frontend/package.json'
53                         ]
54                 },
55                 banana: {
56                         core: 'languages/i18n/',
57                         api: 'includes/api/i18n/',
58                         installer: 'includes/installer/i18n/'
59                 },
60                 watch: {
61                         files: [
62                                 '<%= jscs.all %>',
63                                 '<%= jsonlint.all %>',
64                                 '.jshintignore',
65                                 '.jshintrc'
66                         ],
67                         tasks: 'test'
68                 },
69                 karma: {
70                         options: {
71                                 proxies: ( function () {
72                                         var obj = {};
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, {
79                                                 enumerable: true,
80                                                 get: function () {
81                                                         if ( !wgServer ) {
82                                                                 grunt.fail.fatal( 'MW_SERVER is not set' );
83                                                         }
84                                                         if ( !wgScriptPath ) {
85                                                                 grunt.fail.fatal( 'MW_SCRIPT_PATH is not set' );
86                                                         }
87                                                         return wgServer + wgScriptPath;
88                                                 }
89                                         } );
90                                         return obj;
91                                 }() ),
92                                 files: [ {
93                                         pattern: wgServer + wgScriptPath + '/index.php?title=Special:JavaScriptTest/qunit/export',
94                                         watched: false,
95                                         included: true,
96                                         served: false
97                                 } ],
98                                 frameworks: [ 'qunit' ],
99                                 reporters: [ 'dots' ],
100                                 singleRun: true,
101                                 autoWatch: false
102                         },
103                         main: {
104                                 browsers: [ 'Chrome' ]
105                         },
106                         more: {
107                                 browsers: [ 'Chrome', 'Firefox' ]
108                         }
109                 }
110         } );
112         grunt.registerTask( 'lint', ['jshint', 'jscs', 'jsonlint', 'banana'] );
113         grunt.registerTask( 'qunit', 'karma:main' );
115         grunt.registerTask( 'test', ['lint'] );
116         grunt.registerTask( 'default', 'test' );