From 2611f907a98b197346b0463602b931cef9126823 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Thu, 29 Apr 2021 16:42:18 +0200 Subject: [PATCH] Update all tests in the ve-mw module to use ES6 syntax Change-Id: I75f8864c66c9b2a78c683d425d54a94515b74f24 --- jsduck.json | 3 +- modules/ve-mw/tests/.eslintrc.json | 7 ++-- .../tests/ce/ve.ce.ContentBranchNode.test.js | 9 +++-- modules/ve-mw/tests/ce/ve.ce.Document.test.js | 13 ++++---- modules/ve-mw/tests/ce/ve.ce.Surface.test.js | 6 ++-- .../dm/nodes/ve.dm.MWTransclusionNode.test.js | 6 ++-- .../ve-mw/tests/dm/ve.dm.Converter.test.js | 14 ++++---- modules/ve-mw/tests/dm/ve.dm.Document.test.js | 13 ++++---- .../ve-mw/tests/dm/ve.dm.MWImageModel.test.js | 24 +++++++------- .../dm/ve.dm.MWInternalLinkAnnotation.test.js | 14 ++++---- .../tests/dm/ve.dm.MWTemplateModel.test.js | 27 +++++++-------- .../dm/ve.dm.MWTransclusionModel.test.js | 14 ++++---- .../tests/dm/ve.dm.SurfaceFragment.test.js | 4 +-- modules/ve-mw/tests/dm/ve.dm.mwExample.js | 4 +-- .../ve.init.mw.DesktopArticleTarget.test.js | 12 +++---- .../ui/actions/ve.ui.FormatAction.test.js | 5 ++- .../ui/actions/ve.ui.MWLinkAction.test.js | 7 ++-- ...ui.MWWikitextStringTransferHandler.test.js | 18 +++++----- .../ve.ui.UrlStringTransferHandler.test.js | 7 ++-- .../ve.ui.FragmentInspector.test.js | 2 +- .../ve-mw/tests/ui/ve.ui.DiffElement.test.js | 5 ++- modules/ve-mw/tests/ve.test.utils.js | 33 ++++++++----------- 22 files changed, 111 insertions(+), 136 deletions(-) diff --git a/jsduck.json b/jsduck.json index 9fdf2af1a6..8c37284645 100644 --- a/jsduck.json +++ b/jsduck.json @@ -10,7 +10,8 @@ "--external": "HTMLDocument,HTMLBodyElement,HTMLHtmlElement,Window,Node,Text,Set,Range,Selection,ClientRect,File,FileList,Blob,DataTransfer,DataTransferItem,KeyboardEvent,MouseEvent,Promise,Storage", "--warnings": [ "-nodoc(class,public)", "-global" ], "--exclude": [ - "lib/ve/rebaser/src/dm/" + "lib/ve/rebaser/src/dm/", + "modules/ve-mw/tests/" ], "--": [ ".jsduck/external.js", diff --git a/modules/ve-mw/tests/.eslintrc.json b/modules/ve-mw/tests/.eslintrc.json index 558423519a..3cb05079d5 100644 --- a/modules/ve-mw/tests/.eslintrc.json +++ b/modules/ve-mw/tests/.eslintrc.json @@ -1,16 +1,15 @@ { "extends": [ "wikimedia/qunit", - "../../../.eslintrc.json" + "../../../.eslintrc.json", + "wikimedia/language/es6" ], - "env": { - "es6": true - }, "globals": { "sinon": false }, "rules": { "compat/compat": [ "error", "last 2 chrome versions, last 2 firefox versions" ], + "indent": "off", "no-jquery/no-parse-html-literal": "off" } } diff --git a/modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js b/modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js index 65f99ed4b0..43c2aae267 100644 --- a/modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js +++ b/modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js @@ -11,8 +11,7 @@ QUnit.module( 've.ce.ContentBranchNode (MW)', ve.test.utils.mwEnvironment ); // FIXME runner copypasted from core, use data provider QUnit.test( 'getRenderedContents', function ( assert ) { - var i, len, doc, $wrapper, - cases = [ { + const cases = [ { msg: 'Annotation spanning text and inline nodes', data: [ { type: 'paragraph' }, @@ -40,9 +39,9 @@ QUnit.test( 'getRenderedContents', function ( assert ) { '' } ]; - for ( i = 0, len = cases.length; i < len; i++ ) { - doc = new ve.dm.Document( ve.dm.example.preprocessAnnotations( cases[ i ].data ) ); - $wrapper = $( new ve.ce.ParagraphNode( doc.getDocumentNode().getChildren()[ 0 ] ).getRenderedContents() ); + for ( let i = 0; i < cases.length; i++ ) { + const doc = new ve.dm.Document( ve.dm.example.preprocessAnnotations( cases[ i ].data ) ), + $wrapper = $( new ve.ce.ParagraphNode( doc.getDocumentNode().getChildren()[ 0 ] ).getRenderedContents() ); // HACK strip out all the class="ve-ce-textStyleAnnotation ve-ce-textStyleBoldAnnotation" crap $wrapper.find( '.ve-ce-textStyleAnnotation' ).removeAttr( 'class' ); assert.equalDomElement( $wrapper[ 0 ], $( '
' ).html( cases[ i ].html )[ 0 ], cases[ i ].msg ); diff --git a/modules/ve-mw/tests/ce/ve.ce.Document.test.js b/modules/ve-mw/tests/ce/ve.ce.Document.test.js index 034790eadf..b8a1fbefbc 100644 --- a/modules/ve-mw/tests/ce/ve.ce.Document.test.js +++ b/modules/ve-mw/tests/ce/ve.ce.Document.test.js @@ -9,15 +9,14 @@ QUnit.module( 've.ce.Document (MW)' ); /* Tests */ QUnit.test( 'Converter tests', function ( assert ) { - var msg, model, view, caseItem, $documentElement, - cases = ve.dm.mwExample.domToDataCases; + const cases = ve.dm.mwExample.domToDataCases; - for ( msg in cases ) { + for ( const msg in cases ) { if ( cases[ msg ].ceHtml ) { - caseItem = ve.copy( cases[ msg ] ); - model = ve.test.utils.getModelFromTestCase( caseItem ); - view = new ve.ce.Document( model ); - $documentElement = view.getDocumentNode().$element; + const caseItem = ve.copy( cases[ msg ] ), + model = ve.test.utils.getModelFromTestCase( caseItem ), + view = new ve.ce.Document( model ), + $documentElement = view.getDocumentNode().$element; // Simplify slugs $documentElement.find( '.ve-ce-branchNode-slug' ).contents().remove(); assert.equalDomElement( diff --git a/modules/ve-mw/tests/ce/ve.ce.Surface.test.js b/modules/ve-mw/tests/ce/ve.ce.Surface.test.js index 5bd5e38e61..c14c03f15d 100644 --- a/modules/ve-mw/tests/ce/ve.ce.Surface.test.js +++ b/modules/ve-mw/tests/ce/ve.ce.Surface.test.js @@ -10,8 +10,7 @@ QUnit.module( 've.ce.Surface (MW)', ve.test.utils.mwEnvironment ); /* Tests */ QUnit.test( 'handleLinearDelete', function ( assert ) { - var done = assert.async(), - promise = Promise.resolve(), + const done = assert.async(), blocklength = ve.dm.mwExample.MWBlockImage.data.length, cases = [ // This asserts that getRelativeRange (via getRelativeOffset) doesn't try to @@ -54,6 +53,7 @@ QUnit.test( 'handleLinearDelete', function ( assert ) { } ]; + let promise = Promise.resolve(); cases.forEach( function ( caseItem ) { promise = promise.then( function () { return ve.test.utils.runSurfaceHandleSpecialKeyTest( assert, caseItem ); @@ -66,7 +66,7 @@ QUnit.test( 'handleLinearDelete', function ( assert ) { } ); QUnit.test( 'beforePaste/afterPaste', function ( assert ) { - var cases = [ + const cases = [ { documentHtml: '

', rangeOrSelection: new ve.Range( 1 ), diff --git a/modules/ve-mw/tests/dm/nodes/ve.dm.MWTransclusionNode.test.js b/modules/ve-mw/tests/dm/nodes/ve.dm.MWTransclusionNode.test.js index 8a35075adb..1a0584a095 100644 --- a/modules/ve-mw/tests/dm/nodes/ve.dm.MWTransclusionNode.test.js +++ b/modules/ve-mw/tests/dm/nodes/ve.dm.MWTransclusionNode.test.js @@ -10,7 +10,7 @@ QUnit.module( 've.dm.MWTransclusionNode', ve.test.utils.mwEnvironment ); /* Tests */ QUnit.test( 'getWikitext', function ( assert ) { - var i, node, cases = [ + const cases = [ { msg: 'mix of numbered and named parameters', mw: { @@ -103,8 +103,8 @@ QUnit.test( 'getWikitext', function ( assert ) { wikitext: '{{foo|bar=[[baz|quux]]}}' } ]; - for ( i = 0; i < cases.length; i++ ) { - node = new ve.dm.MWTransclusionNode( + for ( let i = 0; i < cases.length; i++ ) { + const node = new ve.dm.MWTransclusionNode( { type: 'mwTransclusion', attributes: { mw: cases[ i ].mw } } ); assert.strictEqual( node.getWikitext(), cases[ i ].wikitext, cases[ i ].msg ); diff --git a/modules/ve-mw/tests/dm/ve.dm.Converter.test.js b/modules/ve-mw/tests/dm/ve.dm.Converter.test.js index 5b9373e76f..67644839a5 100644 --- a/modules/ve-mw/tests/dm/ve.dm.Converter.test.js +++ b/modules/ve-mw/tests/dm/ve.dm.Converter.test.js @@ -8,11 +8,10 @@ QUnit.module( 've.dm.Converter (MW)', ve.test.utils.mwEnvironment ); QUnit.test( 'getModelFromDom', function ( assert ) { - var msg, caseItem, - cases = ve.dm.mwExample.domToDataCases; + const cases = ve.dm.mwExample.domToDataCases; - for ( msg in cases ) { - caseItem = ve.copy( cases[ msg ] ); + for ( const msg in cases ) { + const caseItem = ve.copy( cases[ msg ] ); if ( caseItem.mwConfig ) { mw.config.set( caseItem.mwConfig ); } @@ -22,11 +21,10 @@ QUnit.test( 'getModelFromDom', function ( assert ) { } ); QUnit.test( 'getDomFromModel', function ( assert ) { - var msg, caseItem, - cases = ve.dm.mwExample.domToDataCases; + const cases = ve.dm.mwExample.domToDataCases; - for ( msg in cases ) { - caseItem = ve.copy( cases[ msg ] ); + for ( const msg in cases ) { + const caseItem = ve.copy( cases[ msg ] ); if ( caseItem.mwConfig ) { mw.config.set( caseItem.mwConfig ); } diff --git a/modules/ve-mw/tests/dm/ve.dm.Document.test.js b/modules/ve-mw/tests/dm/ve.dm.Document.test.js index 0d97011798..b5857d69d4 100644 --- a/modules/ve-mw/tests/dm/ve.dm.Document.test.js +++ b/modules/ve-mw/tests/dm/ve.dm.Document.test.js @@ -11,8 +11,7 @@ QUnit.module( 've.dm.Document (MW)', ve.test.utils.mwEnvironment ); // FIXME runner copypasted from core, use data provider QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', function ( assert ) { - var documentModel, i, j, - store = new ve.dm.HashValueStore(), + const store = new ve.dm.HashValueStore(), storeItems = [ ve.dm.mwExample.MWBlockImage.storeItems, ve.dm.mwExample.MWInlineImage.storeItems @@ -228,14 +227,14 @@ QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', function ( assert } ]; - for ( i = 0; i < storeItems.length; i++ ) { - for ( j = 0; j < storeItems[ i ].length; j++ ) { + for ( let i = 0; i < storeItems.length; i++ ) { + for ( let j = 0; j < storeItems[ i ].length; j++ ) { store.hash( storeItems[ i ][ j ].value, storeItems[ i ][ j ].hash ); } } - for ( i = 0; i < tests.length; i++ ) { - documentModel = new ve.dm.Document( new ve.dm.ElementLinearData( store, tests[ i ].data ) ); - for ( j = 0; j < tests[ i ].cases.length; j++ ) { + for ( let i = 0; i < tests.length; i++ ) { + const documentModel = new ve.dm.Document( new ve.dm.ElementLinearData( store, tests[ i ].data ) ); + for ( let j = 0; j < tests[ i ].cases.length; j++ ) { assert.equalRange( documentModel.getRelativeRange( tests[ i ].cases[ j ].given, diff --git a/modules/ve-mw/tests/dm/ve.dm.MWImageModel.test.js b/modules/ve-mw/tests/dm/ve.dm.MWImageModel.test.js index eb2596f428..2fdef818b4 100644 --- a/modules/ve-mw/tests/dm/ve.dm.MWImageModel.test.js +++ b/modules/ve-mw/tests/dm/ve.dm.MWImageModel.test.js @@ -10,8 +10,7 @@ QUnit.module( 've.dm.MWImageModel', ve.test.utils.mwEnvironment ); /* Tests */ QUnit.test( 'Create and manipulate image nodes', function ( assert ) { - var i, imageType, imageModel, value, result, expected, expectedAlignment, method, dir, dummyDoc, - imageNode = {}, + const imageNode = {}, images = { mwInlineImage: { dir: 'ltr', @@ -115,7 +114,7 @@ QUnit.test( 'Create and manipulate image nodes', function ( assert ) { } }; - for ( imageType in images ) { + for ( const imageType in images ) { // Create the node imageNode[ imageType ] = ve.dm.MWImageModel.static.createImageNode( images[ imageType ].attrs, @@ -130,23 +129,23 @@ QUnit.test( 'Create and manipulate image nodes', function ( assert ) { ); // Run tests - for ( i = 0; i < images[ imageType ].tests.length; i++ ) { - dir = images[ imageType ].dir; - dummyDoc = new ve.dm.Document( [], null, null, null, null, 'en', images[ imageType ].dir ); + for ( let i = 0; i < images[ imageType ].tests.length; i++ ) { + const dir = images[ imageType ].dir, + dummyDoc = new ve.dm.Document( [], null, null, null, null, 'en', images[ imageType ].dir ); // Start from original details - imageModel = ve.dm.MWImageModel.static.newFromImageAttributes( images[ imageType ].attrs, dummyDoc ); + const imageModel = ve.dm.MWImageModel.static.newFromImageAttributes( images[ imageType ].attrs, dummyDoc ); // Run attributes - for ( method in images[ imageType ].tests[ i ].methods ) { - value = images[ imageType ].tests[ i ].methods[ method ]; + for ( const method in images[ imageType ].tests[ i ].methods ) { + const value = images[ imageType ].tests[ i ].methods[ method ]; imageModel[ method ]( value ); } // Check result - for ( method in images[ imageType ].tests[ i ].results.expect ) { - result = imageModel[ method ](); - expected = images[ imageType ].tests[ i ].results.expect[ method ]; + for ( const method in images[ imageType ].tests[ i ].results.expect ) { + const result = imageModel[ method ](), + expected = images[ imageType ].tests[ i ].results.expect[ method ]; assert.deepEqual( result, expected, @@ -156,6 +155,7 @@ QUnit.test( 'Create and manipulate image nodes', function ( assert ) { // Run language-specific tests if ( images[ imageType ].tests[ i ].results.position ) { + let expectedAlignment; // Definition: // * withText (document direction; 'left' for ltr, 'right' for rtl) // * oppositeToText (opposite the document direction; 'right' for ltr, 'left' for rtl) diff --git a/modules/ve-mw/tests/dm/ve.dm.MWInternalLinkAnnotation.test.js b/modules/ve-mw/tests/dm/ve.dm.MWInternalLinkAnnotation.test.js index 8a5f8906b3..92bb863371 100644 --- a/modules/ve-mw/tests/dm/ve.dm.MWInternalLinkAnnotation.test.js +++ b/modules/ve-mw/tests/dm/ve.dm.MWInternalLinkAnnotation.test.js @@ -7,15 +7,14 @@ QUnit.module( 've.dm.MWInternalLinkAnnotation' ); QUnit.test( 'toDataElement', function ( assert ) { - var i, l, - doc = ve.dm.example.createExampleDocument(), + const doc = ve.dm.example.createExampleDocument(), externalLink = function ( href ) { - var link = document.createElement( 'a' ); + const link = document.createElement( 'a' ); link.setAttribute( 'href', href ); return link; }, internalLink = function ( pageTitle, params ) { - var link = document.createElement( 'a' ); + const link = document.createElement( 'a' ); link.setAttribute( 'href', location.origin + mw.Title.newFromText( pageTitle ).getUrl( params ) ); return link; }, @@ -130,14 +129,13 @@ QUnit.test( 'toDataElement', function ( assert ) { converter.contextStack = []; converter.fromClipboard = true; - for ( i = 0, l = cases.length; i < l; i++ ) { + for ( let i = 0; i < cases.length; i++ ) { assert.deepEqual( ve.dm.MWInternalLinkAnnotation.static.toDataElement( [ cases[ i ].element ], converter ), cases[ i ].expected, cases[ i ].msg ); } } ); QUnit.test( 'getFragment', function ( assert ) { - var i, l, - cases = [ + const cases = [ { msg: 'No fragment returns null', original: 'Foo', @@ -175,7 +173,7 @@ QUnit.test( 'getFragment', function ( assert ) { } ]; - for ( i = 0, l = cases.length; i < l; i++ ) { + for ( let i = 0; i < cases.length; i++ ) { assert.strictEqual( ve.dm.MWInternalLinkAnnotation.static.getFragment( cases[ i ].original ), cases[ i ].expected, cases[ i ].msg ); } } ); diff --git a/modules/ve-mw/tests/dm/ve.dm.MWTemplateModel.test.js b/modules/ve-mw/tests/dm/ve.dm.MWTemplateModel.test.js index 49f91cdb52..3a34996491 100644 --- a/modules/ve-mw/tests/dm/ve.dm.MWTemplateModel.test.js +++ b/modules/ve-mw/tests/dm/ve.dm.MWTemplateModel.test.js @@ -6,7 +6,7 @@ */ ( function () { - var transclusionData = { + const transclusionData = { params: { foo: { wt: 'Foo value' }, bar: { wt: 'Bar value' }, @@ -26,7 +26,7 @@ * @return {ve.dm.MWTemplateModel} */ function newTemplateModel() { - var doc = ve.dm.Document.static.newBlankDocument(), + const doc = ve.dm.Document.static.newBlankDocument(), transclusion = new ve.dm.MWTransclusionModel( doc ), clonedTransclusionData = ve.extendObject( {}, transclusionData ); @@ -36,46 +36,43 @@ /* Tests */ QUnit.test( 'serialize input parameters', function ( assert ) { - var templateModel = newTemplateModel(), + const templateModel = newTemplateModel(), serializedTransclusionData = templateModel.serialize(); assert.deepEqual( serializedTransclusionData, { template: transclusionData } ); } ); QUnit.test( 'serialize changed input parameters', function ( assert ) { - var templateModel = newTemplateModel(), - newParameterModel = new ve.dm.MWParameterModel( templateModel, 'baz', 'Baz value' ), - serializedTransclusionData; + const templateModel = newTemplateModel(), + newParameterModel = new ve.dm.MWParameterModel( templateModel, 'baz', 'Baz value' ); templateModel.addParameter( newParameterModel ); - serializedTransclusionData = templateModel.serialize(); + const serializedTransclusionData = templateModel.serialize(); assert.deepEqual( serializedTransclusionData.template.params.baz, { wt: 'Baz value' } ); } ); // T75134 QUnit.test( 'serialize after parameter was removed', function ( assert ) { - var templateModel = newTemplateModel(), - barParam = templateModel.getParameter( 'bar' ), - serializedTransclusionData; + const templateModel = newTemplateModel(), + barParam = templateModel.getParameter( 'bar' ); templateModel.removeParameter( barParam ); - serializedTransclusionData = templateModel.serialize(); + const serializedTransclusionData = templateModel.serialize(); assert.deepEqual( serializedTransclusionData.template.params, { foo: { wt: 'Foo value' }, empty: { wt: '' } } ); } ); // T101075 QUnit.test( 'serialize without empty parameter not present in original parameter set', function ( assert ) { - var templateModel = newTemplateModel(), - newEmptyParam = new ve.dm.MWParameterModel( templateModel, 'new_empty', '' ), - serializedTransclusionData; + const templateModel = newTemplateModel(), + newEmptyParam = new ve.dm.MWParameterModel( templateModel, 'new_empty', '' ); templateModel.addParameter( newEmptyParam ); - serializedTransclusionData = templateModel.serialize(); + const serializedTransclusionData = templateModel.serialize(); assert.deepEqual( serializedTransclusionData, { template: transclusionData } ); } ); diff --git a/modules/ve-mw/tests/dm/ve.dm.MWTransclusionModel.test.js b/modules/ve-mw/tests/dm/ve.dm.MWTransclusionModel.test.js index 294cc2743a..d1c9205b8c 100644 --- a/modules/ve-mw/tests/dm/ve.dm.MWTransclusionModel.test.js +++ b/modules/ve-mw/tests/dm/ve.dm.MWTransclusionModel.test.js @@ -19,7 +19,7 @@ } ) ); function runAddPartTest( assert, name, response, server, callback ) { - var doc = ve.dm.Document.static.newBlankDocument(), + const doc = ve.dm.Document.static.newBlankDocument(), transclusion = new ve.dm.MWTransclusionModel( doc ), part = ve.dm.MWTemplateModel.newFromName( transclusion, name ), done = assert.async(); @@ -36,7 +36,7 @@ } QUnit.test( 'fetch template part data', function ( assert ) { - var response = { + const response = { batchcomplete: '', pages: { 1331311: { @@ -65,7 +65,7 @@ }; runAddPartTest( assert, 'Test', response, this.server, function ( transclusion ) { - var parts = transclusion.getParts(), + const parts = transclusion.getParts(), spec = parts[ 0 ].getSpec(); assert.strictEqual( parts.length, 1 ); @@ -76,7 +76,7 @@ // T243868 QUnit.test( 'fetch part data for parameterized template with no TemplateData', function ( assert ) { - var response = { + const response = { batchcomplete: '', pages: { 1331311: { @@ -91,7 +91,7 @@ }; runAddPartTest( assert, 'NoData', response, this.server, function ( transclusion ) { - var parts = transclusion.getParts(), + const parts = transclusion.getParts(), spec = parts[ 0 ].getSpec(); assert.strictEqual( parts.length, 1 ); @@ -100,7 +100,7 @@ } ); QUnit.test( 'fetch part data for template with no TemplateData and no params', function ( assert ) { - var response = { + const response = { batchcomplete: '', pages: { 1331311: { @@ -112,7 +112,7 @@ }; runAddPartTest( assert, 'NoParams', response, this.server, function ( transclusion ) { - var parts = transclusion.getParts(), + const parts = transclusion.getParts(), spec = parts[ 0 ].getSpec(); assert.strictEqual( parts.length, 1 ); diff --git a/modules/ve-mw/tests/dm/ve.dm.SurfaceFragment.test.js b/modules/ve-mw/tests/dm/ve.dm.SurfaceFragment.test.js index b609f79396..0e34c61fda 100644 --- a/modules/ve-mw/tests/dm/ve.dm.SurfaceFragment.test.js +++ b/modules/ve-mw/tests/dm/ve.dm.SurfaceFragment.test.js @@ -29,7 +29,7 @@ QUnit.test( 'isolateAndUnwrap (MWheading)', function ( assert ) { } ); QUnit.test( 'insertContent (MWheading)', function ( assert ) { - var doc = new ve.dm.Document( [ + const doc = new ve.dm.Document( [ { type: 'list', attributes: { style: 'bullet' } }, { type: 'listItem' }, { type: 'paragraph' }, @@ -42,9 +42,9 @@ QUnit.test( 'insertContent (MWheading)', function ( assert ) { { type: '/internalList' } ] ), surface = new ve.dm.Surface( doc ), - fragment = surface.getLinearFragment( new ve.Range( 4, 4 ) ), headingData = [ { type: 'mwHeading', attributes: { level: 3 } }, 'x', { type: '/mwHeading' } ]; + let fragment = surface.getLinearFragment( new ve.Range( 4, 4 ) ); fragment.insertContent( headingData ); assert.deepEqual( doc.getData( new ve.Range( 3, 14 ) ), diff --git a/modules/ve-mw/tests/dm/ve.dm.mwExample.js b/modules/ve-mw/tests/dm/ve.dm.mwExample.js index 5f3dfd1c5a..694842d071 100644 --- a/modules/ve-mw/tests/dm/ve.dm.mwExample.js +++ b/modules/ve-mw/tests/dm/ve.dm.mwExample.js @@ -665,7 +665,7 @@ ve.dm.mwExample.domToDataCases = { { type: '/internalList' } ], modify: function ( model ) { - var data = [ 'x', [ ve.dm.example.bold ] ], + const data = [ 'x', [ ve.dm.example.bold ] ], linearData = ve.dm.example.preprocessAnnotations( [ data ], model.getStore() ); model.data.data.splice( 3, 0, linearData.data[ 0 ] ); }, @@ -726,7 +726,7 @@ ve.dm.mwExample.domToDataCases = { { type: '/internalList' } ], modify: function ( model ) { - var data = [ 'x', [ ve.dm.example.bold ] ], + const data = [ 'x', [ ve.dm.example.bold ] ], linearData = ve.dm.example.preprocessAnnotations( [ data ], model.getStore() ); model.data.data.splice( 3, 0, linearData.data[ 0 ] ); }, diff --git a/modules/ve-mw/tests/init/targets/ve.init.mw.DesktopArticleTarget.test.js b/modules/ve-mw/tests/init/targets/ve.init.mw.DesktopArticleTarget.test.js index ec06826112..27ff559715 100644 --- a/modules/ve-mw/tests/init/targets/ve.init.mw.DesktopArticleTarget.test.js +++ b/modules/ve-mw/tests/init/targets/ve.init.mw.DesktopArticleTarget.test.js @@ -8,8 +8,7 @@ QUnit.module( 've.init.mw.DesktopArticleTarget', ve.test.utils.mwEnvironment ); QUnit.test( 'init', function ( assert ) { - var - response = { + const response = { visualeditor: { result: 'success', notices: [ @@ -114,8 +113,7 @@ QUnit.test( 'init', function ( assert ) { } ); QUnit.test( 'compatibility', function ( assert ) { - var profile, matches, compatibility, - cases = [ + const cases = [ { msg: 'Unidentified browser', userAgent: 'FooBar Browser Company Version 3.141', @@ -248,15 +246,15 @@ QUnit.test( 'compatibility', function ( assert ) { } ]; - compatibility = { + const compatibility = { supportedList: ve.init.mw.DesktopArticleTarget.static.compatibility.supportedList, // TODO: Fix this mess when we split ve.init from ve.platform unsupportedList: mw.libs.ve.unsupportedList }; cases.forEach( function ( caseItem ) { - profile = $.client.profile( { userAgent: caseItem.userAgent, platform: '' } ); - matches = []; + const profile = $.client.profile( { userAgent: caseItem.userAgent, platform: '' } ), + matches = []; [ 'unsupportedList', 'supportedList' ].every( function ( list ) { if ( $.client.test( compatibility[ list ], profile, true ) ) { matches.push( list ); diff --git a/modules/ve-mw/tests/ui/actions/ve.ui.FormatAction.test.js b/modules/ve-mw/tests/ui/actions/ve.ui.FormatAction.test.js index 80c7cda12e..5a936b85eb 100644 --- a/modules/ve-mw/tests/ui/actions/ve.ui.FormatAction.test.js +++ b/modules/ve-mw/tests/ui/actions/ve.ui.FormatAction.test.js @@ -10,8 +10,7 @@ QUnit.module( 've.ui.FormatAction (MW)', ve.test.utils.mwEnvironment ); /* Tests */ QUnit.test( 'convert (MW-specific types)', function ( assert ) { - var i, - cases = [ + const cases = [ { rangeOrSelection: new ve.Range( 14, 16 ), type: 'mwHeading', @@ -69,7 +68,7 @@ QUnit.test( 'convert (MW-specific types)', function ( assert ) { } ]; - for ( i = 0; i < cases.length; i++ ) { + for ( let i = 0; i < cases.length; i++ ) { ve.test.utils.runActionTest( 'format', assert, cases[ i ].html || ve.dm.example.isolationHtml, false, 'convert', [ cases[ i ].type, cases[ i ].attributes ], cases[ i ].rangeOrSelection, cases[ i ].msg, diff --git a/modules/ve-mw/tests/ui/actions/ve.ui.MWLinkAction.test.js b/modules/ve-mw/tests/ui/actions/ve.ui.MWLinkAction.test.js index 987b4b3ffc..5b09fe7c44 100644 --- a/modules/ve-mw/tests/ui/actions/ve.ui.MWLinkAction.test.js +++ b/modules/ve-mw/tests/ui/actions/ve.ui.MWLinkAction.test.js @@ -10,7 +10,7 @@ QUnit.module( 've.ui.MWLinkAction' ); /* Tests */ QUnit.test( 'MW autolink', function ( assert ) { - var cases = [ + const cases = [ { msg: 'Strip trailing punctuation (but not matched parens)', html: '

https://en.wikipedia.org/wiki/Red_(disambiguation) xyz

', @@ -18,9 +18,8 @@ QUnit.test( 'MW autolink', function ( assert ) { method: 'autolinkUrl', expectedRangeOrSelection: new ve.Range( 51 ), expectedData: function ( data, action ) { - var i, - a = action.getLinkAnnotation( 'https://en.wikipedia.org/wiki/Red_(disambiguation)' ); - for ( i = 1; i < 51; i++ ) { + const a = action.getLinkAnnotation( 'https://en.wikipedia.org/wiki/Red_(disambiguation)' ); + for ( let i = 1; i < 51; i++ ) { data[ i ][ 1 ].push( a.element ); } } diff --git a/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js b/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js index 310c84f75c..c111c5671a 100644 --- a/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js +++ b/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.MWWikitextStringTransferHandler.test.js @@ -22,8 +22,7 @@ QUnit.module( 've.ui.MWWikitextStringTransferHandler', QUnit.newMwEnvironment( { /* Tests */ ve.test.utils.runWikitextStringHandlerTest = function ( assert, server, string, mimeType, expectedResponse, expectedData, annotations, assertDom, msg ) { - var handler, i, j, name, - done = assert.async(), + const done = assert.async(), item = ve.ui.DataTransferItem.static.newFromString( string, mimeType ), doc = ve.dm.Document.static.newBlankDocument(), mockSurface = { @@ -40,9 +39,9 @@ ve.test.utils.runWikitextStringHandlerTest = function ( assert, server, string, }; // Preprocess the expectedData array - for ( i = 0; i < expectedData.length; i++ ) { + for ( let i = 0; i < expectedData.length; i++ ) { if ( Array.isArray( expectedData[ i ] ) ) { - for ( j = 0; j < expectedData[ i ][ 1 ].length; j++ ) { + for ( let j = 0; j < expectedData[ i ][ 1 ].length; j++ ) { if ( typeof expectedData[ i ][ 1 ][ j ] === 'number' ) { expectedData[ i ][ 1 ][ j ] = annotations[ expectedData[ i ][ 1 ][ j ] ]; } @@ -51,14 +50,14 @@ ve.test.utils.runWikitextStringHandlerTest = function ( assert, server, string, } // Check we match the wikitext string handler - name = ve.ui.dataTransferHandlerFactory.getHandlerNameForItem( item ); + const name = ve.ui.dataTransferHandlerFactory.getHandlerNameForItem( item ); assert.strictEqual( name, 'wikitextString', msg + ': triggers match function' ); // Invoke the handler - handler = ve.ui.dataTransferHandlerFactory.create( 'wikitextString', mockSurface, item ); + const handler = ve.ui.dataTransferHandlerFactory.create( 'wikitextString', mockSurface, item ); handler.getInsertableData().done( function ( docOrData ) { - var actualData, store; + let actualData, store; if ( docOrData instanceof ve.dm.Document ) { actualData = docOrData.getData(); store = docOrData.getStore(); @@ -88,8 +87,7 @@ ve.test.utils.runWikitextStringHandlerTest = function ( assert, server, string, }; QUnit.test( 'convert', function ( assert ) { - var i, - cases = [ + const cases = [ { msg: 'Simple link', // Put link in the middle of text to verify that the @@ -269,7 +267,7 @@ QUnit.test( 'convert', function ( assert ) { } ]; - for ( i = 0; i < cases.length; i++ ) { + for ( let i = 0; i < cases.length; i++ ) { ve.test.utils.runWikitextStringHandlerTest( assert, this.server, cases[ i ].pasteString, cases[ i ].pasteType, cases[ i ].parsoidResponse, cases[ i ].expectedData, cases[ i ].annotations, cases[ i ].assertDom, cases[ i ].msg diff --git a/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js b/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js index b933d01357..50513e2a21 100644 --- a/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js +++ b/modules/ve-mw/tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js @@ -9,15 +9,14 @@ QUnit.module( 've.ui.UrlStringTransferHandler (MW)' ); /* Tests */ QUnit.test( 'paste', function ( assert ) { - var i, - cases = [ + const cases = [ { msg: 'External link converts to internal link', pasteString: location.origin + mw.Title.newFromText( 'Main Page' ).getUrl(), pasteType: 'text/plain', expectedData: function () { // Explicitly create an internal link so we can assert this behaviour is working - var a = ve.dm.MWInternalLinkAnnotation.static.newFromTitle( mw.Title.newFromText( 'Main Page' ) ).element; + const a = ve.dm.MWInternalLinkAnnotation.static.newFromTitle( mw.Title.newFromText( 'Main Page' ) ).element; return [ [ 'M', [ a ] ], [ 'a', [ a ] ], @@ -33,7 +32,7 @@ QUnit.test( 'paste', function ( assert ) { } ]; - for ( i = 0; i < cases.length; i++ ) { + for ( let i = 0; i < cases.length; i++ ) { ve.test.utils.runUrlStringHandlerTest( assert, cases[ i ].pasteString, cases[ i ].pasteHtml, cases[ i ].pasteType, cases[ i ].expectedData, cases[ i ].msg ); } } ); diff --git a/modules/ve-mw/tests/ui/inspectors/ve.ui.FragmentInspector.test.js b/modules/ve-mw/tests/ui/inspectors/ve.ui.FragmentInspector.test.js index 063175cef3..8a5c74a530 100644 --- a/modules/ve-mw/tests/ui/inspectors/ve.ui.FragmentInspector.test.js +++ b/modules/ve-mw/tests/ui/inspectors/ve.ui.FragmentInspector.test.js @@ -17,7 +17,7 @@ QUnit.module( 've.ui.FragmentInspector (MW)', QUnit.newMwEnvironment( { /* Tests */ QUnit.test( 'Wikitext link inspector', function ( assert ) { - var done = assert.async(), + const done = assert.async(), surface = ve.init.target.createSurface( ve.dm.converter.getModelFromDom( ve.createDocumentFromHtml( diff --git a/modules/ve-mw/tests/ui/ve.ui.DiffElement.test.js b/modules/ve-mw/tests/ui/ve.ui.DiffElement.test.js index 6a5206fa8c..cbf0ac6327 100644 --- a/modules/ve-mw/tests/ui/ve.ui.DiffElement.test.js +++ b/modules/ve-mw/tests/ui/ve.ui.DiffElement.test.js @@ -7,8 +7,7 @@ QUnit.module( 've.ui.DiffElement (MW)', ve.test.utils.mwEnvironment ); QUnit.test( 'Diffing', function ( assert ) { - var i, len, - fixBase = function ( body ) { + const fixBase = function ( body ) { return '' + body + ''; }, cases = [ @@ -47,7 +46,7 @@ QUnit.test( 'Diffing', function ( assert ) { } ]; - for ( i = 0, len = cases.length; i < len; i++ ) { + for ( let i = 0; i < cases.length; i++ ) { ve.test.utils.runDiffElementTest( assert, cases[ i ] ); } diff --git a/modules/ve-mw/tests/ve.test.utils.js b/modules/ve-mw/tests/ve.test.utils.js index 0870777b19..a2584707af 100644 --- a/modules/ve-mw/tests/ve.test.utils.js +++ b/modules/ve-mw/tests/ve.test.utils.js @@ -6,8 +6,6 @@ */ ( function () { - var getDomElementSummaryCore; - function MWDummyTarget() { MWDummyTarget.super.call( this ); } @@ -40,7 +38,7 @@ return Array.prototype.join.call( arguments, ',' ); }; MWDummyPlatform.prototype.getHtmlMessage = function () { - var $wrapper = $( '
' ); + const $wrapper = $( '
' ); Array.prototype.forEach.call( arguments, function ( arg, i, args ) { $wrapper.append( arg ); if ( i < args.length - 1 ) { @@ -48,15 +46,13 @@ } } ); // Merge text nodes - // eslint-disable-next-line no-restricted-properties $wrapper[ 0 ].normalize(); return $wrapper.contents().toArray(); }; ve.test.utils.MWDummyPlatform = MWDummyPlatform; ve.test.utils.mwEnvironment = ( function () { - var mwPlatform, corePlatform, mwTarget, coreTarget, - setEditorPreference = mw.libs.ve.setEditorPreference, + const setEditorPreference = mw.libs.ve.setEditorPreference, dummySetEditorPreference = function () { return ve.createDeferred().resolve().promise(); }, overrides = [ ve.dm.MWHeadingNode, @@ -69,22 +65,21 @@ ve.dm.BlockImageNode ]; - corePlatform = ve.init.platform; - coreTarget = ve.init.target; - mwPlatform = new ve.test.utils.MWDummyPlatform(); + const corePlatform = ve.init.platform, + coreTarget = ve.init.target, + mwPlatform = new ve.test.utils.MWDummyPlatform(); // Unregister mwPlatform ve.init.platform = corePlatform; - mwTarget = new ve.test.utils.MWDummyTarget(); + const mwTarget = new ve.test.utils.MWDummyTarget(); // Unregister mwTarget ve.init.target = coreTarget; function setupOverrides() { - var i; - for ( i = 0; i < overrides.length; i++ ) { + for ( let i = 0; i < overrides.length; i++ ) { ve.dm.modelRegistry.register( overrides[ i ] ); } - for ( i = 0; i < overridden.length; i++ ) { + for ( let i = 0; i < overridden.length; i++ ) { ve.dm.modelRegistry.unregister( overridden[ i ] ); } ve.ui.windowFactory.unregister( ve.ui.LinkAnnotationInspector ); @@ -99,11 +94,10 @@ } function teardownOverrides() { - var i; - for ( i = 0; i < overrides.length; i++ ) { + for ( let i = 0; i < overrides.length; i++ ) { ve.dm.modelRegistry.unregister( overrides[ i ] ); } - for ( i = 0; i < overridden.length; i++ ) { + for ( let i = 0; i < overridden.length; i++ ) { ve.dm.modelRegistry.register( overridden[ i ] ); } ve.ui.windowFactory.unregister( ve.ui.MWLinkAnnotationInspector ); @@ -123,7 +117,7 @@ }; }() ); - getDomElementSummaryCore = ve.getDomElementSummary; + const getDomElementSummaryCore = ve.getDomElementSummary; /** * Override getDomElementSummary to extract HTML from data-mw/body.html @@ -134,10 +128,9 @@ ve.getDomElementSummary = function ( element, includeHtml ) { // "Parent" method return getDomElementSummaryCore( element, includeHtml, function ( name, value ) { - var obj, html; if ( name === 'data-mw' ) { - obj = JSON.parse( value ); - html = ve.getProp( obj, 'body', 'html' ); + const obj = JSON.parse( value ), + html = ve.getProp( obj, 'body', 'html' ); if ( html ) { obj.body.html = ve.getDomElementSummary( $( '
' ).html( html )[ 0 ] ); }