floriangrundig / karma-test-runner

Grails plugin to run javascript tests with karma in grails lifecycle "test-app"
Apache License 2.0
7 stars 5 forks source link

Not connected to server with reporters: ['remote'] #17

Open steel119 opened 8 years ago

steel119 commented 8 years ago

When i run karma start karma.conf.js

I am getting the below error:

c:\NIWorkSpace\network-insights-web-portal>karma start karma.conf.js 24 05 2016 12:24:51.473:INFO [karma]: Karma v0.13.22 server started at http://lo calhost:9876/ 24 05 2016 12:24:51.488:INFO [launcher]: Starting browser PhantomJS 24 05 2016 12:24:52.488:INFO [reporter.remote]: Error while communicate to remot e server ("localhost:8888") to report test results. Error: connect ECONNREFUSED 127.0.0.1:8888 24 05 2016 12:24:52.489:INFO [reporter.remote]: Connection closed 24 05 2016 12:24:53.057:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on s ocket /#dGuxYeoDdWFNol1QAAAA with id 55430891 24 05 2016 12:24:53.079:ERROR [reporter.remote]: Not connected to server. 24 05 2016 12:24:53.089:ERROR [reporter.remote]: Not connected to server. 24 05 2016 12:24:53.091:INFO [reporter.remote]: Error while communicate to remot e server ("localhost:8888") to report test results. Error: This socket is closed 24 05 2016 12:24:54.095:INFO [reporter.remote]: Karma finished...

c:\NIWorkSpace\network-insights-web-portal>

My karma.conf.js file is:

// Karma configuration // Generated on Tue May 24 2016 10:48:30 GMT-0400 (Eastern Daylight Time)

module.exports = function(config) { config.set({

// 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: [

  //'js/angular/angular.min.js',
  //'web-app/test/angular-mocks.js',
  //'js/angular/angular-mocks.js',
  'web-app/test/*Spec.js'

],

// 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: ['remote'],
remoteReporter: {
    host: 'localhost',
    port: '8888'
},

// 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: false,

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

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

logLevel: config.LOG_INFO,

plugins: [
  'karma-jasmine',
  //'karma-junit-reporter',
  'karma-chrome-launcher',
  'karma-phantomjs-launcher',
  'karma-remote-reporter'
],

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity

}) }

Any help would be appreciated.

Thanks

floriangrundig commented 8 years ago

Hi,

in your karma config you've configured the remote reporter to point to localhost:8888 which is not the default port (9889). If you want to use a different port then you have to annotate the test class with @KarmaTestSuiteRunner.KarmaRemoteServerPort(8888) (I've described that almost at the end of the documentation)... Have you done that?

With kind regards

steel119 commented 8 years ago

Thanks for the response. I initially tried it with the default port but got the same error, Please find the error for your reference:

c:\NIWorkSpace\network-insights-web-portal>karma start karma.conf.js 24 05 2016 13:06:44.803:INFO [karma]: Karma v0.13.22 server started at http://lo calhost:9876/ 24 05 2016 13:06:44.803:INFO [launcher]: Starting browser PhantomJS 24 05 2016 13:06:45.809:INFO [reporter.remote]: Error while communicate to remot e server ("localhost:9889") to report test results. Error: connect ECONNREFUSED 127.0.0.1:9889 24 05 2016 13:06:45.809:INFO [reporter.remote]: Connection closed 24 05 2016 13:06:46.356:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on s ocket /#fN2SRkxmFOciQtzsAAAA with id 78011606 24 05 2016 13:06:46.377:ERROR [reporter.remote]: Not connected to server. 24 05 2016 13:06:46.387:ERROR [reporter.remote]: Not connected to server. 24 05 2016 13:06:46.389:INFO [reporter.remote]: Error while communicate to remot e server ("localhost:9889") to report test results. Error: This socket is closed 24 05 2016 13:06:47.392:INFO [reporter.remote]: Karma finished...

floriangrundig commented 8 years ago

Can you post one of the test cases?

steel119 commented 8 years ago

i have not event started with writing test case. I was just trying the setup.When i tried to run 'karma start karma.conf.js' there was an error.

Below is the link that i am referencing for setting-up : https://objectpartners.com/2014/08/19/add-javascript-unit-tests-and-run-them-with-grails-test-app/

floriangrundig commented 8 years ago

haha - interesting - I didn't know that somebody actually wrote about that plugin :)

So back to the problem:

You need at least one test case e.g. ` import de.is24.util.karmatestrunner.junit.KarmaTestSuiteRunner import org.junit.runner.RunWith

@RunWith(KarmaTestSuiteRunner.class) @KarmaTestSuiteRunner.KarmaConfigPath("./path/to/karma.conf.js")

public class JavaScriptUnitTestKarmaSuite {

} `

The test runner I've implemented (@RunWith(KarmaTestSuiteRunner.class)) will start a server and will receive the tests results from karma which are send by the configured remote reporter karma plugin... When the server receives the test results from karma it will publish them as JUnit test reports... But without one test case - nobody starts the server, that's why the remote reporter karma plugin outputs the connection refused exception ...

Does that make sense to you?

with kind regards

steel119 commented 8 years ago

Totally makes sense. Let me try it. Thanks again

steel119 commented 8 years ago

I got it working. Thanks for the help A quick question though I have my own grails plugins where we have given angular.min.js Now in my module where i have configured karma.conf.js i need to use the angular.min.js from the plugin as i don't want to duplicate it in all the modules. When i run the unit test with ''test-app unit:javascript" it is not able to reference the "angular.min.js" from the plugin. Though if i give "angular.min.js" locally its running fine.

floriangrundig commented 8 years ago

Hmm - I'm not sure I understand your problem correctly - let me summarise what I think you've meant:

You've have a grails application which consists of several modules (plugins) -> one of you're plugins contains the static js resources like angular.min.js let's call it my-resources-plugin Another plugin or the main app let's call it foo-module depends on that my-resources-plugin and foo-module contains the js tests. Now you have the problem that foo-module can not run the tests since you can't reference the my-resources-plugin::angular.min.js in the foo-module::karma.conf.js?

If that's the case - I'm not sure whether I can help you that much since my grails-time is over for almost 2 years and I don't know grails in that detail anymore... (But as a motivation - in my previous job we had exactly the situation I described above and we solved it somehow, but I can't remember how :)

But let me ask a question: if your foo-module depends on my-resources-plugin (I guess the dependency is a compile dependency) the my-resources-plugin should be stored somewhere in the directory of the foo-module (e.g. //target/work/plugins)? If so you still can reference the angular.min.js (you just need to move the karma.conf.js in a parent directory....

Does that help you?