2018-08-29 04:46:30 +00:00
|
|
|
( function () {
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2018-06-05 20:58:25 +00:00
|
|
|
// For each test that is asynchronous, allow this time to pass before
|
2016-02-04 10:35:02 +00:00
|
|
|
// killing the test and assuming timeout failure.
|
|
|
|
|
QUnit.config.testTimeout = 60 * 1000;
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
|
2019-10-30 21:46:31 +00:00
|
|
|
QUnit.dump.maxDepth = QUnit.config.maxDepth = 20;
|
|
|
|
|
|
2016-11-22 02:57:18 +00:00
|
|
|
// Reduce default animation duration from 400ms to 0ms for unit tests
|
2017-02-22 18:46:19 +00:00
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
2016-11-22 02:57:18 +00:00
|
|
|
$.fx.speeds._default = 0;
|
|
|
|
|
|
2023-02-23 00:55:34 +00:00
|
|
|
// Add a checkbox to QUnit header to toggle MediaWiki ResourceLoader debug mode.
|
|
|
|
|
QUnit.config.urlConfig.push( {
|
|
|
|
|
id: 'debug',
|
|
|
|
|
label: 'Enable ResourceLoaderDebug',
|
|
|
|
|
tooltip: 'Enable debug mode in ResourceLoader',
|
|
|
|
|
value: 'true'
|
|
|
|
|
} );
|
|
|
|
|
|
2022-05-15 14:34:20 +00:00
|
|
|
// Integrate SinonJS with QUnit
|
|
|
|
|
//
|
|
|
|
|
// - Add a Sinon sandbox to the test context that is automatically
|
|
|
|
|
// restored at the end of each test.
|
|
|
|
|
// - Forward sinon assertions to QUnit.
|
2020-06-18 18:19:42 +00:00
|
|
|
//
|
|
|
|
|
// Inspired by http://sinonjs.org/releases/sinon-qunit-1.0.0.js
|
qunit: Add SinonJS utility
To be used in mediawiki.api tests and elsewhere.
For now they are opt-in and disabled by default,
individual tests can enable fake timers, servers and/or
xhrs by calling this.sandbox to access the dedicated
sinon sandbox for that test.
Clock example:
QUnit.test( 'example', function ( assert ) {
var clock = this.sandbox.useFakeTimers();
setTimeout( function () {
assert.ok( true, 'test' );
} );
clock.tick(1);
} );
Server example:
QUnit.test( 'example', function ( assert ) {
this.server = this.sandbox.useFakeServer();
new mw.Api().getToken( 'foo' ).done( function ( token ) {
assert.equal( token, '0123abc', 'Token' );
} );
// assert.equal( this.server.requests.length, 1, 'Requests' );
this.server.respond( function ( request ) {
request.respond( 200, { 'Content-Type': 'application/json' },
'{ "tokens": { "testactiontoken": "0123abc" } }'
);
} );
} );
Change-Id: I789fb71903f26dbbfe781f010dc5cd3756759943
2014-02-05 05:18:28 +00:00
|
|
|
sinon.assert.fail = function ( msg ) {
|
2021-11-08 17:14:34 +00:00
|
|
|
QUnit.assert.true( false, msg );
|
qunit: Add SinonJS utility
To be used in mediawiki.api tests and elsewhere.
For now they are opt-in and disabled by default,
individual tests can enable fake timers, servers and/or
xhrs by calling this.sandbox to access the dedicated
sinon sandbox for that test.
Clock example:
QUnit.test( 'example', function ( assert ) {
var clock = this.sandbox.useFakeTimers();
setTimeout( function () {
assert.ok( true, 'test' );
} );
clock.tick(1);
} );
Server example:
QUnit.test( 'example', function ( assert ) {
this.server = this.sandbox.useFakeServer();
new mw.Api().getToken( 'foo' ).done( function ( token ) {
assert.equal( token, '0123abc', 'Token' );
} );
// assert.equal( this.server.requests.length, 1, 'Requests' );
this.server.respond( function ( request ) {
request.respond( 200, { 'Content-Type': 'application/json' },
'{ "tokens": { "testactiontoken": "0123abc" } }'
);
} );
} );
Change-Id: I789fb71903f26dbbfe781f010dc5cd3756759943
2014-02-05 05:18:28 +00:00
|
|
|
};
|
|
|
|
|
sinon.assert.pass = function ( msg ) {
|
2021-11-08 17:14:34 +00:00
|
|
|
QUnit.assert.true( true, msg );
|
qunit: Add SinonJS utility
To be used in mediawiki.api tests and elsewhere.
For now they are opt-in and disabled by default,
individual tests can enable fake timers, servers and/or
xhrs by calling this.sandbox to access the dedicated
sinon sandbox for that test.
Clock example:
QUnit.test( 'example', function ( assert ) {
var clock = this.sandbox.useFakeTimers();
setTimeout( function () {
assert.ok( true, 'test' );
} );
clock.tick(1);
} );
Server example:
QUnit.test( 'example', function ( assert ) {
this.server = this.sandbox.useFakeServer();
new mw.Api().getToken( 'foo' ).done( function ( token ) {
assert.equal( token, '0123abc', 'Token' );
} );
// assert.equal( this.server.requests.length, 1, 'Requests' );
this.server.respond( function ( request ) {
request.respond( 200, { 'Content-Type': 'application/json' },
'{ "tokens": { "testactiontoken": "0123abc" } }'
);
} );
} );
Change-Id: I789fb71903f26dbbfe781f010dc5cd3756759943
2014-02-05 05:18:28 +00:00
|
|
|
};
|
|
|
|
|
sinon.config = {
|
|
|
|
|
injectIntoThis: true,
|
|
|
|
|
injectInto: null,
|
2015-09-03 20:15:33 +00:00
|
|
|
properties: [ 'spy', 'stub', 'mock', 'sandbox' ],
|
qunit: Add SinonJS utility
To be used in mediawiki.api tests and elsewhere.
For now they are opt-in and disabled by default,
individual tests can enable fake timers, servers and/or
xhrs by calling this.sandbox to access the dedicated
sinon sandbox for that test.
Clock example:
QUnit.test( 'example', function ( assert ) {
var clock = this.sandbox.useFakeTimers();
setTimeout( function () {
assert.ok( true, 'test' );
} );
clock.tick(1);
} );
Server example:
QUnit.test( 'example', function ( assert ) {
this.server = this.sandbox.useFakeServer();
new mw.Api().getToken( 'foo' ).done( function ( token ) {
assert.equal( token, '0123abc', 'Token' );
} );
// assert.equal( this.server.requests.length, 1, 'Requests' );
this.server.respond( function ( request ) {
request.respond( 200, { 'Content-Type': 'application/json' },
'{ "tokens": { "testactiontoken": "0123abc" } }'
);
} );
} );
Change-Id: I789fb71903f26dbbfe781f010dc5cd3756759943
2014-02-05 05:18:28 +00:00
|
|
|
// Don't fake timers by default
|
|
|
|
|
useFakeTimers: false,
|
|
|
|
|
useFakeServer: false
|
|
|
|
|
};
|
2022-05-15 14:34:20 +00:00
|
|
|
QUnit.hooks.beforeEach( function () {
|
|
|
|
|
// Sinon sandbox
|
|
|
|
|
var config = sinon.getConfig( sinon.config );
|
|
|
|
|
config.injectInto = this;
|
|
|
|
|
sinon.sandbox.create( config );
|
|
|
|
|
} );
|
|
|
|
|
QUnit.hooks.afterEach( function () {
|
|
|
|
|
this.sandbox.verifyAndRestore();
|
|
|
|
|
} );
|
2014-12-10 05:58:31 +00:00
|
|
|
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
/**
|
2022-04-26 21:49:47 +00:00
|
|
|
* Ensure mw.config and other `mw` singleton state is prestine for each test.
|
|
|
|
|
*
|
|
|
|
|
* Example:
|
|
|
|
|
*
|
|
|
|
|
* QUnit.module('mw.myModule', QUnit.newMwEnvironment() );
|
|
|
|
|
*
|
|
|
|
|
* QUnit.module('mw.myModule', QUnit.newMwEnvironment( {
|
|
|
|
|
* config: {
|
|
|
|
|
* wgServer: 'https://example.org'
|
|
|
|
|
* },
|
|
|
|
|
* messages: {
|
|
|
|
|
* 'monday-short': 'Monday'
|
|
|
|
|
* }
|
|
|
|
|
* } );
|
2015-09-05 19:11:47 +00:00
|
|
|
*
|
2015-09-05 18:55:03 +00:00
|
|
|
* @param {Object} [localEnv]
|
2022-04-26 21:49:47 +00:00
|
|
|
* @param {Object} [localEnv.config]
|
|
|
|
|
* @param {Object} [localEnv.messages]
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
*/
|
|
|
|
|
QUnit.newMwEnvironment = ( function () {
|
2022-04-26 22:33:09 +00:00
|
|
|
var deepClone = typeof structuredClone === 'function' ? structuredClone : function ( obj ) {
|
|
|
|
|
return $.extend( /* deep */ true, {}, obj );
|
|
|
|
|
};
|
|
|
|
|
var liveConfig = mw.config.values;
|
|
|
|
|
var liveMessages = mw.messages.values;
|
2022-05-15 15:25:22 +00:00
|
|
|
var liveWarnFn = mw.log.warn;
|
|
|
|
|
var liveErrorFn = mw.log.error;
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
|
2014-04-07 18:43:19 +00:00
|
|
|
function suppressWarnings() {
|
2022-05-15 15:25:22 +00:00
|
|
|
mw.log.warn = mw.log.error = function () {};
|
2014-04-07 18:43:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function restoreWarnings() {
|
2022-05-15 15:25:22 +00:00
|
|
|
mw.log.warn = liveWarnFn;
|
|
|
|
|
mw.log.error = liveErrorFn;
|
2014-04-07 18:43:19 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-15 14:34:20 +00:00
|
|
|
return function newMwEnvironment( localEnv ) {
|
2022-05-15 14:20:09 +00:00
|
|
|
localEnv = localEnv || {};
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
|
2022-04-26 21:49:47 +00:00
|
|
|
var orgBeforeEach = localEnv.beforeEach;
|
|
|
|
|
var orgAfterEach = localEnv.afterEach;
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
|
2018-01-31 21:05:09 +00:00
|
|
|
localEnv.beforeEach = function () {
|
2022-04-26 22:33:09 +00:00
|
|
|
mw.config.values = deepClone( liveConfig );
|
|
|
|
|
if ( localEnv.config ) {
|
|
|
|
|
mw.config.set( localEnv.config );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mw.messages.values = deepClone( liveMessages );
|
|
|
|
|
if ( localEnv.messages ) {
|
|
|
|
|
mw.messages.set( localEnv.messages );
|
|
|
|
|
}
|
2018-01-31 21:05:09 +00:00
|
|
|
|
|
|
|
|
this.suppressWarnings = suppressWarnings;
|
|
|
|
|
this.restoreWarnings = restoreWarnings;
|
|
|
|
|
|
|
|
|
|
if ( orgBeforeEach ) {
|
|
|
|
|
return orgBeforeEach.apply( this, arguments );
|
|
|
|
|
}
|
|
|
|
|
};
|
qunit: Remove old $.fx and $.ajax tracking from testrunner
I added this about ten years ago after I encountered two issues in
the same week where, during development, I couldn't get a newly written
test to pass. The root cause was that the test was async, but I
forgot to use `assert.async()`. In one case due to an XHR request,
and in one case due to an unfinished animation. By tracking these,
and warning about unfinished ones, this would be found sooner.
To my knowledge, nobody (including myself) has ever since then
encountered these warnings during development in a way that helped
identify a mistake. Instead, we've only seen them ocasionally pop
up in CI due to unfinished AJAX requests and animations unrelated
to tests.
It is best practice not to trigger animations or requests during a test
that you don't wait for. In practice, I believe such a thing would
likely be a mistake and only make the test slower. But, we can
follow that best practice without enforcing it, with the benefit
of tolerating a few minor inefficiencies here and there, without
causing CI to be in a failing state every time it slips in, especially
if it slips in in a non-deterministic way, causing flaky tests.
But.. I didn't introduce it to help with that best practice, and
it seems we've been pretty good about this regardless. I introduced
it to help debug a test that is consistently failing on code that
isn't merged yet. In retrospect, I think a modern DevTools/debugger
would help you figure out the issue easy enough with a breakpoint
without this additional complexity.
The objective here is to make the QUnit test runner simpler and less
special in ways that are specific to MediaWiki, as well as to make it
a bit faster by reducing logic that has to run for every single test
case.
Bug: T250045
Change-Id: I77878f2d855da89f6b2e2c0e17060daacf867678
2023-02-25 00:03:10 +00:00
|
|
|
localEnv.afterEach = function () {
|
2022-04-26 21:49:47 +00:00
|
|
|
var ret;
|
2018-01-31 21:05:09 +00:00
|
|
|
if ( orgAfterEach ) {
|
|
|
|
|
ret = orgAfterEach.apply( this, arguments );
|
|
|
|
|
}
|
2017-04-15 00:12:06 +00:00
|
|
|
|
2022-05-15 15:25:13 +00:00
|
|
|
// For convenience and to avoid leakage, always restore after each test.
|
|
|
|
|
// Restoring earlier is allowed.
|
2018-01-31 21:05:09 +00:00
|
|
|
restoreWarnings();
|
|
|
|
|
|
2022-04-26 22:33:09 +00:00
|
|
|
mw.config.values = liveConfig;
|
|
|
|
|
mw.messages.values = liveMessages;
|
2018-01-31 21:05:09 +00:00
|
|
|
|
qunit: Remove old $.fx and $.ajax tracking from testrunner
I added this about ten years ago after I encountered two issues in
the same week where, during development, I couldn't get a newly written
test to pass. The root cause was that the test was async, but I
forgot to use `assert.async()`. In one case due to an XHR request,
and in one case due to an unfinished animation. By tracking these,
and warning about unfinished ones, this would be found sooner.
To my knowledge, nobody (including myself) has ever since then
encountered these warnings during development in a way that helped
identify a mistake. Instead, we've only seen them ocasionally pop
up in CI due to unfinished AJAX requests and animations unrelated
to tests.
It is best practice not to trigger animations or requests during a test
that you don't wait for. In practice, I believe such a thing would
likely be a mistake and only make the test slower. But, we can
follow that best practice without enforcing it, with the benefit
of tolerating a few minor inefficiencies here and there, without
causing CI to be in a failing state every time it slips in, especially
if it slips in in a non-deterministic way, causing flaky tests.
But.. I didn't introduce it to help with that best practice, and
it seems we've been pretty good about this regardless. I introduced
it to help debug a test that is consistently failing on code that
isn't merged yet. In retrospect, I think a modern DevTools/debugger
would help you figure out the issue easy enough with a breakpoint
without this additional complexity.
The objective here is to make the QUnit test runner simpler and less
special in ways that are specific to MediaWiki, as well as to make it
a bit faster by reducing logic that has to run for every single test
case.
Bug: T250045
Change-Id: I77878f2d855da89f6b2e2c0e17060daacf867678
2023-02-25 00:03:10 +00:00
|
|
|
// Stop animations to ensure a clean start for the next test
|
|
|
|
|
$.timers = [];
|
|
|
|
|
$.fx.stop();
|
2018-01-31 21:05:09 +00:00
|
|
|
|
|
|
|
|
return ret;
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
};
|
2018-01-31 21:05:09 +00:00
|
|
|
return localEnv;
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
};
|
|
|
|
|
}() );
|
2012-05-12 22:37:30 +00:00
|
|
|
|
2022-04-26 21:49:47 +00:00
|
|
|
/**
|
|
|
|
|
* Wait for multiple promises to have finished.
|
|
|
|
|
*
|
|
|
|
|
* This differs from `$.when`, which stops as soon as one fails,
|
|
|
|
|
* which makes sense in a production context, but not in a test
|
|
|
|
|
* where we really do need to wait until all are finished before
|
|
|
|
|
* moving on.
|
|
|
|
|
*
|
|
|
|
|
* @return {jQuery.Promise}
|
|
|
|
|
*/
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
QUnit.whenPromisesComplete = function () {
|
|
|
|
|
var altPromises = [];
|
2012-05-12 22:37:30 +00:00
|
|
|
|
2019-02-20 22:53:09 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-each-util
|
2024-06-11 12:43:19 +00:00
|
|
|
$.each( arguments, ( i, arg ) => {
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
var alt = $.Deferred();
|
|
|
|
|
altPromises.push( alt );
|
2012-01-03 18:33:26 +00:00
|
|
|
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
// Whether this one fails or not, forwards it to
|
|
|
|
|
// the 'done' (resolve) callback of the alternative promise.
|
|
|
|
|
arg.always( alt.resolve );
|
2013-02-15 11:10:19 +00:00
|
|
|
} );
|
2012-05-12 22:37:30 +00:00
|
|
|
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
return $.when.apply( $, altPromises );
|
|
|
|
|
};
|
2012-05-12 22:37:30 +00:00
|
|
|
|
2013-03-06 00:56:15 +00:00
|
|
|
/**
|
|
|
|
|
* Recursively convert a node to a plain object representing its structure.
|
|
|
|
|
* Only considers attributes and contents (elements and text nodes).
|
|
|
|
|
* Attribute values are compared strictly and not normalised.
|
|
|
|
|
*
|
|
|
|
|
* @param {Node} node
|
|
|
|
|
* @return {Object|string} Plain JavaScript value representing the node.
|
|
|
|
|
*/
|
|
|
|
|
function getDomStructure( node ) {
|
2015-07-13 18:02:49 +00:00
|
|
|
if ( node.nodeType === Node.ELEMENT_NODE ) {
|
2022-04-26 21:49:47 +00:00
|
|
|
var processedChildren = [];
|
2024-06-11 12:43:19 +00:00
|
|
|
$( node ).contents().each( ( i, el ) => {
|
2015-07-13 18:02:49 +00:00
|
|
|
if ( el.nodeType === Node.ELEMENT_NODE || el.nodeType === Node.TEXT_NODE ) {
|
2013-03-06 00:56:15 +00:00
|
|
|
processedChildren.push( getDomStructure( el ) );
|
|
|
|
|
}
|
2020-02-22 00:49:45 +00:00
|
|
|
} );
|
|
|
|
|
|
2022-04-26 21:49:47 +00:00
|
|
|
var attribs = {};
|
2020-02-22 00:49:45 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-each-util
|
2024-06-11 12:43:19 +00:00
|
|
|
$.each( node.attributes, ( i, attrib ) => {
|
2020-02-22 00:49:45 +00:00
|
|
|
attribs[ attrib.name ] = attrib.value;
|
|
|
|
|
} );
|
2013-03-06 00:56:15 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
tagName: node.tagName,
|
2020-02-22 00:49:45 +00:00
|
|
|
attributes: attribs,
|
2013-03-06 00:56:15 +00:00
|
|
|
contents: processedChildren
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
// Should be text node
|
2020-02-22 00:49:45 +00:00
|
|
|
return node.textContent;
|
2013-03-06 00:56:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-04-26 21:49:47 +00:00
|
|
|
* Get structure of node for this HTML.
|
2013-03-06 00:56:15 +00:00
|
|
|
*
|
|
|
|
|
* @param {string} html HTML markup for one or more nodes.
|
2020-06-12 17:27:55 +00:00
|
|
|
* @return {Object}
|
2013-03-06 00:56:15 +00:00
|
|
|
*/
|
|
|
|
|
function getHtmlStructure( html ) {
|
2015-09-03 20:15:33 +00:00
|
|
|
var el = $( '<div>' ).append( html )[ 0 ];
|
2013-03-06 00:56:15 +00:00
|
|
|
return getDomStructure( el );
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-26 21:49:47 +00:00
|
|
|
var addons = {
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
|
2022-04-26 21:49:47 +00:00
|
|
|
/**
|
|
|
|
|
* Assert numerical value less than X
|
|
|
|
|
*
|
|
|
|
|
* @param {Mixed} actual
|
|
|
|
|
* @param {number} expected
|
|
|
|
|
* @param {string} [message]
|
|
|
|
|
*/
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
lt: function ( actual, expected, message ) {
|
2017-07-17 19:29:11 +00:00
|
|
|
this.pushResult( {
|
|
|
|
|
result: actual < expected,
|
|
|
|
|
actual: actual,
|
|
|
|
|
expected: 'less than ' + expected,
|
|
|
|
|
message: message
|
|
|
|
|
} );
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
},
|
|
|
|
|
|
2022-04-26 21:49:47 +00:00
|
|
|
/**
|
|
|
|
|
* Assert numerical value less than or equal to X
|
|
|
|
|
*
|
|
|
|
|
* @param {Mixed} actual
|
|
|
|
|
* @param {number} expected
|
|
|
|
|
* @param {string} [message]
|
|
|
|
|
*/
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
ltOrEq: function ( actual, expected, message ) {
|
2017-07-17 19:29:11 +00:00
|
|
|
this.pushResult( {
|
|
|
|
|
result: actual <= expected,
|
|
|
|
|
actual: actual,
|
|
|
|
|
expected: 'less than or equal to ' + expected,
|
|
|
|
|
message: message
|
|
|
|
|
} );
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
},
|
|
|
|
|
|
2022-04-26 21:49:47 +00:00
|
|
|
/**
|
|
|
|
|
* Assert numerical value greater than X
|
|
|
|
|
*
|
|
|
|
|
* @param {Mixed} actual
|
|
|
|
|
* @param {number} expected
|
|
|
|
|
* @param {string} [message]
|
|
|
|
|
*/
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
gt: function ( actual, expected, message ) {
|
2017-07-17 19:29:11 +00:00
|
|
|
this.pushResult( {
|
|
|
|
|
result: actual > expected,
|
|
|
|
|
actual: actual,
|
|
|
|
|
expected: 'greater than ' + expected,
|
|
|
|
|
message: message
|
|
|
|
|
} );
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
},
|
|
|
|
|
|
2022-04-26 21:49:47 +00:00
|
|
|
/**
|
|
|
|
|
* Assert numerical value greater than or equal to X
|
|
|
|
|
*
|
|
|
|
|
* @param {Mixed} actual
|
|
|
|
|
* @param {number} expected
|
|
|
|
|
* @param {string} [message]
|
|
|
|
|
*/
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
gtOrEq: function ( actual, expected, message ) {
|
2017-07-17 19:29:11 +00:00
|
|
|
this.pushResult( {
|
|
|
|
|
result: actual >= true,
|
|
|
|
|
actual: actual,
|
|
|
|
|
expected: 'greater than or equal to ' + expected,
|
|
|
|
|
message: message
|
|
|
|
|
} );
|
2013-03-06 00:56:15 +00:00
|
|
|
},
|
|
|
|
|
|
2019-10-30 21:46:31 +00:00
|
|
|
/**
|
|
|
|
|
* Asserts that two DOM nodes are structurally equivalent.
|
|
|
|
|
*
|
2020-05-15 00:02:06 +00:00
|
|
|
* @param {HTMLElement} actual
|
2019-10-30 21:46:31 +00:00
|
|
|
* @param {Object} expectedStruct
|
|
|
|
|
* @param {string} message Assertion message.
|
|
|
|
|
*/
|
|
|
|
|
domEqual: function ( actual, expectedStruct, message ) {
|
|
|
|
|
var actualStruct = getDomStructure( actual );
|
|
|
|
|
this.pushResult( {
|
|
|
|
|
result: QUnit.equiv( actualStruct, expectedStruct ),
|
|
|
|
|
actual: actualStruct,
|
|
|
|
|
expected: expectedStruct,
|
|
|
|
|
message: message
|
|
|
|
|
} );
|
|
|
|
|
},
|
|
|
|
|
|
2013-03-06 00:56:15 +00:00
|
|
|
/**
|
|
|
|
|
* Asserts that two HTML strings are structurally equivalent.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} actualHtml Actual HTML markup.
|
|
|
|
|
* @param {string} expectedHtml Expected HTML markup
|
|
|
|
|
* @param {string} message Assertion message.
|
|
|
|
|
*/
|
|
|
|
|
htmlEqual: function ( actualHtml, expectedHtml, message ) {
|
|
|
|
|
var actual = getHtmlStructure( actualHtml ),
|
|
|
|
|
expected = getHtmlStructure( expectedHtml );
|
2017-07-17 19:29:11 +00:00
|
|
|
this.pushResult( {
|
|
|
|
|
result: QUnit.equiv( actual, expected ),
|
|
|
|
|
actual: actual,
|
|
|
|
|
expected: expected,
|
|
|
|
|
message: message
|
|
|
|
|
} );
|
2013-03-06 00:56:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Asserts that two HTML strings are not structurally equivalent.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} actualHtml Actual HTML markup.
|
|
|
|
|
* @param {string} expectedHtml Expected HTML markup.
|
|
|
|
|
* @param {string} message Assertion message.
|
|
|
|
|
*/
|
|
|
|
|
notHtmlEqual: function ( actualHtml, expectedHtml, message ) {
|
|
|
|
|
var actual = getHtmlStructure( actualHtml ),
|
|
|
|
|
expected = getHtmlStructure( expectedHtml );
|
|
|
|
|
|
2017-07-17 19:29:11 +00:00
|
|
|
this.pushResult( {
|
|
|
|
|
result: !QUnit.equiv( actual, expected ),
|
|
|
|
|
actual: actual,
|
|
|
|
|
expected: expected,
|
|
|
|
|
message: message,
|
|
|
|
|
negative: true
|
|
|
|
|
} );
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
}
|
2012-01-03 18:33:26 +00:00
|
|
|
};
|
|
|
|
|
|
2024-06-11 18:00:44 +00:00
|
|
|
Object.assign( QUnit.assert, addons );
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
|
2022-04-26 21:49:47 +00:00
|
|
|
// Small test suite to confirm proper functionality of the utilities and
|
|
|
|
|
// initializations defined above in this file.
|
2017-07-17 19:29:11 +00:00
|
|
|
QUnit.module( 'testrunner', QUnit.newMwEnvironment( {
|
2022-04-27 00:02:24 +00:00
|
|
|
beforeEach: function () {
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
this.mwHtmlLive = mw.html;
|
|
|
|
|
mw.html = {
|
|
|
|
|
escape: function () {
|
2014-04-11 18:40:52 +00:00
|
|
|
return 'mocked';
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
},
|
2022-04-27 00:02:24 +00:00
|
|
|
afterEach: function () {
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
mw.html = this.mwHtmlLive;
|
|
|
|
|
},
|
|
|
|
|
config: {
|
|
|
|
|
testVar: 'foo'
|
|
|
|
|
},
|
|
|
|
|
messages: {
|
|
|
|
|
testMsg: 'Foo.'
|
|
|
|
|
}
|
2024-06-11 12:43:19 +00:00
|
|
|
} ), () => {
|
2012-06-07 20:45:53 +00:00
|
|
|
|
2024-06-11 12:43:19 +00:00
|
|
|
QUnit.test( 'beforeEach', ( assert ) => {
|
2022-04-27 00:02:24 +00:00
|
|
|
assert.strictEqual( mw.html.escape( 'foo' ), 'mocked', 'callback ran' );
|
|
|
|
|
assert.strictEqual( mw.config.get( 'testVar' ), 'foo', 'config applied' );
|
|
|
|
|
assert.strictEqual( mw.messages.get( 'testMsg' ), 'Foo.', 'messages applied' );
|
2012-06-07 20:45:53 +00:00
|
|
|
|
2022-04-27 00:02:24 +00:00
|
|
|
mw.config.set( 'testVar', 'bar' );
|
|
|
|
|
mw.messages.set( 'testMsg', 'Bar.' );
|
|
|
|
|
} );
|
2012-06-07 20:45:53 +00:00
|
|
|
|
2024-06-11 12:43:19 +00:00
|
|
|
QUnit.test( 'afterEach', ( assert ) => {
|
2022-04-27 00:02:24 +00:00
|
|
|
assert.strictEqual( mw.config.get( 'testVar' ), 'foo', 'config restored' );
|
|
|
|
|
assert.strictEqual( mw.messages.get( 'testMsg' ), 'Foo.', 'messages restored' );
|
|
|
|
|
} );
|
Lint: Go-go-gadget jshint! Passing entire JS code base (again).
There were still some files not passing jshint, and for files
that did, we managed to screw 'em up again.
Added more explicit settings in .jshintrc to avoid relying on a
kind of default somewhere. There are too many default-factors:
closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint..
Added node_modules/ and extensions/ to .jshintignore.
Previously "$ jshint ." would recurse over all kinds of
unrelated code. Extensions should have their own jshint
dotfiles. When linting from Jenkins this won't be a problem as
those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles
don't apply as they'll be out of scope).
Some of our modules are really messy and should be refactored
to be less spaghetti-ish and have more descriptive variable
names and more manageable function-level complexity.
But for this commit, I'm keeping it as much as-is as possible,
because its hard/large enough to review as it is.
A few errors are cited below to give an impression of the kind
of warnings I addressed (for cases where the diff isn't
so obvious):
* jquery.hidpi.js: line 110, col 15, Empty block.
* mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements.
* mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote.
* mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used.
* startup.js: line 19, col 22, 'isCompatible' is defined but never used.
* jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case.
* jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used.
* mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined.
* mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote.
* mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined.
* mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined.
* mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used.
Other fixes:
* Add closures fix implied global errors ($, mw and more),
and prevents local variables from becoming globals.
* Avoid jQ magic map arg etc. (per code conventions).
* Fix incorrect usage of jQuery methods (prop instead of attr,
prop false instead of removeProp, ..).
* Unquote keys in object literals for consistency, and
enforce single quotes (no magic quotes in javascript, as much
as we might think "\n" and '/n' are really exactly the same).
Chose single quotes over double quotes since that's what most
code already had and what conventions seemed to prefer
(both the old generic ones and the new per-lang ones since
2011/2012).
* Enforce camelCase variable names with jshint per code
conventions.
* $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn()
(No event simulation overhead, unless intended of course)
* Incorrect indentation (ignore whitespace in the diff!).
* Avoid proprietary selectors like ':first' when .eq(0)
afterwards is just as possible (significantly faster in
jQuery due to mostly avoiding the Sizzle engine and going
native in modern browsers).
* When at it, convert deprecated jQuery methods to new ones.
Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn).
* Addressed whitespace here and there.
Interesting:
* mediawiki.js: local function "compare" wasn't used anymore
(hasn't been in a while!) removed per jshint warning.
* mediawiki.special.recentchanges.js: Was a mess, only a few
lines of code, rewritten.
Pfew, let's hope it's the last one before we lint from Jenkins!
Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
|
|
|
|
2024-06-11 12:43:19 +00:00
|
|
|
QUnit.test( 'Loader status', ( assert ) => {
|
2022-04-27 00:02:24 +00:00
|
|
|
var modules = mw.loader.getModuleNames();
|
|
|
|
|
var error = [];
|
|
|
|
|
var missing = [];
|
|
|
|
|
|
|
|
|
|
for ( var i = 0; i < modules.length; i++ ) {
|
|
|
|
|
var state = mw.loader.getState( modules[ i ] );
|
|
|
|
|
if ( state === 'error' ) {
|
|
|
|
|
error.push( modules[ i ] );
|
|
|
|
|
} else if ( state === 'missing' ) {
|
|
|
|
|
missing.push( modules[ i ] );
|
|
|
|
|
}
|
2013-04-03 19:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-27 00:02:24 +00:00
|
|
|
assert.deepEqual( error, [], 'Modules in error state' );
|
|
|
|
|
assert.deepEqual( missing, [], 'Modules in missing state' );
|
|
|
|
|
} );
|
2013-04-03 19:17:08 +00:00
|
|
|
|
2024-06-11 12:43:19 +00:00
|
|
|
QUnit.test( 'assert.htmlEqual', ( assert ) => {
|
2022-04-27 00:02:24 +00:00
|
|
|
assert.htmlEqual(
|
|
|
|
|
'<div><p class="some classes" data-length="10">Child paragraph with <a href="http://example.com">A link</a></p>Regular text<span>A span</span></div>',
|
|
|
|
|
'<div><p data-length=\'10\' class=\'some classes\'>Child paragraph with <a href=\'http://example.com\' >A link</a></p>Regular text<span>A span</span></div>',
|
|
|
|
|
'Attribute order, spacing and quotation marks (equal)'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.notHtmlEqual(
|
|
|
|
|
'<div><p class="some classes" data-length="10">Child paragraph with <a href="http://example.com">A link</a></p>Regular text<span>A span</span></div>',
|
|
|
|
|
'<div><p data-length=\'10\' class=\'some more classes\'>Child paragraph with <a href=\'http://example.com\' >A link</a></p>Regular text<span>A span</span></div>',
|
|
|
|
|
'Attribute order, spacing and quotation marks (not equal)'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.htmlEqual(
|
|
|
|
|
'<label for="firstname" accesskey="f" class="important">First</label><input id="firstname" /><label for="lastname" accesskey="l" class="minor">Last</label><input id="lastname" />',
|
|
|
|
|
'<label for="firstname" accesskey="f" class="important">First</label><input id="firstname" /><label for="lastname" accesskey="l" class="minor">Last</label><input id="lastname" />',
|
|
|
|
|
'Multiple root nodes (equal)'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.notHtmlEqual(
|
|
|
|
|
'<label for="firstname" accesskey="f" class="important">First</label><input id="firstname" /><label for="lastname" accesskey="l" class="minor">Last</label><input id="lastname" />',
|
|
|
|
|
'<label for="firstname" accesskey="f" class="important">First</label><input id="firstname" /><label for="lastname" accesskey="l" class="important" >Last</label><input id="lastname" />',
|
|
|
|
|
'Multiple root nodes (not equal, last label node is different)'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.htmlEqual(
|
|
|
|
|
'fo"o<br/>b>ar',
|
|
|
|
|
'fo"o<br/>b>ar',
|
|
|
|
|
'Extra escaping is equal'
|
|
|
|
|
);
|
|
|
|
|
assert.notHtmlEqual(
|
|
|
|
|
'foo<br/>bar',
|
|
|
|
|
'foo<br/>bar',
|
|
|
|
|
'Text escaping (not equal)'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.htmlEqual(
|
|
|
|
|
'foo<a href="http://example.com">example</a>bar',
|
|
|
|
|
'foo<a href="http://example.com">example</a>bar',
|
|
|
|
|
'Outer text nodes are compared (equal)'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.notHtmlEqual(
|
|
|
|
|
'foo<a href="http://example.com">example</a>bar',
|
|
|
|
|
'foo<a href="http://example.com">example</a>quux',
|
|
|
|
|
'Outer text nodes are compared (last text node different)'
|
|
|
|
|
);
|
|
|
|
|
} );
|
2013-03-06 00:56:15 +00:00
|
|
|
|
2022-04-27 00:02:24 +00:00
|
|
|
var beforeEachRan = false;
|
|
|
|
|
QUnit.module( 'testrunner-nested-hooks', {
|
|
|
|
|
beforeEach: function () {
|
|
|
|
|
beforeEachRan = true;
|
|
|
|
|
}
|
|
|
|
|
} );
|
2012-05-12 22:37:30 +00:00
|
|
|
|
2024-06-11 12:43:19 +00:00
|
|
|
QUnit.test( 'beforeEach', ( assert ) => {
|
2022-04-27 00:02:24 +00:00
|
|
|
assert.true( beforeEachRan );
|
|
|
|
|
} );
|
2017-07-17 19:29:11 +00:00
|
|
|
} );
|
|
|
|
|
|
2023-05-17 20:36:17 +00:00
|
|
|
QUnit.module( 'testrunner-next' );
|
2017-08-02 14:21:56 +00:00
|
|
|
|
2024-06-11 12:43:19 +00:00
|
|
|
QUnit.test( 'afterEach', ( assert ) => {
|
2022-04-27 00:02:24 +00:00
|
|
|
assert.strictEqual( mw.html.escape( '<' ), '<', 'mock not leaked to next module' );
|
|
|
|
|
assert.strictEqual( mw.config.get( 'testVar' ), null, 'config not leaked to next module' );
|
|
|
|
|
assert.strictEqual( mw.messages.get( 'testMsg' ), null, 'messages not lekaed to next module' );
|
2017-08-02 14:21:56 +00:00
|
|
|
} );
|
|
|
|
|
|
2018-08-29 04:46:30 +00:00
|
|
|
}() );
|