Manual:JavaScript unit testing/fr

MediaWiki uses QUnit to unit test its JavaScript code base.



Exécution à partir d'un navigateur

 * 1) Set   to . ( This is already set if you use  or MediaWiki-Vagrant. )
 * 2) Visit Special:JavaScriptTest in a browser to run the tests.



One-time setup
Enter an isolated environment where you have Node.js and npm. [https://timotijhof.net/posts/2019/protect-yourself-from-npm/ Why? ]

If using MediaWiki-Docker:


 * Consider using Fresh
 * Run  from the MediaWiki core directory. ( Fresh automatically finds the MW address in Docker's   file. )
 * Once inside your isolated shell, run  to install or update any dependencies.

If using MediaWiki-Vagrant:


 * Ensure environment variables  and   are set (consider saving this to  ):
 * Run  from the MediaWiki-Vagrant directory.
 * Once inside the Vagrant VM. navigate to the MediaWiki core directory and run.

If using a different setup:


 * Ensure environment variables  and   are set (consider saving this to  ):
 * Consider using Fresh, or if you have an isolated environment already, ensure a comparable version of Node.js and npm are installed (the before-last LTS should do).
 * Navigate to the MediaWiki core directory and run.

Exécuter
This runs the QUnit tests in Headless Chrome:

You can run QUnit tests for specific components with the  option. Pass the name of an extension or skin, or  for MediaWiki core tests.

] You can use the  argument for QUnit to watch the files associated with a component, and automatically re-run tests when those files change.



Comment contribuer ?


Exécuter les tests avant de valider
Make it a habit to run unit tests before committing and submitting your changes to.



Ecrire des tests unitaires
for new functionality, and consider fillling gaps in coverage when changing existing.



Ecrire un test
It is the convention to name the test suite file after the module it covers. For example,  covers the   module.

Inside the test suite should be a call to  with the module name.

The unit tests for MediaWiki core are located in the  directory.



Enregistrer un test


Noyau MediaWiki
Test suites are added to the registration of the  module in.

Tests are organised into a directory structure that matches the directory structure of the code being tested. For example: The unit test for  can be found at.

Example:

Les extensions
Extensions register their QUnit tests via the attribute in.



Voir aussi

 * Writing Testable JavaScript (May 2013), Rebecca Murphey, A List Apart
 * Writing Testable JavaScript (May 2013), Rebecca Murphey, A List Apart
 * Writing Testable JavaScript (May 2013), Rebecca Murphey, A List Apart