Skip to content

tns test from a fresh project creation doesn't work #4119

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

Closed
Oatelaus opened this issue Nov 9, 2018 · 12 comments
Closed

tns test from a fresh project creation doesn't work #4119

Oatelaus opened this issue Nov 9, 2018 · 12 comments

Comments

@Oatelaus
Copy link

Oatelaus commented Nov 9, 2018

Environment

  • CLI: 5.0.0
  • Cross-platform modules: 5.0.2 (have also tested with 5.0.0, unsure if these versions need to match with CLI)
  • Android Runtime: 5.0.0
  • iOS Runtime: 5.0.0
  • Plugin(s):
Successfully prepared plugin nativescript-angular for android.
Successfully prepared plugin nativescript-theme-core for android.
Successfully prepared plugin nativescript-unit-test-runner for android.
Successfully prepared plugin tns-core-modules for android.
Successfully prepared plugin nativescript-intl for android.
Successfully prepared plugin tns-core-modules-widgets for android.

Describe the bug
When initializing tests for a fresh installation on V5, they immediately do not work and just don't even start.

To Reproduce

  1. tns create <appName> --ng
  2. cd <appName> && tns test init (I picked Jasmine for the test init)
  3. tns test android

The tests don't run.

Output here: https://hastebin.com/oluvahequl

You can see I edit the example.js file, in hopes a trigger of compilation could trigger tests.

Meanwhile my android device is reporting No reachable hosts.

Expected behavior

The tests to run.

@Oatelaus Oatelaus changed the title tns test <platform> v5 tns test from a fresh project creation doesn't work Nov 9, 2018
@Oatelaus
Copy link
Author

Oatelaus commented Nov 9, 2018

Have managed to get the tests to at least execute by switching singleRun from false to true as per this issue here:

#2739

If this is known to not work, why is it default to true?

Regardless, this is still a fairly broken default installation as after switching this, I'm still getting errors:

Chrome 70.0.3538 (Mac OS X 10.14.0) ERROR
  {
    "message": "An error was thrown in afterAll\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exportsis not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined",
    "str": "An error was thrown in afterAll\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined\nUncaught ReferenceError: exports is not defined"
  }
Chrome 70.0.3538 (Mac OS X 10.14.0): Executed 0 of 0 ERROR (0.025 secs / 0 secs)

@Fatme
Copy link
Contributor

Fatme commented Nov 9, 2018

@Fedelaus,

You can find more information here #4071.
Closing as a duplicate to #4071.

@Fatme Fatme closed this as completed Nov 9, 2018
@Oatelaus
Copy link
Author

Oatelaus commented Nov 9, 2018

@Fatme

The only relation I see in that issue is that they're also trying to run tns test.

Their unexpected behaviour is different (their tests run immediately, mine don't run at all).
Their android test returns socket undefined (mine does not).
They are running v5 cli, but their iOS/Android/Core Modules are completely different (an entire major version).

I am reporting that the default, out of the box installation, does not work with tests as per the documentation.

As well as that, the suggested change provided by yourself makes no difference in my example.

@chorsnell
Copy link

@Fatme I too think this is unrelated to #4071 :)

This is completely out of the box v5 behaviour, and a fairly big impediment in my team using NS for serious enterprise applications.

Are there any additional reproduction steps / information we can provide? We are getting the exact same issue as @Fedelaus

@Fatme
Copy link
Contributor

Fatme commented Nov 9, 2018

@Fedelaus, @poppahorse,

Sorry guys, my bad!

I didn't notice the following: "No reachable hosts."

It seems your android emulators are with android 28. If this is the case you need to add android:usesCleartextTraffic=“true” in App_Resources/android/AndroidManifest.xml.

<application
         android:usesCleartextTraffic=“true”

@Fatme Fatme reopened this Nov 9, 2018
@irwansyahwii
Copy link

@Fatme thank you so much, your solutions save my headache

@groksrc
Copy link

groksrc commented Nov 16, 2018

I came to this issue while setting up a CI build. I also found this helpful, they seem to be related: #2017

@Oatelaus
Copy link
Author

Thanks for the reply @Fatme.

You are correct my emu for that specific output was 28 but I was seeing the same from a default installation using 24, and I managed to get them to execute as per here: #4119 (comment)

but then immediately see that output when utilizing typescript files about exports, even though the documentation just says I need to import reflect-metadata and install jasmine types.

It definitely feels like the out of the box setup requires tweaking if the documentation is actually correct.

@trylovetom
Copy link

@Fatme Why!? Why need to add this workround.

@Fatme
Copy link
Contributor

Fatme commented Sep 26, 2019

@trylovetom

This workaround was needed because the default value of usesCleartextTraffic was changed as of Android API 28.
According to the docs:

The default value for apps that target API level 27 or lower is "true". Apps that target API level 28 or higher default to "false".

As the default value was changed to false, tns test command didn't work out of the box as the application makes http requests runtime in order to connect to karma server. So, the user needs manually to change the value of usesCleartextTraffic in AndroidManifest.xml.

However, this workaround is no more needed as we fixed it directly in [email protected]. So, if you use [email protected] or higher, it should work out of the box.

@jevenson
Copy link

@Fatme I am using [email protected] and I still need to enable usesCleartextTraffic in AndroidManifest.xml.

Is this intentional or a bug?

@alexist
Copy link

alexist commented Jul 23, 2021

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

NativeScript/nativescript-unit-test-runner#51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests