- 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
Sometimes $.active is non-zero but the ajaxRequests array doesn't
contain any pending requests (yet). In that case, log $.active
as well.
Change-Id: I1c181b1234d1f883605de38805bc029c064a1f5b
* jsonlint now includes docs/, includes/ (api and installer i18n),
maintenance/, and tests/.
539 files -> 864 files.
- Continue to exclude JSDuck artefacts in docs/js/.
- Continue to exclude vendor/.
* jshint now includes mw-config/ and maintenance/.
177 files -> 179 files.
* jscs now includes everything jshint includes.
172 files -> 179 files.
- The -skip.js files no longer need excluding.
Use the native exclude syntax for jshint and jscs so that other
software and services with JSHint support use these as well.
Change-Id: Idebf30275f9c93483069367f923ed290c38e0b26
Updating all non-third-party scripts to depend on 'dom-level2-shim'
and use the constants.
* jquery.highlightText
* jquery.tablesorter
* mediawiki.api.upload
* test.mediawiki.qunit.testrunner
Change-Id: Ib07dded9fa18c749b3c064ab90326852146567b2
This was causing pending (mocked) XHR requests to sometimes be
cleaned up prematurely.
As a general rule, setup always calls its parent first. And teardown
always calls its parent last. The inner callback runs within the
scope of the outer one and should still have acces to the sinon mocks.
Change-Id: Ic4d9243c04af73e529b689e650d35ddabaa7f4b9
I added this in the JSTesting branch back in SVN (r107521, merged in
r107919 for MediaWiki 1.19.0).
It was mostly for debugging the setup/teardown in the branch. It never
had much practical use.
Change-Id: I8d6eb9e06ad070c23cb9c9041b5cf4143ee6ac0b
Similar to what we do with animations already, ensure we give
the next test a clean start by aborting any requests that were
made during the test that are still pending.
Also log the details of the request (ajax options, e.g. url) to
the console.
To test:
* Add "sleep( 1 );" to LocalSettings.php.
* add "$.ajax( mw.util.wikiScript() )" to a test in mediawiki.util.test.js.
* Run Special:JavaScriptTest/qunit/plain?module=mediawiki.util
Change-Id: Iefef89effc092d296baa9df68a86d95497730708
To use, ensure npm modules are up to date by running 'npm install'
in tests/frontend. Then run 'grunt qunit' to run it in Chrome.
To run it in both Firefox and Chrome (locally), run
grunt karma:more
Moved fixture from hardcoded HTML to the testrunner so that our
tests don't depend on arbitrary HTML and thus also pass in browser
contexts where the page only loads QUnit + test suites (e.g. Karma).
Change-Id: I4e96da137340a28789b38940e75d4b6b8bc5d76a
The config variable itself and the documentation property were added
in MediaWiki 1.19 (r107919 / c447423593).
The testswarm-injectjs propert was added in MediaWiki 1.20 (5e590be3d6).
We never actually ended up using TestSwarm, and this variable
is not used anywhere I can see.
Having a configuration variable for a documentation page seems
odd. I can't find another instance of this. As it's tied to development
(not for users of the wiki), link to mediawiki.org direcly.
Change-Id: Ib16607683a293b6d6661ed0411dad9a3ff551a08
Having unfinished animations affect other test can be a problem,
but when it does happen, having just a number isn't helpful in
trying to pinpoint the cause.
Logging a description of the element should make this relatively
straight forward.
Also reset the animations after the test so that the next test has a
clean start (instead of the current situation where every subsequent
test, until the animation finishes, also reports it as a failure).
Example:
Unfinished animation #0 in fx queue on <div class="mw-notification
mw-notification-tag-legacy" style="opacity: 0; "/>
Change-Id: I41058c4cba3383e3ad1456990ccf8dae4ca64951
The default value of 10s is ocasionally failing when loading resources
via RL. Increase to 30s as suggested in the qunit documentation.
http://api.qunitjs.com/QUnit.config/#config-testTimeout
Change-Id: I288db068c8dd1041e0a9be959b3b0c6ddcc7606e
Follows-up b90c69cdf7.
This takes the approach of throwing an error to make the exact issue
obvious.
Unlike other versions (including the code in jQuery it is loosely
based on), this does not attempt to cleanup by stopping the effects
queue.
Change-Id: Ibb6ca0d083d4e8f1556e6f3493da17f7a5f44024
It was iterating over it and considering its 'script' properties
to be methods that had to be tested.
The CompletnessTest before this change is filled with stuff like:
- loader.moduleRegistry.skins.vector.js.script
- loader.moduleRegistry.mediawiki.api.script
- loader.moduleRegistry.mediawiki.Title.script
- ..
And was actually causing it to hit hard limit and thus actual
lots of actual methods were no longer inspected by the test.
Change-Id: I13fbf1224b48aa34a7bb01fdc0543023e502bb4f
A module can be registered with a skip function. Such function,
if provided, will be invoked by the client when a module is
queued for loading. If the function returns true, the client will
bypass any further loading action and mark the module as 'ready'.
This can be used to implement a feature test for a module
providing a shim or polyfill.
* Change visibility of method ResourceLoader::filter to public.
So that it can be invoked by ResourceLoaderStartupModule.
* Add option to suppress the cache key report in ResourceLoader::filter.
We usually only call the minifier once on an entire request
reponse (because it's all concatenated javascript or embedded
javascript in various different closures, still valid as one
large script) and only add a little bottom line for the cache
key. When embedding the skip function we have to run the minifier
on them separately as they're output as strings (not actual
functions). These strings are typically quite small and blowing
up the response with loads of cache keys is not desirable in
production.
* Add method to clear the static cache of ResourceLoader::inDebugMode.
Global static state is evil but, as long as we have it, we at
least need to clear it after switching contexts in the test suite.
Also:
* Remove obsolete setting of 'debug=true' in the FauxRequest in
ResourceLoaderTestCase. It already sets global wgResourceLoaderDebug
in the setUp() method.
Bug: 66390
Change-Id: I87a0ea888d791ad39f114380c42e2daeca470961
Tests should be atomic because when re-running failed tests, they
run out of order (by design).
The thing being asserted here wasn't all that useful as that is
upstream behaviour we ought to be able to rely on.
Change-Id: I2f006e1cf05f5535e8220ca8ffc2da603745d184
There are various tests triggering deprecation warnings because
they are testing deprecated functionality, on purpose.
Surpress these so that the logs aren't filled with false
positives in Jenkins.
Change-Id: I4bb546781a0c89999b2e5df7715abf492a44856d
* Set up Grunt via package.json (run `npm install` in mediawiki-core)
* Add grunt task for node-jscs (NEW)
This is a style checker (as opposed to jshint, which is for
code quality). There are a few small style-related things that
JSHint can check (camelcase, onevar etc.) but those are being
deprecated in JSHint v3, people should use more sophisticated
tools like node-jscs for this instead. As such this commit
removes moves of those options from our jshint configuration.
See: http://jshint.com/blog/jshint-3-plans/
* Add grunt task for jshint
This will use the same jshint configuration as we use on
Jenkins but makes it easier to run locally from the command
line by being part of the same `$ grunt test` task list.
Also:
* Changed jshintignore to use "dir/**"" instead of "/dir" or "dir"
because the latter is not compatible with Grunt for some reason.
See also https://github.com/gruntjs/grunt-contrib-jshint/issues/126.
Examples of coding style rules that were being violated that we
can now catch in node-jscs:
* Operator "," should stick to preceding expression
* Missing space after "if" keyword
* Multiple line break
* Empty block (in jquery.textSelection and mediawiki.language)
Bug: 54218
Change-Id: Ib9d7eab9f0d5cea5fb33f0b9f82e5554897fdfe0