Manual:JavaScript unit testing/cs

MediaWiki používá QUnit k unit test své báze kódu JavaScript.



Spustit z prohlížeče

 * 1) Nastavte  až . (Toto je již nastaveno, pokud používáte  nebo MediaWiki-Vagrant.)
 * 2) Visit Special:JavaScriptTest in a browser to run the tests.



Spuštění z příkazového řádku


Jednorázové nastavení
Enter an isolated environment where you have Node.js and 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.

Spustit
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.



Jak se zapojit?


Spuštění testu před potvrzením
Make it a habit to run unit tests before committing and submitting your changes to.



Psaní testů jednotek
for new functionality, and consider fillling gaps in coverage when changing existing.



Psaní testu
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.



Zaregistrování testu


Jádro 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:

Rozšíření
Extensions register their QUnit tests via the QUnitTestModule attribute in.



Související odkazy

 * 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