From d056d4c273a069d572ceb2160346ee697d7b87de Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 23 Jan 2019 15:51:49 -0800 Subject: [PATCH] build: Use headless Chrome and Firefox for QUnit testing 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 | 23 ++++++++++++++--------- package.json | 3 ++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index fdbf0efbc5..2592815659 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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' ] ); }; diff --git a/package.json b/package.json index 3ab6b0c4ae..387e74eaee 100644 --- a/package.json +++ b/package.json @@ -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", -- 2.20.1