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

コマンド ラインで実行
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.
 * 5) Once inside your isolated shell, run  to install or update any dependencies.

実行
This runs the QUnit tests in Headless Chrome:

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

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

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

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