Manual:JavaScript unit testing/ja

MediaWiki uses QUnit to unit test its JavaScript code base.



ブラウザーで実行

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

実行
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.



貢献する方法


コミット前にテストを実行する
Make it a habit to run unit tests before committing and submitting your changes to.



単体テストを書く
for new functionality, and consider fillling gaps in coverage when changing existing.



テストを書く
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.



テストを登録する


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:

拡張機能
Extensions register their QUnit tests via the QUnitTestModule attribute in.



関連項目

 * 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