From: Timo Tijhof Date: Tue, 11 Jul 2017 19:56:35 +0000 (-0700) Subject: mw.loader: Avoid use of deprecated QUnit.asyncTest/QUnit.start X-Git-Tag: 1.31.0-rc.0~2710^2 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=6418c54c4ad9a49643ba61a6567b2c8359926c5f;p=lhc%2Fweb%2Fwiklou.git mw.loader: Avoid use of deprecated QUnit.asyncTest/QUnit.start Deprecated since QUnit 1.16, removed in QUnit 2.0. (We're on 1.23 currently.) Migrate to assert.async(). This is a fairly atypical use of QUnit.start(), because it functions here as a cross-script callback, where lexical scope cannot be used to share the async() callback directly. Other mw.loader tests already solved this by using a static callback instead which inherits the lexical scope from the test to call done(). The old 'qunitOkCall' script is no longer used after this and thus removed. Change-Id: I430df14b35a69c71df8685494d1379e22af0d6df --- diff --git a/tests/qunit/data/callMwLoaderTestCallback.js b/tests/qunit/data/callMwLoaderTestCallback.js deleted file mode 100644 index dd03411594..0000000000 --- a/tests/qunit/data/callMwLoaderTestCallback.js +++ /dev/null @@ -1 +0,0 @@ -mediaWiki.loader.testCallback(); diff --git a/tests/qunit/data/mwLoaderTestCallback.js b/tests/qunit/data/mwLoaderTestCallback.js new file mode 100644 index 0000000000..dd03411594 --- /dev/null +++ b/tests/qunit/data/mwLoaderTestCallback.js @@ -0,0 +1 @@ +mediaWiki.loader.testCallback(); diff --git a/tests/qunit/data/qunitOkCall.js b/tests/qunit/data/qunitOkCall.js deleted file mode 100644 index 3ed5514e78..0000000000 --- a/tests/qunit/data/qunitOkCall.js +++ /dev/null @@ -1,2 +0,0 @@ -QUnit.start(); -QUnit.assert.ok( true, 'Successfully loaded!' ); diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js index 9dc9e5d661..cd18380f92 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js @@ -90,7 +90,7 @@ isAwesomeDone = true; }; - mw.loader.implement( 'test.callback', [ QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/callMwLoaderTestCallback.js' ) ] ); + mw.loader.implement( 'test.callback', [ QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/mwLoaderTestCallback.js' ) ] ); return mw.loader.using( 'test.callback', function () { assert.strictEqual( isAwesomeDone, true, 'test.callback module should\'ve caused isAwesomeDone to be true' ); @@ -109,7 +109,7 @@ isAwesomeDone = true; }; - mw.loader.implement( 'hasOwnProperty', [ QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/callMwLoaderTestCallback.js' ) ], {}, {} ); + mw.loader.implement( 'hasOwnProperty', [ QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/mwLoaderTestCallback.js' ) ], {}, {} ); return mw.loader.using( 'hasOwnProperty', function () { assert.strictEqual( isAwesomeDone, true, 'hasOwnProperty module should\'ve caused isAwesomeDone to be true' ); @@ -128,7 +128,7 @@ isAwesomeDone = true; }; - mw.loader.implement( 'test.promise', [ QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/callMwLoaderTestCallback.js' ) ] ); + mw.loader.implement( 'test.promise', [ QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/mwLoaderTestCallback.js' ) ] ); return mw.loader.using( 'test.promise' ) .done( function () { @@ -680,38 +680,44 @@ ); } ); - QUnit.asyncTest( '.load( "//protocol-relative" ) - T32825', function ( assert ) { - // This bug was actually already fixed in 1.18 and later when discovered in 1.17. - // Test is for regressions! + // This bug was actually already fixed in 1.18 and later when discovered in 1.17. + QUnit.test( '.load( "//protocol-relative" ) - T32825', function ( assert ) { + var target, + done = assert.async(); - // Forge a URL to the test callback script - var target = QUnit.fixurl( - mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/qunitOkCall.js' + // URL to the callback script + target = QUnit.fixurl( + mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/mwLoaderTestCallback.js' ); - - // Confirm that mw.loader.load() works with protocol-relative URLs + // Ensure a protocol-relative URL for this test target = target.replace( /https?:/, '' ); + assert.equal( target.slice( 0, 2 ), '//', 'URL is protocol-relative' ); - assert.equal( target.slice( 0, 2 ), '//', - 'URL must be relative to test relative URLs!' - ); + mw.loader.testCallback = function () { + delete mw.loader.testCallback; + assert.ok( true, 'callback' ); + done(); + }; - // Async! - // The target calls QUnit.start + // Go! mw.loader.load( target ); } ); - QUnit.asyncTest( '.load( "/absolute-path" )', function ( assert ) { - // Forge a URL to the test callback script - var target = QUnit.fixurl( - mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/qunitOkCall.js' - ); + QUnit.test( '.load( "/absolute-path" )', function ( assert ) { + var target, + done = assert.async(); - // Confirm that mw.loader.load() works with absolute-paths (relative to current hostname) + // URL to the callback script + target = QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/mwLoaderTestCallback.js' ); assert.equal( target.slice( 0, 1 ), '/', 'URL is relative to document root' ); - // Async! - // The target calls QUnit.start + mw.loader.testCallback = function () { + delete mw.loader.testCallback; + assert.ok( true, 'callback' ); + done(); + }; + + // Go! mw.loader.load( target ); } );