build: Use headless Chrome and Firefox for QUnit testing
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 23 Jan 2019 23:51:49 +0000 (15:51 -0800)
committerJforrester <jforrester@wikimedia.org>
Sun, 10 Feb 2019 06:26:10 +0000 (06:26 +0000)
Also:

* Remove "watch" task from Gruntfile.
  This wasn't exposed via npm-run and afaik rarely if ever used.
  It seems mostly obsoleted by modern editors which perform
  linting and style guidance as-you-type and on-save.

* Remove "chromium" target from karma config, the default
  target supports both Chromium and Chrome.

* Remove unused "default" alias in Gruntfile. Was only
  accessible if developers installed grunt-cli globally, which
  we don't require and shouldn't encourage. The new minify task
  is now exposed as "npm run build".

* Remove "test" alias in Gruntfile. Was only used by "npm run test",
  which now uses "grunt lint" directly, which makes it more clear
  that these are only linters, and not unit tests.

This references T211784 because ensuring no headed browsers are used
(which would need Xvfb to start), is a prerequisite for the new Node 10
images. We may still need to provide a slower Xvfb-wrapped variant for
some repos, but would be nice of mw-core wasn't one of them.

Bug: T211784
Change-Id: I270a16d2b4f799ac7c9f84e9e2ee23806bdbc57e

Gruntfile.js
package.json

index fdbf0ef..2592815 100644 (file)
@@ -8,7 +8,6 @@ module.exports = function ( grunt ) {
 
        grunt.loadNpmTasks( 'grunt-banana-checker' );
        grunt.loadNpmTasks( 'grunt-contrib-copy' );
-       grunt.loadNpmTasks( 'grunt-contrib-watch' );
        grunt.loadNpmTasks( 'grunt-eslint' );
        grunt.loadNpmTasks( 'grunt-jsonlint' );
        grunt.loadNpmTasks( 'grunt-karma' );
@@ -103,6 +102,18 @@ module.exports = function ( grunt ) {
                },
                karma: {
                        options: {
+                               customLaunchers: {
+                                       ChromeCustom: {
+                                               base: 'ChromeHeadless',
+                                               // Chrome requires --no-sandbox in Docker/CI.
+                                               // Newer CI images expose CHROMIUM_FLAGS which sets this (and
+                                               // anything else it might need) automatically. Older CI images,
+                                               // (including Quibble for MW) don't set it yet.
+                                               flags: ( process.env.CHROMIUM_FLAGS ||
+                                                       ( process.env.ZUUL_PROJECT ? '--no-sandbox' : '' )
+                                               ).split( ' ' )
+                                       }
+                               },
                                proxies: karmaProxy,
                                files: [ {
                                        pattern: wgServer + wgScriptPath + '/index.php?title=Special:JavaScriptTest/qunit/export',
@@ -122,13 +133,10 @@ module.exports = function ( grunt ) {
                                crossOriginAttribute: false
                        },
                        main: {
-                               browsers: [ 'Chrome' ]
-                       },
-                       chromium: {
-                               browsers: [ 'Chromium' ]
+                               browsers: [ 'ChromeCustom' ]
                        },
                        firefox: {
-                               browsers: [ 'Firefox' ]
+                               browsers: [ 'FirefoxHeadless' ]
                        }
                },
                copy: {
@@ -159,7 +167,4 @@ module.exports = function ( grunt ) {
        grunt.registerTask( 'minify', 'svgmin' );
        grunt.registerTask( 'lint', [ 'eslint', 'banana', 'stylelint' ] );
        grunt.registerTask( 'qunit', [ 'assert-mw-env', 'karma:main' ] );
-
-       grunt.registerTask( 'test', [ 'lint' ] );
-       grunt.registerTask( 'default', [ 'minify', 'test' ] );
 };
index 3ab6b0c..387e74e 100644 (file)
@@ -1,7 +1,8 @@
 {
   "private": true,
   "scripts": {
-    "test": "grunt test",
+    "build": "grunt minify",
+    "test": "grunt lint",
     "qunit": "grunt qunit",
     "doc": "jsduck",
     "postdoc": "grunt copy:jsduck",