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

DisconnectedClient disconnected from CONNECTED state (transport error) #7287

Open
alexZaicev opened this issue May 26, 2019 · 19 comments
Open
Assignees

Comments

@alexZaicev
Copy link

alexZaicev commented May 26, 2019

Environment
Your ANDROID_HOME environment variable is set and points to correct directory.
√ Your adb from the Android SDK is correctly installed.
√ The Android SDK is installed.
√ A compatible Android SDK for compilation is found.
√ Javac is installed and is configured properly.
√ The Java Development Kit (JDK) is installed and is configured properly.
√ Local builds for iOS can be executed only on a macOS system. To build for iOS on a different operating system, you can use the NativeScript cloud infrastructure.
√ Getting NativeScript components versions information...
√ Component nativescript has 5.4.0 version and is up to date.
‼ Update available for component tns-core-modules. Your current version is 5.4.0 and the latest available version is 5.4.1.
√ Component tns-android has 5.4.0 version and is up to date.
‼ Update available for component tns-ios. Your current version is 5.3.1 and the latest available version is 5.4.0.

Contents of my package.json

{
"nativescript": {
"id": "org.nativescript.demoTest",
"tns-android": {
"version": "5.4.0"
},
"tns-ios": {
"version": "5.4.0"
}
},
"main": "app.js",
"description": "NativeScript Application",
"license": "SEE LICENSE IN ",
"repository": "",
"dependencies": {
"nativescript-theme-core": "~1.0.4",
"nativescript-unit-test-runner": "^0.6.3",
"tns-core-modules": "~5.4.0"
},
"devDependencies": {
"@types/jasmine": "3.3.12",
"karma": "4.1.0",
"karma-jasmine": "2.0.1",
"karma-nativescript-launcher": "0.4.0",
"karma-webpack": "3.0.5",
"nativescript-dev-typescript": "~0.9.0",
"nativescript-dev-webpack": "~0.22.0"
},
"gitHead": "c06800e52ee1a184ea2dffd12a6702aaa43be4e3",
"readme": "NativeScript Application"
}

Contents of karma.conf.js

module.exports = function (config) {
const options = {

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: ['app/tests/**/*.ts'],


// list of files to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [],

customLaunchers: {
  android: {
    base: 'NS',
    platform: 'android'
  },
  ios: {
    base: 'NS',
    platform: 'ios'
  },
  ios_simulator: {
    base: 'NS',
    platform: 'ios',
    arguments: ['--emulator']
  }
},

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
};

setWebpackPreprocessor(config, options);
setWebpack(config, options);

config.set(options);
}

function setWebpackPreprocessor(config, options) {
if (config && config.bundle) {
if (!options.preprocessors) {
  options.preprocessors = {};
}

options.files.forEach(file => {
  if (!options.preprocessors[file]) {
    options.preprocessors[file] = [];
  }
  options.preprocessors[file].push('webpack');
  });
}
}

function setWebpack(config, options) {
if (config && config.bundle) {
const env = {};
env[config.platform] = true;
env.sourceMap = config.debugBrk;
options.webpack = require('./webpack.config')(env);
delete options.webpack.entry;
delete options.webpack.output.libraryTarget;
}
}

Describe the bug
Whenever I try to run test cases on my android emulators, I can see the results, but I receive a warning from test runner:

26 05 2019 16:30:13.077:WARN [NativeScript / 26 (8.0.0; Android SDK built for x86)]: Disconnected (0 times)Client disconNativeScript / 26 (8.0.0; Android SDK built for x86) ERROR

And I can`t see my results in the browser or the emulator, only inside the console.

Expected behavior
I want to be able to what test failed and passed in the browser and if possible code coverage to see what branches were missed


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@tsonevn tsonevn self-assigned this May 27, 2019
@tsonevn
Copy link
Contributor

tsonevn commented May 27, 2019

Hi @alexZaicev,
If I understand you correctly, you are executing your tests successfully and the results are printed correctly in the console, and now you want to review the results using browser. To do that you should extend the karma configurations and to add the browser as a report option. Check out this StackOverflow thread, where it is described, how to achieve this.
Regarding DisconnectedClient disconnected from CONNECTED state (transport error), this seems to be something related to karma itself. Check out this thread in karma repository, where this topic has been already discussed.

@alexZaicev
Copy link
Author

alexZaicev commented May 27, 2019

Thanks, will check them out!

Also, I have another question regarding testing, is it possible to get the status of tns test android/ios, if, for example, all the tests are successful and only then run the build? The same behavior is in Maven when you do mvn clean install (it installs the dependencies, runs the test and if the tests are successful it will run the build).

@alexZaicev
Copy link
Author

@tsonevn Ive tried your proposed solution to with the links on how to configure karma, and Ive managed to make karma to upload files, buuuut, now I get a different error:

Error during loading: Uncaught ReferenceError: global is not defined in 
http://localhost:9876/base/tests/example.test.bundle.js?cccf17fbd55109d054fc39d95e2fa703e126a45d 
line 1

I assume that {NS} already has global dependency, and I tried to install it from npm, but it didn`t remove the error. I followed this thread , but it is for Angular project, not {NS} Typescript or any {NS} project related

@arun-s-aot
Copy link

arun-s-aot commented Jun 8, 2020

Hey @alexZaicev , were you able to resolve this issue ? I am also facing a similar issue on running karma test in a nativescript application . I have just started creating a new workspace and tried running a simple test.
image

Expecting your inputs please @tsonevn

@Nileshdcool
Copy link

Nileshdcool commented Jun 25, 2020

Did anyone manage to solve this error? Even I am facing the same problem. The device gets disconnected from the report view of test cases results even though all my test cases are successful.

@Nileshdcool
Copy link

Hi @alexZaicev,
If I understand you correctly, you are executing your tests successfully and the results are printed correctly in the console, and now you want to review the results using browser. To do that you should extend the karma configurations and to add the browser as a report option. Check out this StackOverflow thread, where it is described, how to achieve this.
Regarding DisconnectedClient disconnected from CONNECTED state (transport error), this seems to be something related to karma itself. Check out this thread in karma repository, where this topic has been already discussed.

It's not using the browser only, even the device gets disconnected. It rapidly flashes the test results and then it gets closed down.

@Nileshdcool
Copy link

Hey @alexZaicev , were you able to resolve this issue ? I am also facing a similar issue on running karma test in a nativescript application . I have just started creating a new workspace and tried running a simple test.
image

Expecting your inputs please @tsonevn

Can you tell me what configurations have you made in your karma.config file for you nartivescript project ?

@RoiJS
Copy link

RoiJS commented Jul 17, 2020

I got the exactly the same error. First time to initiate unit testing for my angular nativescript project. Using the default karma configuration and after simply running the tns test android, this error shown up.

Any updates on this?

image

@faisalansari20
Copy link

Hello Everyone,
I am facing same error after creating fresh project and running tns test init and tns test android. Have any one found any solution to this?

@ujwal-setlur
Copy link

me too 👍

@ignacio68
Copy link

@tsonevn Ive tried your proposed solution to with the links on how to configure karma, and Ive managed to make karma to upload files, buuuut, now I get a different error:

Error during loading: Uncaught ReferenceError: global is not defined in 
http://localhost:9876/base/tests/example.test.bundle.js?cccf17fbd55109d054fc39d95e2fa703e126a45d 
line 1

I assume that {NS} already has global dependency, and I tried to install it from npm, but it didn`t remove the error. I followed this thread , but it is for Angular project, not {NS} Typescript or any {NS} project related

Try to change the global prop to "false" in webpack config file:

node: { "global": false }

@anarnoli
Copy link

anarnoli commented Jul 8, 2021

Hi Guys,

Does anyone able to fix this issue? Please suggest configuration is so.

@alexZaicev @tsonevn

Screenshot 2021-07-08 at 12 57 32 PM

@edusperoni
Copy link
Contributor

@anarnoli there's no error there, that disconnect is the test runner disconnecting after a full run.

@anarnoli
Copy link

anarnoli commented Jul 8, 2021

@edusperoni Thanks for confirmation. Just for curiosity - can we make any change in config or so that it can't be disconnected?

@edusperoni
Copy link
Contributor

@anarnoli What do you mean? Why do you want it to remain connected?

You can use --env.stayOpen so your app doesn't close after each run, you also need singleRun: false on your karma.config.js. Just keep in mind that if you do this in CI, it'll never finish.

@kfron
Copy link

kfron commented Jan 15, 2022

@edusperoni In my case it did not help. Even having singleRun: false does not resolve this issue.
And what do you mean by saying that there is no error? It states that there is an error - if it's expected behavior then this message is misleading.

@edusperoni
Copy link
Contributor

  1. Add this to your webpack config in webpack.chainWebpack for the moment. (It seems we forgot to add it to the unit test runner V3, will fix tomorrow)
const { merge } = require('webpack-merge');
config.plugin('DefinePlugin').tap((args) => {
		args[0] = merge(args[0], {
			__TEST_RUNNER_STAY_OPEN__: true
		});

		return args;
	});
  1. That error is there for verbosity. If you see that the connection was lost because the server is shutting down, or the test ended, then that's expected, but if it shows up mid execution, that's probably not expected. Either way what matters is that your report is correct and if anything fails what matters is the error code that karma returns, which is being correctly outputed.

@anarnoli
Copy link

@kfron I used below link to keep the app running in the emulator after the test run has completed.

https://github.com/jcassidyav/nativescript-testing-demo/tree/main/blog#run-the-tests

@anarnoli
Copy link

@edusperoni In my case it did not help. Even having singleRun: false does not resolve this issue. And what do you mean by saying that there is no error? It states that there is an error - if it's expected behavior then this message is misleading.

@kfron Did't helped this flag to resolve the purpose.

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

No branches or pull requests