Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tns run ios shows "no reachable hosts" after running unit tests #3146

Closed
jschwartz73 opened this issue Oct 4, 2017 · 26 comments
Closed

tns run ios shows "no reachable hosts" after running unit tests #3146

jschwartz73 opened this issue Oct 4, 2017 · 26 comments
Labels
bug run Describes issues related to run command unit testing
Milestone

Comments

@jschwartz73
Copy link

After running unit tests via

  • tns test ios

a call to

  • tns run ios

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:

  1. tns create test-app
  2. cd test-app/
  3. tns run ios
  4. tns test init # Choose Jasmine
  5. tns test ios
  6. tns run ios

Any help would be greatly appreciated.

@jschwartz73
Copy link
Author

screen shot 2017-10-04 at 6 53 36 pm

@jschwartz73
Copy link
Author

I have now reproduced this on two computers.

@NickIliev
Copy link
Contributor

@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:

  1. 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
  2. The other option is that tns run <platform> had synced correct files, but without the app/package.json

The workaround should be pretty easy - touch app/package.json and execute tns run <platform> after that.

@jschwartz73
Copy link
Author

jschwartz73 commented Oct 5, 2017

I tried the workaround and it does not solve the issue.

Any other suggestions?

@wfwheele
Copy link

wfwheele commented Oct 6, 2017

@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?

@rosen-vladimirov
Copy link
Contributor

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 version (output of npm -v):
  • Node.js version (output of node -v):
  • Xcode version (output of xcodebuild -version):
  • Do you reproduce the issue with iOS or Android:
  • Do you have local plugins, do you use npm link in your development workflow?

Meanwhile, I've reproduced and confirmed that the following workflow does not work:

  • tns run ios
  • tns test ios
  • tns run ios - at this point CLI prints 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.
    The workaround for this issue is to execute touch app/package.json and run tns run ios again. This will force CLI to prepare the application.

@wfwheele
Copy link

@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.

@jschwartz73
Copy link
Author

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:

  1. tns create test-app
  2. cd test-app/
  3. tns run ios
  4. tns test init # Choose Jasmine
  5. tns test ios
  6. tns run ios

I'll film a short screencast to demonstrate

@jschwartz73
Copy link
Author

@ghost
Copy link

ghost commented Nov 5, 2017

@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

@henriqueadonai
Copy link

NPM -V = 5.5.1
Node -v = v8.9.1
Using Windows/Visual studio code
ANDROID

@jschwartz73
Copy link
Author

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

@Majed93
Copy link

Majed93 commented Jun 12, 2018

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??

@outsideMyBox
Copy link

Same thing with this configuration:
npm - v : 6.2.0
node -v : v6.10.2
xcodebuild -version : Xcode 9.4.1
iOS

@kamok
Copy link

kamok commented Aug 20, 2018

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.

@18clans
Copy link

18clans commented Sep 6, 2018

Same thing with this configuration:
npm - v : 6.2.0
node -v : v8.11.3
xcodebuild -version : Xcode 9.4.1
iOS and Android

@18clans
Copy link

18clans commented Sep 6, 2018

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.

@kamok
Copy link

kamok commented Sep 10, 2018

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.

@pnahtanoj
Copy link

So, this means that running the application and unit testing can't happen simultaneously, correct? That's a bummer.

@ajoslin103
Copy link

  • xcodebuild -version
    Xcode 10.1
    Build version 10B61
  • node --version
    v10.13.0
  • npm --version
    6.4.1

IOS

@ajoslin103
Copy link

ajoslin103 commented Nov 22, 2018

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


  • It looks like that .../app/package.json file gets changed [rather forcefully] here:

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, "");
}

@Yermo
Copy link

Yermo commented Jan 25, 2019

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.

@Fatme
Copy link
Contributor

Fatme commented Jan 25, 2019

@Yermo ,

You need to add the following code to your App_Resources/Android/AndroidManifest.xml

<application
         android:usesCleartextTraffic=“true”

@Yermo
Copy link

Yermo commented Jan 25, 2019

@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.

@arimus
Copy link

arimus commented Feb 22, 2019

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.

@DimitarTachev DimitarTachev added this to the 5.3.0 milestone Feb 25, 2019
@rosen-vladimirov rosen-vladimirov modified the milestones: 5.3.0, 6.0.0 Mar 21, 2019
@Fatme Fatme removed the planned label Apr 15, 2019
yringler added a commit to yringler/rabbi-gordon-audio that referenced this issue Apr 29, 2019
yringler added a commit to yringler/rabbi-gordon-audio that referenced this issue Apr 29, 2019
@rosen-vladimirov rosen-vladimirov added the run Describes issues related to run command label May 22, 2019
@rosen-vladimirov
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug run Describes issues related to run command unit testing
Projects
None yet
Development

No branches or pull requests