After running unit tests via
a call to
displays an app with a big image of "N" and a label that says "no reachable hosts"
My expectation is that the app would run (not the unit tests)
tns info
nativescript โ 3.2.1 โ 3.2.1 โ Up to date โ
tns-core-modules โ 3.2.0 โ 3.2.0 โ Up to date โ
tns-android โ โ 3.2.0 โ Not installed โ
tns-ios โ 3.2.0 โ 3.2.0 โ Up to date โ
Steps to reproduce:
Any help would be greatly appreciated.

I have now reproduced this on two computers.
@jschwartz73 try the suggestions below
This could be caused by several things
During execution of tests, CLI changes the entry point of an application. After that, when tns run is executed, the original file should be transferred.
I see two options here:
tns test <platform>; tns run <platform>- the second one should prepare the project and restart app on device. We may have issues with checking if app should be prepared and we may have skipped it. This will reproduce the issue- The other option is that
tns run <platform>had synced correct files, but without theapp/package.jsonThe workaround should be pretty easy -
touch app/package.jsonand executetns run <platform>after that.
I tried the workaround and it does not solve the issue.
Any other suggestions?
@jschwartz73 I was experiencing the same thing, it looks like running the tests might have changed app/package.json which I believe is how tns run ios figures out how to start the application. For me I could see via git status that it was modified and just did a git checkout -- app/package.json
Basically you need to make that file looks something like this
{
"android": {
"v8Flags": "--expose_gc"
},
"main": "main.js",
"name": "tns-template-hello-world-ng",
"version": "3.1.2"
}
In your case I bet main points to the unit test runner and not the app itself.
Could anyone give some info on when that file gets changed and whether or not it should or shouldn't be in version control?
Hey all,
tns test <platform> command must update the package.json inside <platforms> dir only - that's how the tests are run. However, it looks like there is some issue with this and it updates the entry point in your app/package.json. This is definitely not intended. Can all of you, who hit the issue, share the following information:
npm -v): node -v):xcodebuild -version):iOS or Android: npm link in your development workflow?Meanwhile, I've reproduced and confirmed that the following workflow does not work:
Skipping prepare and does not update package.json in platforms dir, so the application running on device is the one with tests. CLI should not skip prepare here.touch app/package.json and run tns run ios again. This will force CLI to prepare the application.@rosen-vladimirov as per request:
npm -v : 5.4.2
node -v : v8.1.3
xcodebuild -version : Xcode 9.0 Build version 9A235
I've only been developing with iOS thus far as the project I'm working on only requires iOS at this time.
No local plugins, just a vanilla install using the cli.
npm -v: 5.4.2
node -v: v6.11.3
xcodebuild -version: Xcode 9.0, Build version 9A235
I can reproduce the problem every time using these steps:
I'll film a short screencast to demonstrate
@rosen-vladimirov Hi. I got the same issue reproduced on Android. Steps are the same as for iOS
npm -v: 5.3.0
node -v: v8.6.0
xcodebuild -version: Xcode 9.1, Build version 9B55
NPM -V = 5.5.1
Node -v = v8.9.1
Using Windows/Visual studio code
ANDROID
I'm now running:
npm -v: 5.4.2
node -v: v6.11.3
xcodebuild -version: Xcode 9.1, Build version 9B55
iOS only for the time being
I'm getting this too... Only after running tests i can't run the app again on emulator or device. I get a 'no reachable hosts error' After i do tns update however it seems to work. Is this expected??
Same thing with this configuration:
npm - v : 6.2.0
node -v : v6.10.2
xcodebuild -version : Xcode 9.4.1
iOS
This is still reproducible, and the touch on the package.json doesn't work for me. I need to manually make changes to it, then revert it back it how it was. Then tns run ios will work.
Same thing with this configuration:
npm - v : 6.2.0
node -v : v8.11.3
xcodebuild -version : Xcode 9.4.1
iOS and Android
I tried reverting the package.json and was still getting the "no reachable hosts" screen.
I was able to get my app back to normal by removing the platforms folder and rebuilding the app again. Once you run "tns test [platform]>, you'll be back to the "no reachable hosts" screen.
I simply run this now after tns test ios and if I'm gonna be working with tns run ios again:
tns platform remove ios && tns platform add ios && tns run ios
Added an alias to my bash and have been using it with 100% success rate. Quite annoying, but works.
So, this means that running the application and unit testing can't happen simultaneously, correct? That's a bummer.
IOS
I execute this command after testing:
sed -i.bak 's|./tns_modules/nativescript-unit-test-runner/||' platforms/ios/*/app/package.json
it resets the package.json file and is faster than rebuilding the platforms folder
in nativescript-unit-test-runner/lib/after-prepare.js:
var platformData = $platformsData.getPlatformData($testExecutionService.platform), projectFilesPath = path.join(platformData.appDestinationDirectoryPath, "app"), packageJsonPath = path.join(projectFilesPath, 'package.json'), packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
packageJson.main = "./tns_modules/nativescript-unit-test-runner/app.js";
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson));
I don't know where that file is used downstream, and once it's changed un-writing isn't an option since you have to cntrl-c out of the test runner...
So that means rewriting the file on entry into the 'run' command (and any other commands necessary):
At a first guess I'd propose:
adding an import, function, & export to node_modules/nativescript-dev-webpack/projectHelpers.js
const { resolve, basename } = require("path");
const rewritePackageJsonEntry = (projectDir) => {
const content = getPackageJson(projectDir);
content.main = (content.main) ? basename(content.main) : "app.js";
writeFileSync(content, packageJsonPath)
}
module.exports = {
getAppPathFromProjectData,
getAppResourcesPathFromProjectData,
rewritePackageJsonEntry,
getPackageJson,
getProjectDir,
isAndroid,
isIos,
isAngular,
isVue,
isTypeScript,
writePackageJson,
convertSlashesInPath
};
and changing node_modules/nativescript-dev-webpack/index.js:
const {
rewritePackageJsonEntry,
getPackageJson,
isAndroid,
isIos,
} = require("./projectHelpers");
function getPackageJsonEntry(appDirectory) {
rewritePackageJsonEntry(appDirectory)
const packageJsonSource = getPackageJson(appDirectory);
const entry = packageJsonSource.main;
if (!entry) {
throw new Error(`${appDirectory}/package.json must contain a 'main' attribute!`);
}
return entry.replace(/\.js$/i, "");
}
I am seeing this as well when building for Android using the sample Angular project however if after running
tns test android
I modify any file in the project, then
tns run android
works correctly.
If I run the two commands consecutively without making any edits, I get the "no reachable hosts" error.
@Yermo ,
You need to add the following code to your App_Resources/Android/AndroidManifest.xml
<application
android:usesCleartextTraffic=โtrueโ
@Fatme I am working with the sample app created using
tns create ns-test-app --ng
cd ns-test-app
npm install
tns test init
under Ubuntu.
There is no AndroidManifest.xml file under App_Resources/Android but there is one under App_Resources/Android/src/main/AndroidManifest.xml
I added the android:usesCleartextTraffic="true" line to that file but it has no effect. I still get "no reachable hosts" attempting to run the app after running tests.
Getting this same error first time using nativescript. Btw, some of the docs explicitly have you run tns test ios as your are setting up and testing that you are properly configured.
This seems like a terrible blocker for folks that are just getting started with NativeScript and a great annoyance to existing users. Seems like it should be somewhat high on the list of bug fixes to tackle and it's been open for over a year. I'd imagine that there are a number of folks that have given up before really ever getting started.
That said, thanks for all the tooling and nice job on most of the rest of the on-ramp process. This was just a minor hiccup, albeit a rather nasty one, along the way.
Btw, I was also able to sucessfully use the fixup commands above (platform rebuild & sed). Except that in my case the entry point was main.js, so sed -i.bak 's|./tns_modules/nativescript-unit-test-runner/app.js|main.js|' platforms/ios/*/app/package.json was needed instead.
With current rc version, this should not happen anymore. Steps to reproduce the old behavior:
1. `tns create app1 --js`
2. `cd app1`
3. `tns test init`
4. `tns test android --no-bundle`
5. `tns run android --no-bundle` - this command should show the real application, but instead it will show the unit test page.
With new workflow you skip the --no-bundle flag and everything should work.
Most helpful comment
I simply run this now after
tns test iosand if I'm gonna be working withtns run iosagain:tns platform remove ios && tns platform add ios && tns run iosAdded an alias to my bash and have been using it with 100% success rate. Quite annoying, but works.