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

If using a different setup:
 * 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.


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

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

単体テストを書く
Write unit tests for new functionality, and consider fillling gaps in coverage when changing existing modules in MediaWiki core.

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