build: Introduce eslint-plugin-qunit and enforce
authorEd Sanders <esanders@wikimedia.org>
Tue, 5 Jun 2018 20:58:25 +0000 (21:58 +0100)
committerEd Sanders <esanders@wikimedia.org>
Tue, 5 Jun 2018 20:58:25 +0000 (21:58 +0100)
Change-Id: Iefe06cc865c458000ca5350c2d9205f5b768bac8

13 files changed:
package.json
tests/qunit/.eslintrc.json
tests/qunit/data/testrunner.js
tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js
tests/qunit/suites/resources/mediawiki.rcfilters/UriProcessor.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.Uri.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.experiments.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.template.mustache.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.template.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.test.js

index 1f23b1a..2d425dd 100644 (file)
@@ -12,6 +12,7 @@
     "deepmerge": "1.3.2",
     "eslint": "4.9.0",
     "eslint-config-wikimedia": "0.5.0",
     "deepmerge": "1.3.2",
     "eslint": "4.9.0",
     "eslint-config-wikimedia": "0.5.0",
+    "eslint-plugin-qunit": "3.2.1",
     "grunt": "1.0.1",
     "grunt-banana-checker": "0.6.0",
     "grunt-contrib-copy": "1.0.0",
     "grunt": "1.0.1",
     "grunt-banana-checker": "0.6.0",
     "grunt-contrib-copy": "1.0.0",
index b3a46f4..d3aea5e 100644 (file)
@@ -1,5 +1,9 @@
 {
 {
-       "extends": "../../.eslintrc.json",
+       "extends": [
+               "../../.eslintrc.json",
+               "plugin:qunit/recommended",
+               "plugin:qunit/two"
+       ],
        "env": {
                "qunit": true
        },
        "env": {
                "qunit": true
        },
@@ -9,6 +13,9 @@
        "rules": {
                "operator-linebreak": 0,
                "quote-props": [ "error", "as-needed" ],
        "rules": {
                "operator-linebreak": 0,
                "quote-props": [ "error", "as-needed" ],
-               "valid-jsdoc": 0
-       }
+               "valid-jsdoc": 0,
+               "qunit/require-expect": 0,
+               "qunit/resolve-async": 0
+       },
+       "plugins": [ "qunit" ]
 }
 }
index 06c146c..9074aba 100644 (file)
@@ -40,7 +40,7 @@
         * Configuration
         */
 
         * Configuration
         */
 
-       // For each test() that is asynchronous, allow this time to pass before
+       // For each test that is asynchronous, allow this time to pass before
        // killing the test and assuming timeout failure.
        QUnit.config.testTimeout = 60 * 1000;
 
        // killing the test and assuming timeout failure.
        QUnit.config.testTimeout = 60 * 1000;
 
        }() );
 
        /**
        }() );
 
        /**
-        * Reset mw.config and others to a fresh copy of the live config for each test(),
+        * Reset mw.config and others to a fresh copy of the live config for each test,
         * and restore it back to the live one afterwards.
         *
         * @param {Object} [localEnv]
         * and restore it back to the live one afterwards.
         *
         * @param {Object} [localEnv]
        } );
 
        QUnit.module( 'testrunner-each-compat', {
        } );
 
        QUnit.module( 'testrunner-each-compat', {
+               // eslint-disable-next-line qunit/no-setup-teardown
                setup: function () {
                        this.mwHtmlLive = mw.html;
                },
                setup: function () {
                        this.mwHtmlLive = mw.html;
                },
+               // eslint-disable-next-line qunit/no-setup-teardown
                teardown: function () {
                        mw.html = this.mwHtmlLive;
                }
                teardown: function () {
                        mw.html = this.mwHtmlLive;
                }
index 32cda7e..1e183fb 100644 (file)
 
                        function among( actual, expected, message ) {
                                if ( Array.isArray( expected ) ) {
 
                        function among( actual, expected, message ) {
                                if ( Array.isArray( expected ) ) {
-                                       assert.ok( expected.indexOf( actual ) !== -1, message + ' (got ' + actual + '; expected one of ' + expected.join( ', ' ) + ')' );
+                                       assert.equal( expected.indexOf( actual ) !== -1, true, message + ' (got ' + actual + '; expected one of ' + expected.join( ', ' ) + ')' );
                                } else {
                                        assert.equal( actual, expected, message );
                                }
                                } else {
                                        assert.equal( actual, expected, message );
                                }
index 7431b29..1d9a829 100644 (file)
                        .then( function ( token ) {
                                assert.ok( token.length, 'Got a token' );
                        }, function ( err ) {
                        .then( function ( token ) {
                                assert.ok( token.length, 'Got a token' );
                        }, function ( err ) {
-                               assert.equal( '', err, 'API error' );
+                               assert.equal( err, '', 'API error' );
                        } )
                        .then( function () {
                                assert.equal( test.server.requests.length, 0, 'Requests made' );
                        } )
                        .then( function () {
                                assert.equal( test.server.requests.length, 0, 'Requests made' );
        } );
 
        QUnit.module( 'mediawiki.api (2)', {
        } );
 
        QUnit.module( 'mediawiki.api (2)', {
-               setup: function () {
+               beforeEach: function () {
                        var self = this,
                                requests = this.requests = [];
                        this.api = new mw.Api();
                        var self = this,
                                requests = this.requests = [];
                        this.api = new mw.Api();
                        b: 2
                } );
                this.api.abort();
                        b: 2
                } );
                this.api.abort();
-               assert.ok( this.requests.length === 2, 'Check both requests triggered' );
+               assert.equal( this.requests.length, 2, 'Check both requests triggered' );
                this.requests.forEach( function ( request, i ) {
                        assert.ok( request.abort.calledOnce, 'abort request number ' + i );
                } );
                this.requests.forEach( function ( request, i ) {
                        assert.ok( request.abort.calledOnce, 'abort request number ' + i );
                } );
index 872f4dd..a6c56a9 100644 (file)
        QUnit.test( 'getVersion', function ( assert ) {
                var uriProcessor = new mw.rcfilters.UriProcessor( new mw.rcfilters.dm.FiltersViewModel() );
 
        QUnit.test( 'getVersion', function ( assert ) {
                var uriProcessor = new mw.rcfilters.UriProcessor( new mw.rcfilters.dm.FiltersViewModel() );
 
-               assert.ok(
+               assert.equal(
                        uriProcessor.getVersion( { param1: 'foo', urlversion: '2' } ),
                        2,
                        'Retrieving the version from the URI query'
                );
 
                        uriProcessor.getVersion( { param1: 'foo', urlversion: '2' } ),
                        2,
                        'Retrieving the version from the URI query'
                );
 
-               assert.ok(
+               assert.equal(
                        uriProcessor.getVersion( { param1: 'foo' } ),
                        1,
                        'Getting version 1 if no version is specified'
                        uriProcessor.getVersion( { param1: 'foo' } ),
                        1,
                        'Getting version 1 if no version is specified'
index 918c923..f2cb70b 100644 (file)
                        foo: 'quux',
                        pif: 'paf'
                } );
                        foo: 'quux',
                        pif: 'paf'
                } );
-               assert.ok( uri.toString().indexOf( 'foo=quux' ) >= 0, 'extend query arguments' );
-               assert.ok( uri.toString().indexOf( 'foo=bar' ) === -1, 'extend query arguments' );
-               assert.ok( uri.toString().indexOf( 'pif=paf' ) >= 0, 'extend query arguments' );
+               assert.equal( uri.toString().indexOf( 'foo=quux' ) !== -1, true, 'extend query arguments' );
+               assert.equal( uri.toString().indexOf( 'foo=bar' ) !== -1, false, 'extend query arguments' );
+               assert.equal( uri.toString().indexOf( 'pif=paf' ) !== -1, true, 'extend query arguments' );
        } );
 
        QUnit.test( '.getQueryString()', function ( assert ) {
        } );
 
        QUnit.test( '.getQueryString()', function ( assert ) {
 
                // Verify parts and total length instead of entire string because order
                // of iteration can vary.
 
                // Verify parts and total length instead of entire string because order
                // of iteration can vary.
-               assert.ok( uri.toString().indexOf( 'm=bar' ), 'toString preserves other values' );
-               assert.ok( uri.toString().indexOf( 'n=x&n=y&n=z' ), 'toString parameter includes all values of an array query parameter' );
+               assert.equal( uri.toString().indexOf( 'm=bar' ) !== -1, true, 'toString preserves other values' );
+               assert.equal( uri.toString().indexOf( 'n=x&n=y&n=z' ) !== -1, true, 'toString parameter includes all values of an array query parameter' );
                assert.equal( uri.toString().length, 'http://www.example.com/dir/?m=bar&n=x&n=y&n=z'.length, 'toString matches expected string' );
 
                uri = new mw.Uri( 'http://www.example.com/dir/?m=foo&m=bar&n=1', {
                assert.equal( uri.toString().length, 'http://www.example.com/dir/?m=bar&n=x&n=y&n=z'.length, 'toString matches expected string' );
 
                uri = new mw.Uri( 'http://www.example.com/dir/?m=foo&m=bar&n=1', {
 
                // Verify parts and total length instead of entire string because order
                // of iteration can vary.
 
                // Verify parts and total length instead of entire string because order
                // of iteration can vary.
-               assert.ok( uri.toString().indexOf( 'm=foo&m=bar' ) >= 0, 'toString preserves other values' );
-               assert.ok( uri.toString().indexOf( 'n=x&n=y&n=z' ) >= 0, 'toString parameter includes all values of an array query parameter' );
+               assert.equal( uri.toString().indexOf( 'm=foo&m=bar' ) !== -1, true, 'toString preserves other values' );
+               assert.equal( uri.toString().indexOf( 'n=x&n=y&n=z' ) !== -1, true, 'toString parameter includes all values of an array query parameter' );
                assert.equal( uri.toString().length, 'http://www.example.com/dir/?m=foo&m=bar&n=x&n=y&n=z'.length, 'toString matches expected string' );
 
                // Remove query values
                assert.equal( uri.toString().length, 'http://www.example.com/dir/?m=foo&m=bar&n=x&n=y&n=z'.length, 'toString matches expected string' );
 
                // Remove query values
                assert.equal( uri.getHostPort(), 'www.example.com:81', 'hostport equal to host:port' );
 
                queryString = uri.getQueryString();
                assert.equal( uri.getHostPort(), 'www.example.com:81', 'hostport equal to host:port' );
 
                queryString = uri.getQueryString();
-               assert.ok( queryString.indexOf( 'q1=0' ) >= 0, 'query param with numbers' );
-               assert.ok( queryString.indexOf( 'test1' ) >= 0, 'query param with null value is included' );
-               assert.ok( queryString.indexOf( 'test1=' ) === -1, 'query param with null value does not generate equals sign' );
-               assert.ok( queryString.indexOf( 'test2=value+%28escaped%29' ) >= 0, 'query param is url escaped' );
+               assert.equal( queryString.indexOf( 'q1=0' ) !== -1, true, 'query param with numbers' );
+               assert.equal( queryString.indexOf( 'test1' ) !== -1, true, 'query param with null value is included' );
+               assert.equal( queryString.indexOf( 'test1=' ) !== -1, false, 'query param with null value does not generate equals sign' );
+               assert.equal( queryString.indexOf( 'test2=value+%28escaped%29' ) !== -1, true, 'query param is url escaped' );
 
                relativePath = uri.getRelativePath();
                assert.ok( relativePath.indexOf( uri.path ) >= 0, 'path in relative path' );
 
                relativePath = uri.getRelativePath();
                assert.ok( relativePath.indexOf( uri.path ) >= 0, 'path in relative path' );
index 177c358..9bff988 100644 (file)
@@ -34,8 +34,8 @@
                };
 
                assert.equal(
                };
 
                assert.equal(
-                       'A',
                        getBucket( experiment, token ),
                        getBucket( experiment, token ),
+                       'A',
                        'It returns the bucket if only one is defined.'
                );
 
                        'It returns the bucket if only one is defined.'
                );
 
@@ -44,8 +44,8 @@
                experiment.enabled = false;
 
                assert.equal(
                experiment.enabled = false;
 
                assert.equal(
-                       'control',
                        getBucket( experiment, token ),
                        getBucket( experiment, token ),
+                       'control',
                        'It returns "control" if the experiment is disabled.'
                );
 
                        'It returns "control" if the experiment is disabled.'
                );
 
@@ -54,8 +54,8 @@
                experiment.buckets = {};
 
                assert.equal(
                experiment.buckets = {};
 
                assert.equal(
-                       'control',
                        getBucket( experiment, token ),
                        getBucket( experiment, token ),
+                       'control',
                        'It returns "control" if the experiment doesn\'t have any buckets.'
                );
        } );
                        'It returns "control" if the experiment doesn\'t have any buckets.'
                );
        } );
index b0b2e7a..6cb5d76 100644 (file)
@@ -20,7 +20,7 @@
        // Not that we need this. ;)
        // This fails on IE 6-8
        // Works on IE 9, Firefox 6, Chrome 14
        // Not that we need this. ;)
        // This fails on IE 6-8
        // Works on IE 9, Firefox 6, Chrome 14
-       QUnit.test( 'Keyword workaround: "if" as variable name using Unicode escapes', function ( assert ) {
+       ...( 'Keyword workaround: "if" as variable name using Unicode escapes', function ( assert ) {
                var orig = "another token";
                \u0069\u0066 = orig;
                assert.deepEqual( \u0069\u0066, orig, '\\u0069\\u0066' );
                var orig = "another token";
                \u0069\u0066 = orig;
                assert.deepEqual( \u0069\u0066, orig, '\\u0069\\u0066' );
@@ -31,7 +31,7 @@
        // Not that we need this. ;)
        // This fails on IE 6-9
        // Works on Firefox 6, Chrome 14
        // Not that we need this. ;)
        // This fails on IE 6-9
        // Works on Firefox 6, Chrome 14
-       QUnit.test( 'Keyword workaround: "if" as member variable name using Unicode escapes', function ( assert ) {
+       ...( 'Keyword workaround: "if" as member variable name using Unicode escapes', function ( assert ) {
                var orig = "another token";
                var foo = {};
                foo.\u0069\u0066 = orig;
                var orig = "another token";
                var foo = {};
                foo.\u0069\u0066 = orig;
index 42bc0a7..8914bd4 100644 (file)
@@ -28,7 +28,7 @@
        );
 
        /**
        );
 
        /**
-        * The sync style load test (for @import). This is, in a way, also an open bug for
+        * The sync style load test, for @import. This is, in a way, also an open bug for
         * ResourceLoader ("execute js after styles are loaded"), but browsers don't offer a
         * way to get a callback from when a stylesheet is loaded (that is, including any
         * `@import` rules inside). To work around this, we'll have a little time loop to check
         * ResourceLoader ("execute js after styles are loaded"), but browsers don't offer a
         * way to get a callback from when a stylesheet is loaded (that is, including any
         * `@import` rules inside). To work around this, we'll have a little time loop to check
                        try {
                                assert.strictEqual( cb.later(), 'Defined.', 'require works asynchrously in debug mode' );
                        } catch ( e ) {
                        try {
                                assert.strictEqual( cb.later(), 'Defined.', 'require works asynchrously in debug mode' );
                        } catch ( e ) {
-                               assert.equal( null, String( e ), 'require works asynchrously in debug mode' );
+                               assert.equal( String( e ), null, 'require works asynchrously in debug mode' );
                        }
                } );
        } );
                        }
                } );
        } );
index cb583e7..ab1d55e 100644 (file)
@@ -1,7 +1,7 @@
 ( function ( mw ) {
 
        QUnit.module( 'mediawiki.template.mustache', {
 ( function ( mw ) {
 
        QUnit.module( 'mediawiki.template.mustache', {
-               setup: function () {
+               beforeEach: function () {
                        // Stub register some templates
                        this.sandbox.stub( mw.templates, 'get' ).returns( {
                                'test_greeting.mustache': '<div>{{foo}}{{>suffix}}</div>',
                        // Stub register some templates
                        this.sandbox.stub( mw.templates, 'get' ).returns( {
                                'test_greeting.mustache': '<div>{{foo}}{{>suffix}}</div>',
index a282325..31f4782 100644 (file)
@@ -1,7 +1,7 @@
 ( function ( mw ) {
 
        QUnit.module( 'mediawiki.template', {
 ( function ( mw ) {
 
        QUnit.module( 'mediawiki.template', {
-               setup: function () {
+               beforeEach: function () {
                        var abcCompiler = {
                                compile: function () {
                                        return 'abc default compiler';
                        var abcCompiler = {
                                compile: function () {
                                        return 'abc default compiler';
index 75dc665..9cbbdeb 100644 (file)
                // Interacting with globals
                conf.set( 'globalMapChecker', 'Hi' );
 
                // Interacting with globals
                conf.set( 'globalMapChecker', 'Hi' );
 
-               assert.ok( ( 'globalMapChecker' in window ) === false, 'Map does not its store values in the window object by default' );
+               assert.equal( 'globalMapChecker' in window, false, 'Map does not its store values in the window object by default' );
 
                globalConf = new mw.Map( true );
                globalConf.set( 'anotherGlobalMapChecker', 'Hello' );
 
                globalConf = new mw.Map( true );
                globalConf.set( 'anotherGlobalMapChecker', 'Hello' );