The `nativescript-unit-test-runner` package provides the core infrastructure for executing unit tests within NativeScript applications. It is primarily consumed by the NativeScript CLI (`tns test`) and integrates with standard JavaScript testing frameworks like Karma, Jasmine, and Mocha. The current stable version is `4.0.1`, which includes support for NativeScript 9 and improved ES Module syntax handling. This package acts as the bridge between your test code, the NativeScript runtime, and the underlying test runner environment, facilitating the execution of tests directly on emulators, simulators, or physical devices. It addresses the complexities of running tests in a device-native context, a key differentiator from web-based test runners, and has an active release cadence with major version updates supporting new NativeScript versions.
npm install nativescript-unit-test-runnerVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing a new NativeScript project, setting up the unit test runner with `tns test init`, and executing example tests on Android or iOS devices/simulators.
Ensure your project's `tsconfig.json` (if TypeScript) and build configuration (e.g., `webpack.config.js`) are configured for ES Modules. Update any `require()` statements targeting `nativescript-unit-test-runner` to `import` statements.
Align the `nativescript-unit-test-runner` version with your `nativescript` project version. For NativeScript v9, use `nativescript-unit-test-runner@4.x.x`. Upgrade both packages simultaneously if necessary.
Review NativeScript's documentation for Webpack 5 integration and update your `webpack.config.js` accordingly. Ensure `@nativescript/webpack` is updated to a compatible version.
Be aware of the AOT/JIT difference in test vs. production builds. If AOT-specific issues are suspected, consider configuring your test app with AOT explicitly or running full AOT builds outside the test runner for comprehensive validation.
Ensure your Android emulator is properly configured and reachable on the network. Try restarting the emulator or verifying its network settings. Consult NativeScript documentation for specific emulator networking configurations or update your Android SDK tools.
For versions `4.0.1` and above, ensure you are using ES Module `import` syntax. Verify your `tsconfig.json` (if TypeScript) and build configuration (e.g., Webpack) are set up for proper module resolution.
Upgrade `nativescript-unit-test-runner` to a version compatible with your project's NativeScript core. For NativeScript v9, use `nativescript-unit-test-runner@4.x.x`.
Update your `webpack.config.js` to be compatible with Webpack 5. Refer to the `@nativescript/webpack` documentation and NativeScript CLI documentation for Webpack 5 specific configurations, and ensure your `@nativescript/webpack` package is up-to-date.
Verify your Android emulator's network configuration and ensure it is properly configured to allow connections. Try restarting the emulator or ensuring it has a proper IP address. Check for firewall rules that might block communication between your host machine and the emulator.