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 MediaWiki-Docker-Dev or MediaWiki-Vagrant.)
 * 2) Visit Special:JavaScriptTest in a browser to run the tests.

Exécution à partir de la ligne de commande
One-time setup:


 * 1) Ensure environment variables   and   are set. Either each time, or from   to have them always:
 * 2) Enter an isolated environment where you have Node.js and npm. Why?
 * 3) * If using MediaWiki-Docker, consider using Fresh. Run  from the MediaWiki directory.
 * 4) *If using MediaWiki-Vagrant, simply ssh to your Vagrant VM and navigate to the MediaWiki directory.
 * 5) Once inside your isolated shell, run  to install or update any dependencies.

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

You can run QUnit tests for specific components ( to run MediaWiki core QUnit tests, or the name of an extension or skin) with the   option:

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

Ecrire des tests unitaires
Always write unit tests for new functionality. We're also looking to expand our unit test coverage of already existing modules in the MediaWiki JavaScript library.

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 one, and only one, call to  with the module name.

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

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 QUnitTestModule 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