English documentation follows in the second half of this page. Jump to English.
intra-mart のサーバサイドスクリプト向けの VS Code 拡張機能です。デバッグと
Jest on Rhino のテストエクスプローラを提供します。
デバッグ
1. サーバをデバッグモードで起動する
対象の intra-mart インスタンスを Debug Adapter Protocol モードで起動します。
-Djp.co.intra_mart.system.javascript.Debugger.protocol=dap
-Djp.co.intra_mart.system.javascript.Debugger.port=9000
アタッチする時点で、サーバが先に listen している必要があります。
2. VS Code からアタッチする
JavaScript ファイルを開き、コマンドパレットから intra-mart: Server Side Script のデバッグ
を実行します。localhost:9000 へアタッチします。
別のホストやポートを使う場合は、.vscode/launch.json へ attach 構成を追加し、実行と
デバッグのビューから開始してください。launch.json を新規作成すると VS Code が
「Server side script for intra-mart」として候補に出し、構成スニペットとしても選べます。
{
"type": "intra-mart-server-side-script-debug",
"request": "attach",
"name": "Server side script for intra-mart",
"host": "localhost",
"port": 9000
}
3. ブレークポイントを置いて実行する
ブレークポイントを置いてアタッチし、サーバ側でスクリプトを実行すると停止します。
テストエクスプローラ
1. プロジェクトを用意する
拡張機能は src/main/jssp または src/test/jssp を含むワークスペースで有効になり、
プロジェクトルートごとに 1 つのテストツリーを作ります。プロジェクトルートとは pom.xml と
src/test/jssp の両方を持つディレクトリです。走査では node_modules と target を除きます。
プロジェクトルートごとに次のものが必要です。
- Jest 設定ファイル。最初に見つかった 1 つだけを読み、
"jest" キーを持たない
package.json は設定ファイルなしとして扱います。
jest.config.js
jest.config.json
package.json の "jest" キー
testMatch に一致するテストファイル。デフォルトは **/*.test.js と **/*.spec.js です
- Java ランタイム。Java コードと同じ JDK でテストを実行できるよう
java.configuration.runtimes と java.jdt.ls.java.home を使い、見つからなければ
JAVA_HOME、JDK_HOME、PATH 上の java の順にフォールバックします
jest.config.js はオブジェクト形式の module.exports = { ... } で書いてください。JAR が
Rhino 上で評価するためです。関数形式の module.exports = () => ({ ... }) は専用のエラーで
失敗し、JAR 側では require() を使えません。
Jest 設定ファイルを持たないプロジェクトルートはテストエクスプローラの対象外になります。
デバッグはそのまま使えます。
2. テストを実行する
テストのビューを開きます。テストツリーから、テストの実行、ブレークポイントを使った
デバッグ実行、カバレッジの収集を行えます。
Jest 設定は起動時に 1 度だけ読み込みます。編集したあとは、拡張機能がウィンドウの
再読み込みを促します。
対応言語
English / 日本語 / 简体中文 に対応し、VS Code の表示言語設定に追従します。切り替えは
表示言語を構成する コマンドから行えます。
制限事項
debugger; 文には対応していません。実行は停止しますが、エンジンがこの文の行情報を
記録しないため、報告される停止位置が誤ります。最後に実行された行の次の行を、理由
breakpoint として指します。ブレークポイントを使ってください
- 複数のテストを選んで一度に実行することはできません。実行範囲は最初の選択だけで決まります
it.each の各行とループで生成されたテストの結果は、呼び出し行にある 1 つのアイテムへ
集約されます
- 信頼されていないワークスペースでは拡張機能が無効になります。Jest 設定ファイルを評価し、
テストコードを実行するためです
English
A VS Code extension for intra-mart server side scripts. It provides debugging and a
Jest on Rhino Test Explorer.
Debugging
1. Start the server in debug mode
Start the target intra-mart instance with Debug Adapter Protocol mode enabled:
-Djp.co.intra_mart.system.javascript.Debugger.protocol=dap
-Djp.co.intra_mart.system.javascript.Debugger.port=9000
The server must already be listening when you attach.
2. Attach from VS Code
Open a JavaScript file and run intra-mart: Debug Server Side Script from the Command
Palette. It attaches to localhost:9000.
To use another host or port, add an attach configuration to .vscode/launch.json and start
it from the Run and Debug view. VS Code offers it as "Server side script for intra-mart"
when you create launch.json, and as a configuration snippet.
{
"type": "intra-mart-server-side-script-debug",
"request": "attach",
"name": "Server side script for intra-mart",
"host": "localhost",
"port": 9000
}
3. Set breakpoints and run
Set breakpoints, attach, then run a script on the server to hit them.
Test Explorer
1. Set up a project
The extension activates in workspaces containing src/main/jssp or src/test/jssp, and
creates one test tree per project root, a directory that holds both pom.xml and
src/test/jssp. The scan skips node_modules and target directories.
Each project root needs:
- A Jest configuration file. Only the first file found is read, and a
package.json without
the "jest" key counts as having no configuration file:
jest.config.js
jest.config.json
- the
"jest" key in package.json
- Test files matching
testMatch. The default is **/*.test.js and **/*.spec.js
- A Java runtime. The extension uses
java.configuration.runtimes and
java.jdt.ls.java.home so that tests run on the same JDK as your Java code, then falls
back to JAVA_HOME, JDK_HOME, and java on PATH
jest.config.js must use the object form module.exports = { ... }, because the JAR
evaluates it on Rhino. The function form module.exports = () => ({ ... }) fails with an
explicit error, and require() is not available on the JAR side.
Project roots without a Jest configuration file are excluded from the Test Explorer.
Debugging still works in them.
2. Run tests
Open the Testing view. From the test tree you can run tests, debug them with breakpoints,
and collect coverage.
The Jest configuration is read once at startup. After you edit it, the extension asks you to
reload the window.
Language
The extension UI is available in English, 日本語, and 简体中文, and follows the VS Code
display language. Switch languages with the Configure Display Language command.
Limitations
- The
debugger; statement is not supported. Execution still pauses on it, but the engine
records no line information for the statement, so the reported stop location is wrong. It
points at the line after the last executed one, with reason breakpoint. Use breakpoints
instead
- Running several selected tests at once is not supported. Only the first selection
determines the run scope
- Results of
it.each rows and loop iterations are aggregated into the single item at the
call line
- The extension is disabled in untrusted workspaces, because it evaluates Jest configuration
files and runs test code