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

tests seem to start before previous test has finished #1379

Closed
peter-mouland opened this issue Apr 22, 2015 · 3 comments
Closed

tests seem to start before previous test has finished #1379

peter-mouland opened this issue Apr 22, 2015 · 3 comments

Comments

@peter-mouland
Copy link

It seems as if my document.body.innerHTML is being overridden by the subsequent test. When run in sequence, my test fails as it can not find the correct HTML element to test against. When running a single spec file, the tests pass.

This leads me to believe that the next describe functions are being executed before the previous spec has finished.

Is there a way to ensure that the test have finished before moving onto the next spec file?


At the top of my functional tests I load assets onto the page and update the html using:

require('../helper').loadAssets('my-page-name');

helper.js

function appendCSS(path){
    var  link = document.createElement('link');
    link.rel = 'stylesheet';
    link.href='base/' + path;
    document.body.appendChild(link)
}
function appendScript(path){
    var  link = document.createElement('script');
    link.type = 'javascript';
    link.src='base/' + path;
    document.body.appendChild(link)
}
function loadAssets(page){
    document.body.innerHTML = __html__['_site/' + (page || 'index') + '.html'];
    appendCSS( '_site/styles/main.css');
    appendScript( '_site/scripts/' + page + '.js');
}

module.exports = {
    loadAssets: loadAssets
};

I have fixed this by hacking the spec and adding

    beforeEach(function(){
        require('../helper').loadAssets('my-page-name');
    })
@dignifiedquire
Copy link
Member

This depends not only on karma, but also on the testrunner and bundling tools you are using. Can you describe your setup more closely?

@peter-mouland
Copy link
Author

the bundling of files are finished before the tests begin. I happen to be using browserify to bundle my JS, but as i say, this is complete before test begin.

my karma file :

module.exports = function(config) {
    var karmaConfig = {
        basePath: '..',
        browsers: ['PhantomJS'],
        frameworks: ['jasmine', 'browserify'],
        reporters: ['progress'],
        preprocessors: {
            'test/functional/**/*.js': ['browserify'],
            '_site/*.html': ['html2js']
        },
        plugins: [
            'karma-browserify', 'karma-jasmine', 'karma-coverage', 'karma-phantomjs-launcher', 'karma-chrome-launcher', 'karma-html2js-preprocessor'
        ],
        files: [
            {pattern: '_site/**/vendor.*', included: true, served: true, watched: true},//vendor must be first
            {pattern: '_site/**/*.*', included: true, served: true, watched: true},
            'test/functional/**/*.spec.js'
        ],
        exclude: [
            '**/*.png',
            'src/**/*.requirejs.js',
            '**/*.min.js',
            'src/**/*.txt',
            'src/**/*.csv',
            'src/**/*.hbs'
        ]
    };
    var pkg = require('../package.json');
    karmaConfig.browser = pkg.browser || {};
    karmaConfig["browserify-shim"] = pkg["browserify-shim"] || {};
    karmaConfig.browserify = pkg.browserify || {};
    return config.set(karmaConfig);
};

to run the tests I don't use gulp or grunt or anything, just node 'api' karma provides :

function run(singleRun, configPath){
    return new Promise(function(resolve, reject) {
        karma.start({
            configFile: configPath,
            singleRun: singleRun
        }, function(err){
            err && reject(err);
            !err && resolve();
        });
    });
};

@peter-mouland
Copy link
Author

closing this due to lack of interest

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

No branches or pull requests

2 participants