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
QUnit used to have bad state management (a few years ago) at which point it
became useful to verify the number of assertions in case an asynchronous
failure happened, as it would likely go unnoticed.
* Errors outside testStart/testEnd weren't caught.
QUnit now monitors window.onerror.
* Assertions could be attributed to the wrong test.
QUnit no longer does this since the assert object is associated with
the current test through lexical scope.
* assert.async()/done() replaced global semaphore (QUnit.start).
* A test could forget to be marked as async and make no assertions.
QUnit now marks a test as failed if it makes 0 assertions.
QUnit also has built-in async tracking for promises.
If a test is not reaching all assertions for some reason, this
will cause an error of some sort that is tracked. If in some
specific scenario this isn't the case, assert.expect() can still
be called (e.g. when expecting 0 assertions), but it'd be worthwhile
to file an upstream bug report in that case.
Follows-up 7c363752, which removed 'QUnit.config.requireExpects' from
our test configuration.
Follows-up c4c7007de6 and various other commits that already removed
the test counts from a subset tests. This commit removes the remainder.
Change-Id: Ie58396ba9c83d27220508481cb97c0fa74487756
As of jQuery 1.12, animations use requestAnimationFrame in modern
browsers, which cannot be forced to finish synchronously by merely
mocking the 'setTimeout' and 'Date' clocks via Sinon.
For jquery.color, reduce duration from 10ms to 3ms (not 10ms which will
now be real time, not 0ms since we do want to test real frames).
Change-Id: Ie147fc2a91d2cd349b4031390f3c59b1bcfb65b5
This has never been used outside mediawiki.js for things like mw.config,
and mw.messages.
The public API of those objects will remain, but the constructor will
no longer be supported in the future in order to allow these to be
backed by native Map in the future (with a minimal polyfill rather than
a complete one).
* Remove 'mw.Map(valuesObject)'. (follows-up 63f8d7b9e5).
This is incompatible with native Map and isn't actually used anywhere.
* Deprecate mw.Map#values. Undocumented and considered private.
A few uses have appeared in the wild so keep a short deprecation period.
* Update the MediaWiki QUnit runner to construct new maps in setup/teardown
instead of swapping the internal values object directly.
Also update the runner to update mediawiki.jqueryMsg's parser default since
it kept a reference to the first mw.messages object.
* Add 'logName' parameter to mw.log.deprecate(). Default logName
of property key made sense for its original use case (deprecation warnings
for global variables, which are a property of the window object). But
for keys of any other object, we'll want to some context for the name.
* Remove redundant test expect numbers. (Follows-up 7c36375, c4c7007d)
* Ensure mw.Map.prototype.constructor points to mw.Map.
This was broken by 5819c37b3, which accidentally made it point to Object.
Bug: T146432
Change-Id: I7ff0b230608f5ca582fc6752b59c4bb998c78ba2
Follows-up bc4e07b6f6.
In production mode, 'module' and 'require' are lexically provided
through closure to the executing script and will continue to be
accessible through the script's life-time.
In debug mode, the script executes without wrapper directly from
disk (and as such, in the global scope) and variables are provided
as global variables. Since a variable can only be set to one value,
we swap the object that 'module' points to after each file. And
to avoid leakage, it is removed in-between files and after the
last one. Aside from it being technically infeasible right now,
async access to 'module' is discouraged regardless.
Late access to 'require', however, is not uncommon and should
work as expected.
Bug: T144879
Change-Id: I6ede10fd42676bb035ea26c693c78bcdc1438a7d
* resources/src/startup.js: No more document.write() since
d7905627fd.
* tests/qunit/data/testrunner.js: No more document.write()
since 05f6edc903, and the TestSwarm agent loading
code was removed entirely in 0e9f24a169.
Change-Id: Iac61874e3ca04e1cad0d0fb2b7cebdc9fd4b237a
* Send 'module' and 'require' parameters to module closures.
This depends on Ia925844cc22f143 being deployed one cycle earlier.
* Patch Moment and OOjs to ensure these libraries continue to expose
their module as globals as well. AMD/UMD-compatible libraries
only expose a global *OR* an export, not both. We need both
for back-compat.
* Update pluralRuleParser to make use of module export to allow
usage via require().
To test, check out the patch and run:
> mw.loader.load('moment');
> mw.loader.require('moment')()
> mw.loader.require('moment')('2011-04-01').fromNow()
Bug: T108655
Change-Id: Idbd054880ee70d659ec760aef8fcb38d0704a394
Partially reverts 94c116240 and 7fd977b242 as it was incorrectly
split up. This should've been part of Idbd05488 instead of 94c116240.
Bug: T108655
Bug: T129776
Change-Id: Ia5e6e57c9bd651ec913a2543e2df8951ff345ea2
This hasn't been useful in QUnit for a while now with the improved
assertion context object and tracking of asynchronous tests without
shared global state.
Change-Id: Icaf865b4d6e85e739bf79c4d1bacb8a71ec5a3da