Nativescript-cli: tns test from a fresh project creation doesn't work

Created on 9 Nov 2018  ·  12Comments  ·  Source: NativeScript/nativescript-cli

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.

critical unit testing

Most helpful comment

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: https://github.com/NativeScript/nativescript-cli/issues/4119#issuecomment-437327199

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.

All 12 comments

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

https://github.com/NativeScript/nativescript-cli/issues/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

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.

@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

@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 thank you so much, your solutions save my headache

I came to this issue while setting up a CI build. I also found this helpful, they seem to be related: https://github.com/NativeScript/nativescript-cli/issues/2017

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: https://github.com/NativeScript/nativescript-cli/issues/4119#issuecomment-437327199

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.

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

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

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

Is this intentional or a bug?

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

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

Was this page helpful?
0 / 5 - 0 ratings