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

Did not manage to run jasmine tests #888

Closed
ghost opened this issue Jan 16, 2014 · 12 comments
Closed

Did not manage to run jasmine tests #888

ghost opened this issue Jan 16, 2014 · 12 comments

Comments

@ghost
Copy link

ghost commented Jan 16, 2014

I intended to run jasmine test on win7, phpstorm7, phpstorm karma plugin. I found multiple problems...

I installed karma from git bash:

npm install -g karma

Despite the statements in the documentation it did not install the karma-* plugins, so I had to install them manually:

npm install -g karma-jasmine
npm install -g karma-requirejs
...

After that I generated a test file with karma:

module.exports = function (config) {
    config.set({
        basePath: 'test',
        frameworks: ['jasmine', 'requirejs'],
        files: [
            {pattern: 'test-mixin.js', included: true}
        ],
        exclude: [

        ],
        reporters: ['progress'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['Firefox'],
        captureTimeout: 60000,
        singleRun: false
    });
};

I tried to run (ofc I installed the plugins after found out by run that they are not installed), but I got the following phenomenons:

  • Sometimes I got port is already in use message, sot it automatically tries with other port (but nothing runs on the 9876 just karma). I tried with another port, I got the same results after some runs.
  • If I close the browser window manually it does not start a new window, just writes that server is not running. If I add the new window manually it starts complaining about port collisions, and opens a new window with different port.
  • I tried to change the browser to Chrome in the config file, but it still did open Firefox window.
  • I have confusing messages in phpstorm windows:
    • empty test suite (in event log)
    • no tests found
    • instantiating tests (for several minutes)
    • unable to attach test reporter to test framework or test framework quit unexpectedly
    • waiting for previous execution
    • [DEBUG] config - No config file specified
    • INFO [karma]: Delaying execution, these browsers are not ready: Firefox 26.0.0 (Windows 7)

I don't know what happens in the background, but the test obviously does not run. :S

1
2
3
4

(The code uses core js only, it does not require browser specific tests, so I'll change to jasmine-node instead of this.)

@ghost
Copy link
Author

ghost commented Jan 16, 2014

I removed the requirejs from the frameworks in the config, now it works. Something is wrong with that plugin...

@ghost
Copy link
Author

ghost commented Jan 16, 2014

Okay, to summarize, I got plugin auto install problems, I had to install the plugins manually, and I got requirejs configuration problems, but the error messages about that were very confusing. Maybe you could add better error messages, because it is not easy to debug such cases. Hmm maybe there is a possible nodejs memory leak too, it is on the second image...

@vojtajina
Copy link
Contributor

@Inf3rno sorry to hear it was tough to get Karma running...

If it didn't install the plugins, that means you probably have an older version of NPM, which does not support peerDependencies. We are gonna remove this anyway. You can however use karma init and it will install required plugins, based on your configuration.

Why did you install Karma globally (Just curious if there is any out-dated docs, because the recommended way is to install Karma locally, per project)?

When using RequireJS, you need to actually start Karma (call __karma__.start()) - see the e2e test example.
This will be easier once #896 is done.

The port already in use means there is another instance of Karma running.
Did Karma crash or something?
This might be IntelliJ/windows issue.

Opening FF - again, sounds like a IntelliJ issue.

cc @segrey

@ghost
Copy link
Author

ghost commented Jan 22, 2014

sorry to hear it was tough to get Karma running...

I don't think that the problem is with karma. I mean you have done a great job, karma is very handy if you know how to use it. I think it's much better than the JSTD I used.
I haven't read the full documentation, I just wanted a fast start with the readme file, to see what this system is capable of. Sadly the current readme file does not support that approach...

If it didn't install the plugins, that means you probably have an older version of NPM, which does not support peerDependencies

I have git 1.7.7.1 (latest 1.8.5.3), node 0.8.10 (latest 0.10.24), npm 1.1.62 (latest 1.3.24). I guess I should update them all... Thanks the recommendation! :-)

Why did you install Karma globally?

I read here that I should install karma this way. Currently I have only a single karma dependent project, so it does not really matter which project has which version of karma...

When using RequireJS, you need to actually start Karma (call __karma__.start()) - see the e2e test example.

Yepp this is well documented in the karma-requirejs plugin. I think you should link these plugins in the readme file. If npm does not install automatically the plugins, it would be more obvious which plugin should we use in which circumstances. If npm installs the plugins automatically, we still have to find the documentation of each plugin we use, and that is easier if there is a link for all of them in the main readme file. For example by firefox we have to use karma-firefox, by requirejs we have to use karma-requirejs, etc... So I think the documentation of karma and each karma plugin is good from a standalone aspect, but there is not enough "glue" between them, at least not in the main readme file..

The port already in use means there is another instance of Karma running.
Did Karma crash or something?
This might be IntelliJ/windows issue.

Ye I think it was. It happens by misconfiguration only, so it does not cause any problem when karma is well configured...

From the other issue:

Karma needs to know about the files because of file watching and heavy caching.

Ye I understand now completely. Karma generates a html file from the karma config file, and use the files with include: true in script tags. This is not so obvious at the first glance, I answered many questions on stackoverflow lately about this, so this should be really part of this section of the readme file.

Another issue is the inverse logic of the order of the file patterns. In programming about 99% of the cases the second pattern overrides the first, so the "First pattern matching a file wins." is very unusual (not just me). Is there a serious reason for this approach?

Please feel free to improve the docs

Should I send a pull request or is there an easier way to do that?

@segrey
Copy link
Contributor

segrey commented Jan 24, 2014

Hi guys,

Sorry for the delay. Please see my answers below.

My environment:
OS: Linux Mint 64-Bit
PhpStorm 7.1.1 (133.679)
Karma IntelliJ plugin: 133.434
Karma package: 0.10.9
Node: 0.10.24

Tested on a sample project with intentionally misconfigured karma-requirejs: https://github.com/segrey/karma-demo

Sometimes I got port is already in use message, sot it automatically tries with other port (but nothing runs on the 9876 just karma). I tried with another port, I got the same results after some runs.

I can only reproduce this issue if I force quite PhpStorm (in Linux: kill -SIGKILL <PhpStorm process id>).
In that case karma server (started by PhpStorm) becomes an orphan process and continues to run even without parent process. Next karma server uses the next free port.
That issue will fixed in PhpStorm 8 (karma server will exit once the IDE process is terminated).

If you're experience that issue without killing PhpStorm instance, please provide your steps to reproduce the problem.

If I close the browser window manually it does not start a new window, just writes that server is not running. If I add the new window manually it starts complaining about port collisions, and opens a new window with different port.

Couldn't reproduce. It'd be appreciated, if you could provide reproducible steps.

I tried to change the browser to Chrome in the config file, but it still did open Firefox window.

Couldn't reproduce. Please help.

I have confusing messages in phpstorm windows:
empty test suite (in event log)
no tests found
instantiating tests (for several minutes)
unable to attach test reporter to test framework or test framework quit unexpectedly
waiting for previous execution

Caused by misconfiguration.
Empty test suite shouldn't be displayed in that case I think.
And other messages also could be refined.
Waiting for previous execution message is from karma itself.

[DEBUG] config - No config file specified

Will be fixed in PhpStorm 8.

INFO [karma]: Delaying execution, these browsers are not ready: Firefox 26.0.0 (Windows 7)

That's output of Karma Server itself.

@ghost
Copy link
Author

ghost commented Jan 27, 2014

Hmm I think it can dependent on the operation system, I used windows 7... I cannot remember what was wrong in the config files, it was 2 weeks ago. I don't think I have commits about that, I usually don't commit buggy code... :S

    browsers: ['Chrome'],

I simply replaced "Firefox" with "Chrome" in the karma.config. I did not have the chrome launcher installed... Got the message, "waiting for browser" now in phpstorm, but I managed to open a firefox window with this settings 2 weeks ago...

If you're experience that issue without killing PhpStorm instance, please provide your steps to reproduce the problem."

You should turn off include:true by every file pattern in your karma config. After that run the tests and close the firefox window manually if it's opened. It won't open a new window after you close, and you will have "cannot attach test reporter", "waiting for browser", "cannot capture browser", etc... messages instead of an "empty test suite" message...

Obviously I did not know what I am doing by that configuration .. :D

@segrey
Copy link
Contributor

segrey commented Jan 30, 2014

It won't open a new window after you close

Yes, that's expected. It opens a new browser window on Karma server startup.
Karma server is reused for subsequent test runs, it allows to have fast test runs.
There is the same behavior if you use Karma in console: at Karma server startup all needed browsers are captured automatically, but they aren't re-captured unless Karma server is restarted manually.

@segrey
Copy link
Contributor

segrey commented Jan 30, 2014

Maybe we could close this issue and file issues related to IntelliJ Karma integeration in the http://youtrack.jetbrains.com/issues/WEB#newissue=yes (subsystem: Unit Tests).

@ghost
Copy link
Author

ghost commented Jan 30, 2014

Okay, I close it.

@ghost ghost closed this as completed Jan 30, 2014
@vojtajina
Copy link
Contributor

@Inf3rno I'm updating the readme. It's pretty out-dated (#905).

Regards updating the docs - yep pull request is the best (the source is here https://github.com/karma-runner/karma/tree/master/docs).

@ghost
Copy link
Author

ghost commented Jan 31, 2014

I think I can write a few lines to the readme.md which can help to understand the basic concept behind karma, but first I read the whole documentation. I do it tomorrow... I think writing the text here or to #905 would be better, I don't want to update the whole documentation, just add one or two sections to the main readme file. The rest is yours...

@raphaelLacerda
Copy link

raphaelLacerda commented Mar 31, 2017

i was having the same problem

it was basically removing requirejs from the list of frameworks
frameworks: ['jasmine'],

or

you should put this file main-test.js (http://karma-runner.github.io/0.8/plus/RequireJS.html)

requirejs.config({
// Karma serves files from '/base'
baseUrl: '/',

callback: window.__karma__.start

});

This issue was closed.
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

3 participants