* Update digitGroupingPattern to match CLDR 31: New versions of CLDR has
digit grouping pattern with decimal part. Update digitGroupingPattern
values in Message classes with this improved pattern.
Refer: http://unicode.org/reports/tr35/tr35-numbers.html
* Refer the following chart for the decimal patterns.
http://www.unicode.org/cldr/charts/31/by_type/numbers.number_formatting_patterns.html
* Uses PHP NumberFormatter class for the commafy implementation, which
is available in PHP 7.
* Some tests need to update to match the TR 35 spec
* The formatNum public method in Language.php is the preferred way to
use this feature. It does separator transformation and digit transformation
wherever applicable.
* Renamed the second param name for formatNum from noCommafy to noSeparators
* commafy method is deprecated and formatNum is preferred. Practically,
we are not just adding comma, but seperators according to the language.
Replaced some tests based on commafy methods with tests based on formatNum.
Note: The corresponding js implementation is not changed in this commit.
It would probably be a good idea to use globalize.js, which is also based
on the CLDR patterns.
Note: This patch preserves the existing off-by-one error in
$minimumGroupingDigits; T262500 will eventually fix this.
Bug: T167088
Co-Authored-By: C. Scott Ananian <cscott@cscott.net>
Change-Id: Ic721b9a91e78e4ef07040339d1006b7a90a910c0
=== Observe the bug
1. Run Special:JavaScriptTest
(add ?module=mediawiki.loader to run only the relevant tests)
2. In the Network panel, check the JS requests to load.mock.php?…
3. Without this patch, they are like:
"load.mock.php?1234?lang=en&modules=…&…"
With this patch, they are like:
"load.mock.php?lang=en&modules=…&…"
The question mark is only valid as the start of the query string,
not as divider between them. This means without this patch, the
"lang" parameter is simply ignored because it becomes part
of the key "1234?lang" with value "en".
=== What
The mock server doesn't do anything with "lang". And given that
RL sorts its query parameters for optimum cache-hit rate, the
corrupted parameter is always "lang", as its sorts before
"module" or "version", which our mock server does utilize.
As part of server-side compression of the startup module (d13e5b75),
we filter redundant base parameters that match the default. For
RLContext, this is `{ debug: false, lang: qqx, skin: fallback }`.
As such, if one were to mock the localisation backend with
uselang=qqx internally, the "lang" parameter will not need to be
sent, and thus the above bug will start corrupting the "modules"
paramater instead, which our test suite correctly detects as being
very badly broken.
=== Why
mediawiki.loader.test.js used QUnit.fixurl() as paranoid way to
avoid accidental caching. This blindly adds "?<random>" to the
url. Upstream QUnit assumes the URL will be a simple file on disk,
not expecting existing query parameters.
=== Fix
* Removing the call to QUnit.fixurl(). It was set by me years ago.
But, there is no reason to believe a browser would cache this
anyway. Plus, the file hardly ever changes. Just in case,
set a no-cache header on the server side instead.
* Relatedly, the export of $VARS.reqBase is an associative array in
PHP and becomes an object in JSON. Make sure this works even if
the PHP array is empty, by casting to an object. Otherwise, it
becomes `[]` instead of `{}` given an PHP php array is ambiguous
in terms of whether it is meant as hashtable or list.
Bug: T250045
Change-Id: I3b8ff427577af9df3f1c26500ecf3646973ad34c
This test was an awful, awful, mess. (And I take full responsibility.)
Changing the global user language mid-way into execution is in no way
supported by ResourceLoader and this test was going through great
lengths to fool mw.loader about what's really going on.
Basically, all we're doing is get a list of instructions on what tests
to run, get comparison values based how the PHP side proceses these
(for parity comparison), and then run the assertions.
The mw.language singleton already has support for multiple languages,
and mediawiki.jqueryMsg already supports injecting data and constructing
new instances for each test case. Make use of that :)
Instead of calling ResourceLoaderLanguageDataModule::getData by
trying to hot load the same module repeatedly from load.php,
just export this data using 'packageFiles'.
The mediawiki.jqueryMsg QUnit suite previously took 4s to run locally
and now only 0.1s (145ms). This is not only significant for this
particular module, but also for QUnit in general as Headless Chrome
only took about 7s to run all of MediaWiki core's test suites prior
to this change, which is now down to ~3s. (MacBook Pro)
For WMF CI:
* Before (master commit):
- mediawiki.jqueryMsg.test: ~2.1s (2135ms)
- MediaWiki core total: ~4.8s
* After (this patch):
- mediawiki.jqueryMsg.test: ~0.015s (15ms)
- MediaWiki core total: ~3.6s
Bug: T250045
Bug: T225730
Change-Id: I5f1067feb0a43d63bfc5e7fff5110285a5e433c8
This will make it easy to later allow the user to select which
component's specs to load and run (via CLI and GUI), e.g. for
an entire extension. We currently only have very narrow or very
wide selection mechanisms ('module' param for 1 module,
'rerun' for 1 test case, 'filter' param for global pattern match).
Bug: T250045
Depends-On: I55fe27e1c74972fcb3cdafefdc78e10e24f95b80
Change-Id: I5c01f720d787c3847228de511ce913284786ad66
The `@alternateClassName` feature does not map cleanly to
JSDoc, so reduce its use to make the migration smoother.
Also, it was my intention to only use `@alternateClassName`
as a way to overcome limitations in JSDuck and/or as a stop-gap
to document hacky or overly clever code, not as a general way
to just randomly have two names for the same thing within docs.
* jqXHR: Just use jQuery.jqXHR instead. Also add missing
inheritence to Promise.
* mediaWiki: Just use mw instead. It's already discouraged
in real code, we really don't need to allow it within
doc typehints.
Bug: T138401
Change-Id: I915f747e440bad8f9bb2c11f35abc32ebdb69247
Previously removed from includes/ already.
Also remove odd `@package`, which we never use.
And remove `@since` which doesn't make sense for test-only files.
Change-Id: Ib7265d39329ecadd5279b11820f77f54189b55d2
This has always been an odd case, as indicicated by the cross-class
comment references, and the fact that its test cases are already
in ResourceLoaderTest.php, for convenience, as that's also where
the creation of 'module name strings' is done and tested.
Actually move it there instead of pretending it is there.
Change-Id: Ied9569436cc78704a5c1b75eeebb73f8631350f6
Provides a friendly wrapper for loading scripts using $.ajax().
Returns a promise when the script dependency -- a single
script url -- has been loaded. This matches how mw.loader.load
is able to load a script url, and how mw.loader.using will
return a promised that is resolved when dependecies are loaded,
or rejected if there is an error.
Added as a separate function mw.loader.getScript(), rather
than adding this functionality to using(), as it is a separate
use case, less confusing for users, and there is no shared or
duplicated code between loading a script and loading one
or more named modules.
Bug: T27962
Change-Id: I13be426d03261a2d0c6a1631af94a9f9af58394b
Follows-up Id6d13bbea6:
- '$': mw.loader.implement does this already.
- 'mw': Use the canonical name directly.
This replaces the following patterns:
File closures (common):
- `( function ( $, mw ) {` => `( function () {`
- `( function ( $ ) {` => `( function () {`
- `( function ( mw ) {` => `( function () {`
- `( function ( mw, $ ) {` => `( function () {`
File closures (rare):
- `( function ( mw, $, OO ) {` => `( function () {`
- `( function ( mw, OO, $ ) {` => `( function () {`
- `( function ( mw, document ) {` => `( function () {`
Combined dom-ready and file closure (rare):
- `jQuery( function ( $ ) {` => `$( function () {
- `jQuery( function () {` => `$( function () {
Remaining references in files without a closure, as found by
the new ESLint setting (rare):
- `jQuery` => `$`
- `mediaWiki` => `mw`
Change-Id: I7cf2426cde597259e8c6f3f6f615a1a81a0ca82b
Even though Array.prototype.forEach only works on arrays, and
$.each is more generic, I think it makes sense to begin discouraging
the usage of $.each now. This can be overriden by ignore lines or
by Array.prototype.forEach compatible lines. This doesn't seem too
much of an ask of engineers and helps future migrations
Bug: T200877
Change-Id: I339cff311a830699c8e32f07cec338a39870c53f
This has no usage in non-test code anywhere in Wikimedia Git,
and was only used in the test suite for mw.loader in core,
and in the test suite for the NavigationTiming extension.
The core usage is as part of this commit. The usage in NavTiming
is updated by I240ced4e65988f9.
Bug: T127328
Depends-On: I240ced4e65988f96c7ece3772378c2c9a335fb9a
Change-Id: Ic17c797e528feaf07a4777709d705615fea353e5
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '
(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)
Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).
Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
Disable it in specific files and places where there are legitimate uses
to access $_GET and $_POST directly.
For EditPage, which wants to output $_POST for debugging information,
introduce WebRequest::getPostValues() as a wrapper, matching the
existing ::getQueryValues().
Change-Id: I2cb0a7012fb7ed29dcd720056b42f56508ddc5fa
This class is marked @private, but nonetheless, there is at least
one use in MobileFrontend, so keeping a back-compat alias for now.
Also rename the HtmlEmitter utility class (also private, not used
anywhere outside this file), and fix its broken documentation by
repeating the @class and @private tags on its own constructor.
It previously had all its methods indexed by JSDuck as part of the
previous class in that file (Parser), which created doc pages
with examples that don't work.
Change-Id: I02d851d9b6eac89f1a2b85b438b982bd055bedee
The 'version' param was being computed based on the order of the modules list
before we perform string compression. And this compression can change the order
for its optimisation purposes.
Specifically, when requesting modules like 'a', 'b.1', 'b.2' and 'c'. The
version was computed based on a + b.1 + b.2 + c (standard sort order),
whereas the optimised list is 'a,c|b.1,2', which expands to a + c + b.1 + b.2,
which makes hash validation fail.
Bug: T188076
Change-Id: I00d6985c054fecd88acf73041aa02878e83d62bc
Previously, the 'version' query parameter was computed before request-splitting
which meant that all requests within the same 'source/group'-batch carried the
same 'version' parameter. This was then consistently rejected on the server due
to it not batching the combined hash of modules for any given request.
In practice this happened very rarely (if at all) in production, because
urls don't usually hit anywhere near 2000 in common use.
Bug: T188076
Change-Id: I211523d4781623873887a05d048f56cccd28432c
The load.mock.php has some module implementation stubs that call global
QUnit methods. This has been broken since the upgrade to QUnit 2, which removed
support for these (deprecated) methods, in favour of context-based assert.
However, this went unnoticed because these stubs are only there to make
our test fail if code is behaving incorrectly. Naturally, this isn't the
case normally. In theory, any unmerged code between QUnit 2 upgrade and now
would've failed Jenkins for something like 'QUnit.ok undefined' instead of
the more descriptive error message the stub supplies.
Fix this by instead statically exposing the contextual assert object
to the stubs.
Also centralise the clean up (teardown) for this new exposure, and also
clean up the other static exposure we have (testCallback) in the same way,
and document the cases where we intentionally clean it up inline.
Change-Id: I00b71e7bc9aa97275dfabf1070c4141fa76adb05
It previously depended on Xml.php for Xml::encodeJsCall, which
in turn depends on FormatJson. Other Xml.php methods also depend
on Sanitizer, but that was carefully not triggered.
Avoid both of these by simply constructing the string inline,
and using json_encode() directly for the one variable parameter.
Also, fix the names of one of the ResourceLoaderTest cases for
dotless module names. It claims to have been added to cover a
regression fixed in r88706, but that commit seems rather unrelated.
A bit of searching revealed as the relevant commit instead.
Bug: T188076
Change-Id: I04851d0355227f3a6b79b8d41a51d4beadce0e80
Follows-up 5a49381406, 43dc5c1539, 2454f51b27.
* Merge the three QUnit.module extensions into one.
* Change makeSafeEnv() to use Object.create() instead of creating
a simplified objects so that other properties are still accessible.
The 'testrunner-nested > Dummy' test now actually runs,
previously it was lost.
Change-Id: Id4aeb93582f8cc73b0dffe768a7864002ec85deb
Replace
* $.each( array, function ( index, value ) { ... } ) by
array.forEach( function ( value, index ) { ... } )
* $.grep( array, function ( value ) { ... } ) by
array.filter( function ( value ) { ... } )
* $.map( array, function ( value ) { ... } ) by
array.map( function ( value ) { ... } )
This change is a follow-up to 9d67e9973e.
Change-Id: I8ef9af8c4d2f440faca65ec7c78a977ea7c31ad2
- mostly auto fixes
- some too long lines fixed
- ignore amp space in one case passing by reference
Change-Id: I6472f83bc3cbf4bd629d83050cc3319b19ec465c
* Nested modules:
- Support for Sinon extension was fixed by Ib17bbbef45b2bd.
- Support for Fixture extension was still broken, masked by the use
of a local variable that made the handler not fail when setup ran twice
in a row. Fixed using the same moduleStack.length check.
- Add regression test.
* beforeEach/afterEach:
- Added in 1.16, with compat for setup/teardown.
Our wrapper adds its own setup/teardown, and preserves any original one.
However, it didn't account for beforeEach/afterEach, so it ends up
sending both but only one is used.
- Fix to support both on the incoming localEnv object, and also switch
our wrapper to use beforeEach/afterEach in prep for QUnit 2.0.
- Fix our wrappers to preserve return value since QUnit 2 allows beforeEach
and afterEach hooks to be asynchronous by returning a Promise, similar
to how one can do from QUnit.test().
- Add regression test.
* Centralise makeSafeEnv logic
- We always create our own env object to pass to orgModule().
Document why this is (to avoid recursion).
- Add regression test.
* Custom assertion methods:
- Use this.pushResult instead of the deprecated QUnit.push() method.
This also improves the in-browser reporting of errors by properly
supporting 'negative' results for notHtmlEqual reporter.
Bug: T170515
Change-Id: If4141df10eae55cbe8a5ca7a26707be1cd7b9217
Follows-up 0a208911a2, which added support for the `executeNow`
parameter to QUnit.module.
To properly support nested modules, we also need to skip registering
a second setup and teardown because nested modules already run the
beforeEach (setup), and afterEach (teardown), of their parent modules.
During setup this would needlessly create two sandboxes and override
the 'sandbox' property on the same 'this' context object. During
teardown it would fail because the inner module's teardown would
have already torn down the sandbox.
Change-Id: Ib17bbbef45b2bd0247979cf0fa8aed17800c54a0
Deprecated since QUnit 1.16, removed in QUnit 2.0. (We're on 1.23 currently.)
Migrate to assert.async().
This is a fairly atypical use of QUnit.start(), because it functions here
as a cross-script callback, where lexical scope cannot be used to share
the async() callback directly.
Other mw.loader tests already solved this by using a static callback instead
which inherits the lexical scope from the test to call done(). The old
'qunitOkCall' script is no longer used after this and thus removed.
Change-Id: I430df14b35a69c71df8685494d1379e22af0d6df
Stopping the animation is essentially the same as pausing, it remains in the
animation registry and will continue to fail all subsequent tests until one
of those later tests starts the animation queue again and also happens to
wait long enough for this unrelated animation to finish.
Fix the testrunner to actually fully stop the pre-existing animations, which
requires clearing $.timers as well. This matches the logic we have for
pending ajax requests.
Bug: T163211
Change-Id: Ic7d848187bc3c800e8347e0650093b2ffce6dddc
* Move `restoreWarnings()` in tearDown() to the mirrored location
of related code in setUp().
* Ensure that accidentally calling `suppressWarnings()` twice will
not wipe out the original reference indefinitely. If it was
already set, subsequent calls should do nothing instead of
overwriting them again so that recovery is still possible.
* Log all ajax requests logged during the test, not just the
one currently still pending. This should avoid situations
where we throw "Pending ajax requests" but no information
is logged about which requests those might be.
Change-Id: I900ad98c4c8520bdd6ae00a24ac82272f3becfee
The CompletenessTest was my attempt at measuring a basic code coverage
using run-time inspection instead of static instrumentation.
Originally added in 540419a82e (2010; MediaWiki 1.17).
It was never finished, remained fairly buggy and disabled by default.
It is also no longer used anywhere.
Bug: T155194
Change-Id: I26e7466426dddb43596f402e31005a89060c1b96
Follows-up c0fb8a8836, I890e6e49b.
* Disable 'qunit' env in general source code. And re-declare
locally in the few src files that use it properly.
* Create separate eslint config for tests/qunit with various
rules disabled (e.g. valid-jsdoc and es3-keywords).
Change-Id: I37ccec2019de55edfee92697eb80478df7cb6220