aboutsummaryrefslogtreecommitdiffstats
path: root/tests/qunit
Commit message (Collapse)AuthorAgeFilesLines
* ResourceLoader: Improve error when including file in non-package moduleHannah Okwelum2025-03-251-0/+7
| | | | | | | | | | | | | | | | | | | The way ResourceLoaderModule is currently set up, when packagedFiles are used to declare files, only a "main" script is initially executed, and other files are executed with require("./file path"). This is not the same with using "scripts" to declare your module files. Such scripts are concatenated together into one large script, and require() can only load modules in this instant. When you use require() in such script (outside a package file), we directly use mw.loader.require(). What this fix does is, if require("./*") is encountered in mw.loader.require(), it throws a descriptive error early, instead of later in a more confusing way as `Module "." is not loaded`. Bug: T386833 Change-Id: I97a572c9fefa41e6b97db1d9fd86706490da5c4f
* tests: Sort large arrays in QUnitTestResourcesTim Starling2025-03-241-68/+70
| | | | | Depends-On: Ia5b7ebab3dd16ffb463b0d55979e0c094aa6b5ab Change-Id: Ib34a15f9c8e2d1e6e4488fe3523a2babb7174b08
* Merge "qunit: Move 'testrunner' tests to its own file"jenkins-bot2025-03-213-51/+51
|\
| * qunit: Move 'testrunner' tests to its own fileTimo Tijhof2025-03-193-51/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The environment checks in QUnit.begin() are important to run always, even when e.g. running with component=EventLogging as filter. However, the "testrunner" tests are only useful when changing the assert methods themselves. There is no need to re-run those, just as there as no need to run any other MediaWiki core tests, when testing a non-core component. By moving these out to their own file, part of the 'test.MediaWiki' module, these still run by default and when selecting "MediaWiki core" component, but not when selecting another component. Previously, if you selected e.g. component "EventLogging" the output contained a visible "testrunner" result, which was not part of that component which seems surprising/confusing and certainly not needed. Bug: T250045 Change-Id: I350adf0f9a39796f7052fd5b900acc0ca1a4d4e8
* | Merge "qunit: Add "Component" menu to QUnit toolbar"jenkins-bot2025-03-211-0/+16
|\|
| * qunit: Add "Component" menu to QUnit toolbarTimo Tijhof2025-03-191-0/+16
| | | | | | | | | | Bug: T250045 Change-Id: I53ec35a9b61c5fb8d6bba2cba4dfa21078f8ca2d
* | Merge "qunit: Remove 'debug' checkbox from SpecialJavaScriptTest"jenkins-bot2025-03-211-8/+0
|\|
| * qunit: Remove 'debug' checkbox from SpecialJavaScriptTestTimo Tijhof2025-03-191-8/+0
| | | | | | | | | | Bug: T250045 Change-Id: Ic8372862cb64cb64919e7dee174558243f33324f
* | build: Fix and re-enable eslint rule unicorn/prefer-includesJames D. Forrester2025-03-211-1/+1
|/ | | | Change-Id: I34bb289e941751ae4722c708511326a2a5431bfc
* Merge "mediawiki.api: Allow setting Api-User-Agent via mw.Api constructor"jenkins-bot2025-03-191-0/+12
|\
| * mediawiki.api: Allow setting Api-User-Agent via mw.Api constructorGergő Tisza2025-02-171-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allows passing a user agent in the constructor, which will be sent in the Api-User-Agent header (changing the User-Agent header is not possible under the browser security policy, and it also holds its own valuable information). Setting Api-User-Agent was possible already via the `headers` option, but was uglier and less obvious. Also, this patch adds a default of "MediaWiki-JS/<version>" * different from the MediaWiki PHP user agent ("MediaWiki/<version>"), * clearly related to MediaWiki frontend JavaScript * avoid generic words like "mw.Api" which are easily mistaken for any number of "MediaWiki" "API" things. Usage: const api = new mw.Api( { userAgent: 'MyGadget/1.0.1' } ); This allows gadgets, user scripts, MediaWiki core, and extension code to easily identify which client makes an API request. Identifying the client helps: * WMF and other sysadmins, to debug and find the source of a problem. * MediaWiki maintainers, to assess what disruption would be caused by backwards-incompatible changes in the API response or with proactively fixing clients before such changes. * Gadget and extension maintainers, by enabling them to use Special:ApiFeatureUsage to check whether they rely on deprecated APIs. Bug: T373874 Change-Id: I08cbe95675c7e3b6b3a20875f3d061afdc04efd6
* | build: Upgrade eslint-config-wikimedia to 0.29.1James D. Forrester2025-03-142-0/+2
| | | | | | | | | | | | Disable all new issues for now. Change-Id: Ib145e2cd4f455355bb11857ae68cd05cb432924e
* | language: fix mw.language.convertGrammar with word-specific casing rulesMáté Szabó2025-03-103-36/+95
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - mw.language.convertGrammar is responsible for implementing grammatical transformations for inflected languages, similar to its backend counterpart Language::convertGrammar. - The default implementation may be overridden by language-specific implementations loaded dynamically based on the user language. - Both the default implementation and all language-specific implementations suffer from a bug where requesting a case transformation for which word-specific casing rules are defined will return "undefined" if the case transformation was requested for a word for which no word-specific casing rule exists. - There are QUnit tests for the logic, but they only run if the user language matches the language being tested. This means they never run in CI and cannot even be run locally, since Special:JavaScriptTest has been forcing the user language to "qqx" for more than five years. What: - Place language-specific convertGrammar overrides into a new convertGrammarMapping property keyed by language code to allow loading more than one simultaneously. - Introduce and use a new 'mediawiki.language.grammar.testdata' test-only RL module that loads every language-specific convertGrammar override. - Introduce and use a new 'mediawiki.language.testdata' test-only RL module that loads language-specific rules for languages that we have QUnit tests for. Since this only covers less than two dozen languages, there'd be no value in loading this data for all 300+ languages supported by MediaWiki. - Update QUnit tests for convertGrammar to override the user language and language rules before each case. - Ensure word-specific casing rules always take precedence over language-specific convertGrammar implementations to avoid repeated boilerplate in language-specific code. - Don't attempt to use word-specific casing rules for words that do not have one. - As we're here, add matching PHPUnit tests for Language* subclasses that had preexisting QUnit tests but no PHPUnit tests. Bug: T388370 Change-Id: I3f2432f5f801c2a7e4390c2ff2038363a36e2ed9
* | ResourceLoader: Add mw.hook#deprecate() methodMusikAnimal2025-03-061-0/+77
| | | | | | | | | | | | | | | | | | | | | | | | When called, registering hook handlers will log a deprecation warning via mw.log.makeDeprecated() with the key 'hook_myhookname'. Deprecation warnings are logged for every handler, only if there is at least one handler. Bug: T383381 Co-authored-by: Timo Tijhof <krinkle@fastmail.com> Change-Id: Ia8717563d09d7076cee0a1344fc82c66dc0a1e10
* | linker: Render expired temporary account names differentlyMáté Szabó2025-02-202-0/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - We would like to make the user links associated with expired temporary accounts visually distinguishable from non-expired ones using strikethrough styling and an information tooltip. - The designs call for using Codex tooltips for the latter. Using the Vue directive for this would require us to take a dependency on Codex and Vue for every page that renders user links, and render a small Vue.js app for each expired temporary user link, which does not seem practical. - We can, however, use Codex styles and implement our own simple tooltip functionality without taking on unnecessary dependencies. - This requires adding a new RL module to every page that uses userLink(), so we should update userLink() to do this for us instead of having to update every core and extension page that needs this. What: - Add a strikethrough to expired temporary account links as per the design specification. - Render a tooltip, hidden by default, for expired temporary account links that is styled using Codex styles. - Implement a simple jQuery tooltip handler for expired temporary account links. - Avoid caching expired temporary account link in UserLinkRenderer to ensure each of them receives a unique ID. - Add required ResourceLoader modules directly to the output in userLink(). Bug: T358469 Change-Id: I4f70ff15becbc4991c4f1b0307a14d5354c79dc1
* | jquery.tablesorter: Silence an expected "sort-rowspan-error" warningTimo Tijhof2025-01-271-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | > WARNING: (sort-rowspan-error) This is contributing to warning fatigue in CI, with other stuff slipping in and being missed because it is missed in the normalcy and the noise. This test case is confirming that invalid rowspans degrade gracefully, which may indeed emit a warning. Bug: T250045 Change-Id: I002b5f68078dee5821d20451131bbffe878684ea
* | ResourceLoader: Silence "unavailable module" warning in error handling testTimo Tijhof2025-01-271-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is contributing to warning fatigue in CI, with other stuff slipping and being missed because it's normal. > Skipped unavailable module test.load.circleC > Skipped unavailable module test.load.circle > Skipped unavailable module test.load.missingdep These are expected warnings for these specific error handling tests. The test already silenced the "error" to avoid a test failure, but it did not yet silence the warning that goes along with it. Bug: T250045 Change-Id: I492e31f2fc2e3342742a10d9fe14a00badca5657
* | mediawiki.api: Remove console warning for legacy token typeTimo Tijhof2025-01-271-6/+6
|/ | | | | | | | | | | | | | | | | | | | | The following warnings are logged to the browser console (and e.g. on the CLI from `npm run qunit` in MediaWiki): > Use of the "options" token is deprecated. Use "csrf" instead. > Use of the "email" token is deprecated. Use "csrf" instead. This is contributing to warning fatigue in CI, with other stuff slipping and being missed because it's normal. We could call suppressWarnings(), or sinon.stub(mw.log, 'warn'). But, in this case I think we can just remove it at the source as the warning isn't helping anyone. These types are part of the stable interface for mw.Api, and have been for 10+ years. Remove the obsolete logging code. Bug: T250045 Change-Id: Ibcbc32e3ad9e0afe14199d220757801bae9ad0a4
* resources: Use simple for-in instead of Object.keys().forEach()Timo Tijhof2025-01-141-2/+2
| | | | | | Follows-up If16d0a3682047537d0a089cddaec58b7c1dec7c8. Change-Id: I725bb89cfa8330ce29876f3e3f6720c92a72b020
* mediawiki.api: Fix tests depending on script pathBartosz Dziewoński2024-12-281-6/+6
| | | | | | | I noticed these tests failing locally on Special:JavaScriptTest. We already follow a similar pattern in other tests in this file. Change-Id: Ibf6c6cfc4ab9bde4323ca1b253e98d8b9874f2fc
* mediawiki.api: Adopt async-await and assert.rejects() in various testsTimo Tijhof2024-12-282-114/+112
| | | | | | | | | | | | | | | | | | | | * Follows-up Iec338e9f595b452c1, which added calls to a non-existent `assert.fail()` function. We can use assert.rejects() on any promise to assert that it must be rejected, and thus will fail the test for us if that promise gets resolved/succeeds instead. https://qunitjs.com/api/assert/rejects/ * Remove most nesting and chaining so that assertions all remain directly and flat inside the test function, for improved confidence and readability of the test. This is similar to how mediawiki.rest.test.js was mostly written already. * Replace loose partial regex checks, which are prone to false positives and produce little to no debugging information when they fail, with strict full assertions. https://timotijhof.net/posts/2015/qunit-anti-patterns/ Change-Id: If16d0fe50230eae69e39eed93ea1d6715ad9e865
* mediawiki.api: Add "fallback" test for FormData supportTimo Tijhof2024-12-281-11/+31
| | | | | | | | | | | | | | | Previously it ran one with a conditional for the current browser, which means in practice the fallback is never tested during development nor in CI. Split it up with the native test conditional on browser support, and the fallback always run as well. Replace loose partial regex checks, which are prone to false positives and produce little to no debugging information when they fail, with strict full assertions. Change-Id: I3fb63ff4850216652b95a3c3ab9122a9788820fa
* Merge "mw.Api: Introduce abort signals"jenkins-bot2024-12-241-0/+77
|\
| * mw.Api: Introduce abort signalsBartosz Dziewoński2024-12-051-0/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a `signal` option to mw.Api#ajax and related methods, which allows the HTTP request(s) to be cancelled. The interface is inspired by the Fetch API, and uses the same AbortController/AbortSignal classes. Cancelling a request this way rejects it with a DOMException rather than a 'http' error code, similarly to native fetch() function. For compatibility (some browsers we support may not have a working AbortController; it's a weird situation, see comments in the code), provide our own implementation at mw.Api.AbortController. Add better documentation for the existing style of cancelling promises too, documented as mw.Api~AbortablePromise. It's not an actual class, since the 'abort' method is added ad-hoc, just an alias for the docs. mw.Api extensions can support both AbortSignal and AbortablePromise, but it's a bit tricky to do. Add mw.Api.makeAbortablePromise() to help with that, and explain how to do it in its documentation. Update a few uses of the previous style, which either chained promises in a complex way, or complained about the 'abort' method in comments. I've left the simple cases unchanged, to show it's still supported. (By the way, everything is called "abortable"/"aborted" rather than "cancellable"/"cancelled", even though that's a nicer term, to avoid confusion about whether these words have one or two 'l's.) Depends-On: I7ff705af79760e33200a2dfbfdd05138c18bb110 Needed-By: I3a3ca1b32af58f396b66802a3d435b4c9d137e14 Needed-By: Ia803b4eab766768c2c8a096c308958b48eb34af2 Bug: T346984 Change-Id: Iec338e9f595b452c19ce8e74eb81339fbce11640
* | Always prevent API calls if user input widget only accepts IPsDreamy Jazz2024-12-062-0/+51
|/ | | | | | | | | | | | | | | | | | | | | | | | Why: * The mediawiki.widgets.UserInputWidget was updated in 00f2cd7eb3e75f47f2db2549f8daed24e1138780 to prevent autocomplete if only IPs are accepted. * However, this fix seems to either not have worked or broken since the merge and as such API requests which will never return any usernames are made. * This commit fixes this issue and adds a regression test to verify that this fix continues to work. What: * Update mw.widgets.UserInputWidget to override the ::setLookupsDisabled method, such that if the configuration passed in the constructor excludes temporary accounts and named accounts the method will ignore attempts to re-enable lookups. * Add QUnit tests for the JS file which was previously untested, so that the fix can be verified to continue to work. Bug: T380407 Change-Id: I0aed79bd23ea4e77345ae5ecc750d40defd165cd
* Support `{{fullurl:}}` in jqueryMsgJon Harald Søby2024-11-221-0/+30
| | | | | | | | Add support for the `{{fullurl:}}` magic word to jqueryMsg so that it may be used in JavaScript messages. Bug: T379425 Change-Id: If646731874c8cd5e64328795273dfd27d0d65027
* mediawiki.deflate: Support 'deflate' as well as 'deflate-raw'Ed Sanders2024-11-211-28/+56
| | | | | | | | | The latter was only added in Chrome 103, as opposed to Chrome 80. 'deflate-raw' just removes the header and checksum which we can do manually. Change-Id: Ia26768e080663be3615184e117bed20e978a91fa
* Merge "mediawiki.deflate: Add mw.deflateAsync which can use CompressionStream"jenkins-bot2024-11-211-14/+63
|\
| * mediawiki.deflate: Add mw.deflateAsync which can use CompressionStreamEd Sanders2024-11-211-14/+63
| | | | | | | | | | | | | | | | | | | | | | To avoid a breaking change, introduce a new function name as CompressionStream is asynchronous. Once mw.deflate can be removed, we can add skip function for pako based on the availability of CompressionStream. Bug: T235237 Change-Id: I722ebb03c0db7c7b3ee16cc8881e41909142cee9
* | ResourceLoader: Support multiple mw.track() data argumentsTimo Tijhof2024-11-181-5/+17
| | | | | | | | | | Bug: T355837 Change-Id: I020d1a157423a2f50836ff8e164760692a994d94
* | ResourceLoader: Remove unused 'thisValue' from mw.trackSubscribeTimo Tijhof2024-11-181-6/+5
|/ | | | | | | | | | | | | | | | | | This exposed the internal queue structure, which thus means that future changes to this structure are noticable through the public interface (mw.trackSubscribe callbacks). Those callbacks could rely on the presence of a specific property, or perhaps modify or merge it with something else, and thus also rely on the absence of certain properties that they added themselves before or after that merge. Avoid this by removing support for it. It was introduced in 2013 with I8c7af097e6 (873b60f194), but never used: https://codesearch.wmcloud.org/deployed/?q=mw.trackSubscribe%7Cthis%5C.topic%5Cb&files=js%24&excludeFiles=test%7Cnode_modules Change-Id: I2d9bc9b7228ab5f2df2160181f41c40cce8f42b6
* mw.jqueryMsg: Allow complex expressions in parser functions' first paramBartosz Dziewoński2024-11-091-0/+15
| | | | | | | | | | | | | | When parsing wikitext like `{{func:a|b|c}}`, jqueryMsg accepted multiple expressions in the parameters following '|' (which are handled by templateParam()), but not in the first parameter following ':' (which is handled by templateWithOutReplacement()). So, `{{#FORMAL:Informal hello|{{GENDER:|Formal}} hello}}` worked, but `{{#FORMAL:{{GENDER:|Informal}} hello|Formal hello}}` didn't. Now they both work. Bug: T379418 Change-Id: Ia4d57fd953dbd34e45789208ec8e765cce6ddf15
* Remove unnecessary local context variablesEd Sanders2024-11-081-6/+4
| | | | Change-Id: I52fdc5e5bc64bbe7ea895b9d7106dd3c99b0a908
* Merge "Support 'include' parameter in namespace select inputs"jenkins-bot2024-10-302-0/+27
|\
| * Support 'include' parameter in namespace select inputsSTran2024-10-302-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Namespace select inputs already support an 'exclude' parameter, ignoring any namespaces that match ids in that array. For Special:GlobalContributions, it would be useful to have the opposite - an array of namespaces to be included, as it only wants to support filtering on common namespaces. - Allow an 'include' parameter to be passed through to the namespace select input - Support 'include' in Html inputs and OOUI inputs TODO: Support 'include in Codex inputs (see T378582) Bug: T378179 Change-Id: I4170beb588292fbec26926ca3afe559c25de9f55
* | Tests: Expand tests for messageBox functionJon Robson2024-10-291-0/+9
|/ | | | | | | Follow up to Ic262b6c5ce5032f04a950299fb88b606d5c6c881 Bug: T376390 Change-Id: Ib3fce566184ab00eb329d465d640430ed2b6db7e
* Support {{#FORMAL:}} syntax in jqueryMsgJon Harald Søby2024-10-221-0/+16
| | | | | | | | | Add support for the new {{#FORMAL:}} syntax in jqueryMsg. Add formalityIndex to mw.language.data, and add parsing for this syntax mediawiki.jqueryMsg.js. Bug: T366602 Change-Id: Idc6ce0d590729830fd734cccae860f2430b8475c
* tests: Use namespaced classesUmherirrender2024-10-211-0/+1
| | | | | | | | Changes to the use statements and some additions are done automatically via script This also updates @covers tag for the namespaced classes Change-Id: I859ba6d05018c99710b744e2becab432410d3bca
* eslint: Promote 'prefer-const' to error in testsBartosz Dziewoński2024-10-061-1/+0
| | | | | | Follow-up to 7675004bbec95990b20b4fc96aa34beeecc32d5e. Change-Id: Ic0f9acdb0d4ee53fb198c2c0c5ff61c738dd2089
* eslint: Manually enforce prefer-const in testsEd Sanders2024-10-0421-261/+167
| | | | Change-Id: I551cdcc1b115b3f30178e35968419714cdf87fca
* eslint: Enforce no-var in tests and autofixEd Sanders2024-10-0442-453/+453
| | | | Change-Id: Ic7f37dee01dfcf62ecade4bd9277188e27540443
* Re-apply "Rename wgPageContentLanguage to wgPageViewLanguage"Fomafix2024-10-021-5/+5
| | | | | | | | | | | The value of wgPageContentLanguage was changed to "page view language" rather than "page content language" in 44725333f. The naming is confusing and should be renamed to wgPageViewLanguage. This change reverts d2aa7d594945edbe5d597da6b89ac59a1b2dde79. Bug: T303375 Change-Id: Ibe0ed6ec2a7fe042482564970e05d360b89841fe
* Fix styling of message boxes on create account page, adds stable APIJon Robson2024-09-271-0/+10
| | | | | | | | | | | | The stable API mw.util.messageBox is added. This matches the existing Html::messageBox method and provides a stable way to render messages on the client going forward. Since these are often used by gadgets and in extensions this seems like a good idea to allow us to easily change the HTML in future without breaking things and to detect usage more easily. Bug: T375519 Change-Id: If864607cbece899222afba57ca4bfe2f72f9dcfe
* Merge "Use spread operator and variadic params in more places in JS"jenkins-bot2024-09-174-5/+5
|\
| * Use spread operator and variadic params in more places in JSBartosz Dziewoński2024-09-174-5/+5
| | | | | | | | Change-Id: I537f5948e9d8e4b0f420705df806307f5535d681
* | Deprecate mw.cookie.getCrossSite()Bartosz Dziewoński2024-09-171-14/+0
|/ | | | | | | Follow-up to 380d398f1d0cc86dd5f1b008d2dd3e792b003b30, 7c81d82d764eec99ff59c008270c7d66556d8f92. Change-Id: I53e9f51e178087725afbc1ed681113807aa58110
* Remove an unused method in mediawiki.rcfiltersEbrahim Byagowi2024-09-141-43/+0
| | | | | | | doesQueryContainRecognizedParams of UriProcessor doesn't seem to be used anywhere. Change-Id: I8ad54297c41f21bf74f9bb9aac96a616a09a2402
* Merge "tests: Use const for some static data in test files"jenkins-bot2024-09-041-4/+4
|\
| * tests: Use const for some static data in test filesUmherirrender2024-09-011-4/+4
| | | | | | | | Change-Id: Id7ccd48e3bf626095e2d3929831b5d87ed0be948
* | qunit: Replace slow mw.messages reset with empty object resetTimo Tijhof2024-09-023-8/+16
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use an empty object, which is fast to create, instead of deep clone that preserves and restores the initial server response for mw.messages On mediawiki-wmf-quibble with 2000 tests, reduces newMwEnvironment_beforeEach from 3.7s to 0.7s, saving 3 whole seconds on the CI run. The total for QUnit is ~37s after this, down from ~40s. ResourceLoader runs tests with lang=qqx so tests shouldn't rely on these anyway since all mw.messages contains is thousands of key-value pairs with qqx placeholder data like `{"foo":"(foo)"}`. == Changes == * Fix qqx mode to work for non-existent messages, for consistency with how MediaWiki does this in PHP. Otherwise, tests that expect "(foo)" or "(foo: abc)" as part of an assertion, would start to fail. As of writing, no frontend tests in MediaWiki core assert data containing localisation messages, but there are 27 tests in bundled/WMF-deployed extensions that do so, including CheckUser (ext.checkUser.checkuser.getUsersBlockForm), Wikibase (jquery.wikibase.descriptionview), and VisualEditor (ve.ui.MWAddParameterPage). * Document why this code checks for "(foo)", which was added in I3f2a6ceb24 (616b6176db, T222944). Bug: T225730 Bug: T250045 Depends-On: I6348e5ae00776c2c01d91fa90a431b6ffe3da25d Change-Id: I3a4024ccf90e50558152d4ee012e492f49e14a0e