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

test runs fail randomly, unable to execute the karma-loaded function #9

Open
travi opened this issue Jun 7, 2014 · 6 comments
Open

Comments

@travi
Copy link

travi commented Jun 7, 2014

When running my tests, they fairly regularly fail with the following message: TypeError: 'undefined' is not a function (evaluating 'window.__karma__.loaded()'). Rerunning the tests solves the problem, but the instability is frustrating when developing locally and unacceptable when it randomly fails on the ci-server (travis-ci).

Is it possible that I have configured something incorrectly?

I'm executing the tests with grunt and the project is available here, if that would help diagnose.

@michal-lipski
Copy link

I have the same error on first run. Tests run with no problems after second try

package.json

{
    "devDependencies": {
        "barcoder": "~1.1.1",
        "grunt": "~0.4.4",
        "jasmine-reporters": "1.0.1",
        "karma": "~0.12.24",
        "karma-chai-plugins": "^0.2.3",
        "karma-chrome-launcher": "~0.1.5",
        "karma-coverage": "^0.2.6",
        "karma-cucumberjs": "krzysztof-jelski/karma-cucumberjs",
        "karma-jasmine": "~0.1.5",
        "karma-junit-reporter": "~0.2.2",
        "karma-ng-html2js-preprocessor": "~0.1.0",
        "karma-phantomjs-launcher": "~0.1.4",
        "protractor": "~0.21.0",
        "request": "~2.34.0"
    }
}

cucumber.conf.js

module.exports = function (config) {
    var cucumberConfig = {
        basePath: '../../../',
        exclude: [],
        files: [
           ..some files...
        ],
        ngHtml2JsPreprocessor: {
            moduleName: 'karma.cached.htmls',
            cacheIdFromPath: function (filepath) {
                return filepath.replace("main/webapp/app/", "/app/");
            }
        },
        preprocessors: {'**/*.html': ['ng-html2js']},
        frameworks: ['cucumberjs', 'chai'],
        browsers: [
            'PhantomJS'
        ],
        port: 9877,
        urlRoot: '/_karma_/',
        singleRun: true,
        autoWatch: false
    };

    config.set(cucumberConfig);
};

@amatiasq
Copy link

Same error here, any progress?

amatiasq added a commit to amatiasq/karma-cucumberjs that referenced this issue Jan 14, 2015
@amatiasq
Copy link

Found it, it was a HTML parsing - JS timeout race condition. Pull request: #14

In the meantime if you still have this issue you can use the repository where this bug is already fixed:
https://github.com/amatiasq/karma-cucumberjs

@jrobison153
Copy link

I had to close my previous pull request, the race condition was not resolved. After a little more investigation I think the problem is caused by the mix of this adapter which uses requirejs and the Karma load which does not. Within Karma's context.html document the last script tag makes a call to window.karma.loaded(), however this adapter is loading asynchronously at the same time, it's pure chance if it's finished loading before Karma tries to call start().

My previously closed pull request contains the necessary fixes to integrate with the Karma framework, primarily do not monkey with karma.loaded and do not call start() from the adapter. The trick now is to make sure the adapter loads completely before karma attempts to call start(). I see now why s9tpepper was trying to override the loaded function and was calling start() from the adapter code, it was an attempt to work around this race condition.

A solution could be to remove requirejs, I don't see the value in AMD here. Module management could be handled by commonjs and browserify/webpack.

@s9tpepper
Copy link
Owner

Yea I thought this was resolved and then it reared its ugly head again. Going to try a few things this week to resolve this once and for all.

@inthegarage
Copy link

@s9tpepper Did you manage to research the problem? It seems to happen very regularly here.
In the meantime I found that the following fix in the context.html got things moving:

replace:
window.karma.loaded();

with:
function loadKarma() {
if (window.karma.loaded)
window.karma.loaded();
else {
setTimeout(loadKarma, 500);
}
}
loadKarma();

This change in node_modules/karma/static/context.html and debug.html in the same dir.

Ok so no retry count etc, but it will get you moving in the right direction.

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

Successfully merging a pull request may close this issue.

6 participants