question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tns test android no reachable hosts

See original GitHub issue

Environment

  • CLI: 6.2.2
  • Cross-platform modules: 6.2.1
  • Android Runtime: 6.2.0
  • iOS Runtime: n/a
  • Plugin(s):

Describe the bug && Reproduction I’m experiencing the same issue outlined in #4119.

Run tns test android with usesCleartextTraffic=false, the test app shows “no reachable hosts”. Setting usesCleartextTraffic=true allows the tests to execute.

I don’t want to set usesCleartextTraffic to true with my production application, so I’m wondering how I get around this.

Expected behavior I expect the tests to run 😄

Additional context This was supposed to be resolved with this pull request. I see that there is an AndroidManifest.xml file in those changes, and I’m wondering if that is supposed to override the settings in my application’s manifest https://github.com/NativeScript/nativescript-unit-test-runner/pull/30

package.json

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rosen-vladimirovcommented, Dec 4, 2019

@jevenson , the idea is to include a script on your side that sets usesCleartextTraffic to true and then runs the tests, for example in Node.js script you can do something like:

const path = require("path");
const fs = require("fs");
const childProcess = require("child_process");
const os = require("os");
const pathToAndroidManifestInAppResources = path.join(__dirname, "app", "App_Resources", "Android", "src", "main", "AndroidManifest.xml");

const currentContent = fs.readFileSync(pathToAndroidManifestInAppResources).toString();
const newContent = currentContent.replace('android:usesCleartextTraffic="false"', 'android:usesCleartextTraffic="true"');
fs.writeFileSync(pathToAndroidManifestInAppResources, newContent);

const tnsExecutable = os.platform() === "win32" ? "tns.cmd" : "tns";
try {
    const result = childProcess.spawnSync(tnsExecutable, ["test", "android", "--justlaunch"], { stdio: "inherit" });
    console.log(result);
} finally {
    fs.writeFileSync(pathToAndroidManifestInAppResources, currentContent);
}

Currently it is not possible to run the test on API level 28 or above without this setting and we do not have plans to research other ways to achieve this.

0reactions
alexistcommented, Jul 23, 2021

I made a pul request, to display an error message when this error happen

https://github.com/NativeScript/nativescript-unit-test-runner/pull/51

Read more comments on GitHub >

github_iconTop Results From Across the Web

tns test android test harness reports "no reachable hosts" #4182
Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or ...
Read more >
Nativescript unit testing shows no reachable hosts
I'm trying to follow this tutorial to do unit testing in Nativescript with Jasmine/Karma. When I do tns test android, my phone flashes...
Read more >
Unit Testing - NativeScript Docs
Write and execute unit tests to ensure that newly added features are working correctly and no regressions are introduced in the mobile app....
Read more >
Capturing and Inspecting Android Traffic - Fiddler Everywhere
Check the emulator documentation for the IP address used as a loopback address. In most cases, the loopback alias of the Android emulator...
Read more >
NativeScript i - Tutorialspoint
NativeScript Playground application will be helpful for testing your apps in Android or iOS device without deploying the application in the real ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found