Commit graph

15 commits

Author SHA1 Message Date
daniel
d7ed4b14bb REST: validate JSON in tests
This applies JSON Schema validation in phpunit tests where appropriate:

1) In ModuleSpecHandlerTest, the generated OpenApi specs are validated
against the OpenAPI 3 schema.

2) In RestStructureTest, module definition files are validated against
   the mwapi schema.

This patch introduces a new trait to make it easy for phpunit test cases
to perform validation.

This patch also fixes some issues with the docs/rest/mwapi-1.0.json
schema and the includes/Rest/content.v1.json module definition.

Change-Id: I966cddb337c9373ed3a369496548a8d8c538ae84
2024-09-20 15:42:32 +00:00
Roan Kattouw
8a39d83175 Codex: Allow a local development version to be used
Developers can use this to test their local version of Codex with
MediaWiki by pointing $wgCodexDevelopmentDir to their local clone of the
Codex repo, e.g. $wgCodexDevelopmentDir = '/home/yourname/git/codex';

Setting $wgCodexDevelopmentDir affects where the following things come
from:
- Codex JS/CSS files for the full library
- Codex JS/CSS files for code-split chunks, and the manifest.json file
  that points to them
- Icons retrieved by CodexModule::getIcons()
- CSS-only icons imported in Less
- Design tokens imported in Less

Other changes in this patch:
- Add CodexModule::makeFilePath() to centralize the repeated path
  concatenation. This makes it easier to switch out the regular path for
  the dev mode path.
- Replace all uses of $IP (which is deprecated) and MW_INSTALL_PATH in
  CodexModule with the BaseDirectory config setting.
- Make CodexModule::getIcons() reset its static cache if the path to the
  icons file changes. Without this, it's impossible to make the unit
  tests pass.
- Move the i18n messages code from the CodexModule constructor to
  getMessages(). It can't be in the constructor because makeFilePath()
  doesn't work there (it fails because the Config object hasn't been set
  up yet).
- Add a 'mediawiki.skin.codex' import path so that we can stop
  hard-coding the path to the Codex mixins file. Without this, we can't
  make the Codex mixins come from the right place in development mode.
- Consider $wgCodexDevelopmentDir in setting the cache key for compiled
  Less code, since changing this setting can change the output of Less
  compilation (by changing design tokens, icons or mixins).
- Add unit tests for (the non-dev mode behavior of)
  CodexModule::getIcons() and the i18n message key handling.

Bug: T314507
Change-Id: I11c6a81a1ba34fe10f4b1c98bf76f0db40c1ce98
2024-08-22 17:20:24 -07:00
Roan Kattouw
fe62ebafd2 CodexModule: Remove CODEX_MODULE_DIR, instead use CODEX_LIBRARY_DIR
CODEX_MODULE_DIR is always the /modules subdirectory of
CODEX_LIBRARY_DIR, so remove it and derive it that way instead.

- Update tests accordingly
- Rename test data files accordingly
- Use CODEX_LIBRARY_DIR in one place where we had neglected to use a
  constant

Change-Id: Ieb347c2d128f3addfb11f6aca79d63969434f342
2024-05-15 17:12:20 -04:00
Reedy
7ffd9e8daf .eslintignore: Remove jquery.tipsy reference
Bug: T117720
Change-Id: I5d554f390d7826bc3542b2574d4642c489212c4e
Follows-Up: I39a5efe3dcfa276fcdf7627d41923904917958cf
2024-01-16 21:11:39 +00:00
Anne Tomasevich
4baf4dd8be CodexModule: Add unit test for code splitting
This requires the path to the Codex modules directory
to be configurable, so we can use static manifest and
component files in tests. This is achieved by changing
the constant storing the Codex modules dir from private
to protected so it can be overridden when creating a
test module.

Bug: T350054
Change-Id: Icd3c6c5d2a82f5a5fb1c38b52e54893034e7375c
2023-12-01 00:52:23 +00:00
Timo Tijhof
5095cf760c tests: Configure ESLint to permit ES2022 syntax in test suites
Analogous to what the 'compat/compat' rule indicates already, and the
fact that CI, fresh-node, and local dev generally involves recent
versions of Firefox, Chromium-based browsers, or Safari.

This patch is a minimal first step that only loosens the linter,
and auto-fixing only unusual cases where a new rule specifically
warned against existing code.

Change-Id: Ic64f650bd64669c57b884de3f75b23f3549b0c9f
2023-04-17 21:41:53 +00:00
Umherirrender
fefb27b037 build: Run eslint for /docs/ and make pass
The doc folder contains (committed) json files with schema definition
for json files
That should be linted as well to spot syntax errors easier

Change-Id: I20ff7abf6b98d2247ee52e2d2b43af88c062f779
2022-07-27 00:43:02 +02:00
Umherirrender
32729700ba build: Fix include of en.json/qqq.json in .eslintignore
The {en,qqq}.json syntax is Grunt-style, not eslint-style

Change-Id: Ie05358cd17232079857d349ac310751ed637b2a6
2021-11-19 21:00:35 +00:00
Dan Duvall
9a4af25664 Introduced settings sources and formats
A `SettingsSource` is meant to represent any kind of local or remote
store from which settings can be read, be this a local file, remote URL,
database, etc. It is concerned with reading in (and possibly decoding)
settings data, and computing a consistent hash key that may be used in
caching.

A `SettingsFormat` is meant to detect supported file types and/or decode
source contents into settings arrays. As of now, JSON is the only
supported format but others may be implemented.

`FileSource` is the first source implementation, with its default format
being JSON, meant to read settings from local JSON files.

`ArraySource` is mostly useful for testing using array literals.

Refactored `SettingsBuilder` methods to use the new source abstractions.

Bug: T295499
Change-Id: If7869609c4ad1ccd0894d5ba358f885007168972
2021-11-15 14:07:59 -08:00
Timo Tijhof
035af05c60 build: Add /cache to eslintignore
Bug: T291674
Change-Id: I0d0b78d59a02023b97249c116d8754ad9d4be5e0
2021-09-24 00:47:22 +01:00
Tim Starling
06ddb96459 Add benchmark for Linker::formatComment() in preparation for refactor
* Move data files to /data
* Add benchmarkCommentFormatter, named for the new class hierarchy.

Bug: T285917
Change-Id: Idf2529894fe63d34087d6d5ce4dd1676c89b1373
2021-08-24 13:57:53 +10:00
Eric Gardner
5ddd90fd76 Add polyfills for ES6 array methods
Adds the MDN polyfills for Array.prototype.find, findIndex, and
includes to core, along with a skip function. Polyfills live a
single "es6-polyfills" module in case additional similar polyfills
need to be introduced in the future.

Introducing these in core will allow certain extensions
to stop shipping local copies.

Bug: T264135
Change-Id: I37953f6fcad693a8d25e1a19764abd55bbbbb242
2021-04-21 14:43:27 -07:00
Ed Sanders
f682860d6c build: Ignore default upload path in eslint
Change-Id: I493af7938eaa744a9e869e611f54de5cbaa2692e
2021-03-04 17:58:15 +00:00
James D. Forrester
3aa1f6c2fa build: Only run eslint on locally-mastered i18n files
Bug: T276477
Change-Id: Ic1e3c4b00f3a3319f032620f9c96cafd3ee174ad
2021-03-04 17:54:16 +00:00
Timo Tijhof
85d57d4bbf build: Move eslint ignores to .eslintignore
Note that node_modules is excluded by default.

Bug: T249858
Change-Id: Iaa69092b11e49ebf9cc5f2ec8a695894cda31b83
2020-04-22 19:17:08 +01:00