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

karma runner hangs indefinitely #525

Closed
mihaihuluta opened this issue Apr 30, 2013 · 10 comments
Closed

karma runner hangs indefinitely #525

mihaihuluta opened this issue Apr 30, 2013 · 10 comments

Comments

@mihaihuluta
Copy link

Environment

Windows 8 64bit
Node.js 0.10.5 64bit
Karma 0.8.5

I am able to start karma server, Chrome browser opens (I have it defined as default browser in karma config). The issue comes when I am doing 'karma run'. Chrome changes the tab status to Chrome 26.0 (Windows) is executing. But that is all, no output on the console, no nothing. it can stay like that for hours.

Any ideas?

@dogenpunk
Copy link

+1

Windows 7 64bit
Node.js 0.10.5 64bit
Karma 0.8.5

Using jasmine and requirejs. I get the browser connected message in the console. If I update an auto-watched file I get a console message stating that it was changed, then a message: 'Delaying execution, these browsers are not ready: Chrome 26.0 (Windows)'

@vojtajina
Copy link
Contributor

Probably related to #411

@vojtajina
Copy link
Contributor

@mihaihuluta @dogenpunk can you open http://localhost:9876/debug.html, pop up web inspector and see if the tests are actuallly being executed ? Any errors ?

@fschwiet
Copy link

I am seeing this issue. I am learning, so probably making a mistake, but the code is available at https://github.com/fschwiet/letscodejavascript/ if you want to try and repro. I see the same issue on Windows 8 at OSX Mountain Lion.

I am running the browser manually, but otherwise I see the same issue. I tried looking at debug.html too: it is blank when it loads, the console shows tracing that js files were loaded successfully.. The HTML source is pasted at the end of this comment.

For both matchines, node version is v0.10.5. The call to 'karma run' blocks until I reload the browser, when the console then says no tests ran.

server console:

C:\src\letscodejavascript>node_modules\.bin\karma start
INFO [karma]: Karma server started at http://localhost:9876/
INFO [Chrome 26.0 (Windows)]: Connected on socket id gJ6W8ALnw6w1mPPpXcZv
Chrome 26.0 (Windows): Executed 0 of 0 DISCONNECTED (5.798 secs / 0 secs)
WARN [Chrome 26.0 (Windows)]: Disconnected
INFO [Chrome 26.0 (Windows)]: Connected on socket id -j_oEmhy3N3A9latXcZw

client output:

C:\src\letscodejavascript>node_modules\.bin\karma run
Chrome 26.0 (Windows): Executed 0 of 0 DISCONNECTED (5.798 secs / 0 secs)
      C:\src\letscodejavascript [master]> .\karma.bat run

C:\src\letscodejavascript>node_modules\.bin\karma run

Debug.html (the UI renders a blank screen):

<!doctype html>
<!--
This file is almost the same as context.html - loads all source files,
but it's purpose is to be loaded in the main frame (not within an iframe),
just for immediate execution, without reporting to Testacular server.
-->
<html>
<head>
  <title>Karma DEBUG RUNNER</title>
  <!-- TOOD(vojta): create simple favicon and cache it -->
  <link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon" />
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
  <!-- The scripts need to be at the end of body, so that some test running frameworks
   (Angular Scenario, for example) need the body to be loaded so that it can insert its magic
   into it. If it is before body, then it fails to find the body and crashes and burns in an epic
   manner. -->
  <script type="text/javascript">
    window.__karma__ = {
      info: function(info) {
        if (info.dump && window.console) window.console.log(info.dump);
      },
      complete: function() {},
      store: function() {},
      result: window.console ? function(result) {
        if (result.skipped) return;
        var msg = result.success ? 'SUCCESS ' : 'FAILED ';
        window.console.log(msg + result.suite.join(' ') + ' ' + result.description);
      } : function() {},
      loaded: function() {
        this.start();
      }
    };

    // All served files with the latest timestamps
    window.__karma__.files = {
  '/adapter/lib/mocha.js': '1368842050000',
  '/adapter/mocha.js': '1368842050000',
  '/adapter/lib/require.js': '1368842050000',
  '/adapter/require.js': '1368842050000',
  '/base/src/client/_test.js': '1368842055000'
};

  </script>
  <!-- Dynamically replaced with <script> tags -->
  <script type="text/javascript" src="/adapter/lib/mocha.js"></script>
<script type="text/javascript" src="/adapter/mocha.js"></script>
<script type="text/javascript" src="/adapter/lib/require.js"></script>
<script type="text/javascript" src="/adapter/require.js"></script>
  <script type="text/javascript">
    window.__karma__.loaded();
  </script>
</body>
</html>

@mihaihuluta
Copy link
Author

@vojtajina I apologize for my late reply. In my case there were no tests run nor any errors reported on the console.

@TKTheTechie
Copy link

I came across a similar issue when setting up Karma on my Windows 7 PC.

My config initially looked like this -
files = [
JASMINE,
JASMINE_ADAPTER,
QUNIT,
QUNIT_ADAPTER,
REQUIRE,
REQUIRE_ADAPTER,
'unit/*.js'
];

Removing the REQUIRE plugin resolved the issue for me -

files = [
JASMINE,
JASMINE_ADAPTER,
QUNIT,
QUNIT_ADAPTER,
'unit/*.js'
];

I think its a bug with the require plugins?

@fschwiet
Copy link

@PocketDealHunter no, you're making the mistake I made. Your issue is that using the require adapter requires adding an additional js file. See the test-main.js file in the documentation http://karma-runner.github.io/0.8/plus/RequireJS.html

@vojtajina
Copy link
Contributor

@PocketDealHunter also, I don't think combining multiple test frameworks is a good idea. It's possible in theory, but it's not designed for it now.

@fschwiet I think your _test.js contains define(...) right ? You can't do this. You need to have some main.js file, where you configure require.js and require the test files, otherwise require can't resolve the dependencies first - if you directly load the file. (so basically, the main.js file does not have any dependencies). But, based on your later comment, I guess you already figured it out.

Guys, is this issue resolved ? I assume it is and closing it. If you still having this issue, please re-open.

Btw, if you have any ideas, how to make the require.js set easier, let me know or update the docs...

@markballenger
Copy link

I am experiencing this problem as well with requirejs, jasmine, and karma. I well understand the setup for test-main.js, but continue to have this problem.

Karma

// Karma configuration
// Generated on Tue Dec 02 2014 18:27:22 GMT-0500 (Eastern Standard 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','requirejs'],
        // list of files / patterns to load in the browser
        files: [
            'scripts/main-test.js',
            {pattern: 'app/test-spec.js', included: false}
            
        ],
        // list of files to exclude
        exclude: [
            'scripts/_references.js',
            'scripts/jquery*intellisense.js', 
            'scripts/*.min.js',
            'scripts/main.js'
        ],
        // 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: ['junit', 'progress', 'dots'],
        // web server port
        port: 3000,
        // 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_DEBUG,
        // 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: ['Chrome'],
        // Continuous Integration mode
        // if true, Karma captures browsers, runs the tests and exits
        singleRun: false,
        hostname: 'localhost',
        urlRoot: '/',
        plugins: ['karma-requirejs',
                  'karma-junit-reporter',
                  'karma-chrome-launcher',
                  'karma-jasmine'],
        loggers: [{ type: 'console' }]
    });
};

test-main.js

console.log('main-test called...');
var tests = [];
for (var file in window.__karma__.files) {
    if (window.__karma__.files.hasOwnProperty(file)) {
        if (/app.*\.js$/.test(file)) {
            console.log(file);
            tests.push(file);
        }
    }
} 
console.log('calling require.config...');
require.config({
    // relative url from where modules will load
    baseUrl: "/base/app",
    paths: {},
    // ask Require.js to load these files (all our tests)
    deps: tests,
    // start test run, once Require.js is done
    callback: function () { console.log('karma starting...'); window.__karma__.start; console.log('karma started...'); }
});

And the test-spec.js

console.log('test-spec called...');
define([], function () {
    console.log('test-spec define called...');
    describe('test', function () {
        console.log('test-spec describe called...');
        it('should fail', function () {
            console.log('test called...');
            expect(1).toEqual(2);
        });
    });
});

Output from karma

Chrome 39.0.2171 (Windows 8.1) LOG: 'main-test called...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'main-test called...'
Chrome 39.0.2171 (Windows 8.1) LOG: '/base/app/test-spec.js'
Chrome 39.0.2171 (Windows 8.1) LOG: '/base/app/test-spec.js'
Chrome 39.0.2171 (Windows 8.1) LOG: 'calling require.config...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'calling require.config...'
[2014-12-10 11:37:37.066] [DEBUG] web-server - serving (cached): E:/Projects/APA
C2/APAC2/app/test-spec.js
Chrome 39.0.2171 (Windows 8.1) LOG: 'test-spec called...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'test-spec called...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'test-spec describe called...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'test-spec describe called...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'test-spec define called...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'test-spec define called...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'test-spec describe called...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'test-spec describe called...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'karma starting...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'karma starting...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'karma started...'
Chrome 39.0.2171 (Windows 8.1) LOG: 'karma started...'
[2014-12-10 11:37:47.064] [WARN] Chrome 39.0.2171 (Windows 8.1) - Disconnected (
1 times), because no message in 10000 ms.
Chrome 39.0.2171 (Windows 8.1): Executed 0 of 0 DISCONNECTED (10.13 secs / 0 sec
s)
[2014-12-10 11:37:47.069] [DEBUG] reporter.junit - JUnit results written to "E:/
Projects/APAC2/APAC2/test-results.xml".

Note that from test-spec.js, define gets called, and describe gets called, but it never does. The behaviour is exactly as described above and karma just hangs and disconnects, no tests get called.

@markballenger
Copy link

Wow. I ashamedly resolved my problem. face palm. I simply wasn't invoking the window.karma.start() method.... So yeah, must've been in a hurry and had copied code from somewhere and then wrapped the function and forgot to add the (). Sigh. Back to it...

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

6 participants