diff --git a/wasm/README.md b/wasm/README.md index ee32fb41..e35cc367 100644 --- a/wasm/README.md +++ b/wasm/README.md @@ -135,15 +135,32 @@ bounds checking and nice error reporting. 1. **JavaScript API tests.** These verify that a wide variety of MuJoCo functions and classes work - correctly when called from JavaScript. There are also preliminary benchmarks - for JavaScript/C++ shared memory buffers. The enums test is special because - it is generated by a Python script. Run the tests as follows: + correctly when called from JavaScript. Run the tests as follows: ```sh npm run test --prefix ./wasm ``` -2. **Bindings generator tests.** + > [!NOTE] + > The above command runs the [`enums_tests.ts`](tests/enums_tests.ts) file + > which checks that all the enums in the API are bound. This test is + > auto-generated so if you add/edit an enum to MuJoCo then you will need to + > run the following command to re-create the test: + > + > ```sh + > PYTHONPATH=python/mujoco python3 -m wasm.codegen.enums_test_generator + > ``` + +2. **JavaScript API benchmark tests.** + The current benchmark tests check JavaScript/C++ shared memory buffers + performance. We will increase the coverage of the benchmarks overtime. Run + the benchmarks using this command: + + ```sh + npm run benchmark --prefix ./wasm + ``` + +3. **Bindings generator tests.** These are relevant when developing or extending the bindings. The following command finds and runs all `test_*.py` or `*_test.py` files in the `wasm` folder: @@ -152,15 +169,6 @@ bounds checking and nice error reporting. PYTHONPATH=python/mujoco python3 -m pytest ./wasm ``` -> [!NOTE] -> If you add/edit an enum in MuJoCo you will need to run the following command -> to re-creates the [`enums_tests.ts`](tests/enums_tests.ts) file which checks -> that all the enums in the API are bound: -> -> ```sh -> PYTHONPATH=python/mujoco python3 -m wasm.codegen.enums_test_generator -> ``` - ### Debugging We provide a “sandbox” app where you can quickly write code to run in your diff --git a/wasm/package.json b/wasm/package.json index d590119f..6384da1b 100644 --- a/wasm/package.json +++ b/wasm/package.json @@ -8,7 +8,8 @@ "test": "tests" }, "scripts": { - "test": "node --loader ts-node/esm --trace-warnings tests/run-tests.mjs", + "test": "node --loader ts-node/esm --trace-warnings tests/run_tests.mjs", + "benchmark": "node --loader ts-node/esm --trace-warnings tests/run_benchmarks.mjs", "dev:sandbox": "vite --config tests/sandbox/vite.sandbox.config.ts", "build:sandbox": "vite build --config tests/sandbox/vite.sandbox.config.ts", "dev:demo": "vite --config demo_app/vite.demo.config.ts", diff --git a/wasm/tests/run-tests.mjs b/wasm/tests/run_benchmarks.mjs similarity index 96% rename from wasm/tests/run-tests.mjs rename to wasm/tests/run_benchmarks.mjs index 948737e4..800375c8 100644 --- a/wasm/tests/run-tests.mjs +++ b/wasm/tests/run_benchmarks.mjs @@ -18,7 +18,7 @@ const jasmine = new Jasmine(); jasmine.loadConfig({ spec_dir: 'tests', - spec_files: ['**/*_test.ts'], + spec_files: ['benchmark_test.ts'], jsLoader: 'import', random: false, stopSpecOnExpectationFailure: false, diff --git a/wasm/tests/run_tests.mjs b/wasm/tests/run_tests.mjs new file mode 100644 index 00000000..70f39a4a --- /dev/null +++ b/wasm/tests/run_tests.mjs @@ -0,0 +1,40 @@ +// Copyright 2025 DeepMind Technologies Limited +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Jasmine from 'jasmine'; + +const jasmine = new Jasmine(); + +jasmine.loadConfig({ + spec_dir: 'tests', + spec_files: ['**/*_test.ts', '!benchmark_test.ts'], + jsLoader: 'import', + random: false, + stopSpecOnExpectationFailure: false, +}); + +try { + console.log('Starting Jasmine test run...'); + const result = await jasmine.execute(); + console.log(`Jasmine test run finished. Status: ${result.overallStatus}`); + + if (result.overallStatus === 'failed') { + process.exit(1); + } + +} catch (error) { + console.error('Test runner script failed:', error); + process.exit(1); +} +