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

Race condition with browserify preprocessing? #127

Open
levity opened this issue Oct 23, 2014 · 2 comments
Open

Race condition with browserify preprocessing? #127

levity opened this issue Oct 23, 2014 · 2 comments

Comments

@levity
Copy link

levity commented Oct 23, 2014

I'm using karma-bro to provide browserify support for karma, and it looks like there's a race condition between the preprocessing and the running of tests. It only happens with grunt-karma, not when I run karma directly.

When I change one of my test files to flip a test between failing and not failing, then save, watch picks up the change, but the test outcome is as if I hadn't made the change. When I make and save a second change, the outcome is as if I'd only made the first change. e.g.:

it('does basic math', function() { expect(4 + 4).toEqual(8); }); 
// file starts like this

it('does basic math', function() { expect(4 + 4).toEqual(10); }); 
// save -- test passes

it('does basic math', function() { expect(4 + 4).toEqual(9); }); 
// save -- test fails with "expected 8 to equal 9"

it('does basic math', function() { expect(4 + 4).toEqual(8); }); 
// save -- test fails with "expected 8 to equal 10"

I'm guessing the preprocessing is happening in the karma:dev:start thread, so there's a race condition. Any suggestions for how to work around this?

My Karma config:

'use strict';

module.exports = function(config) {
  config.set({
    basePath: '',
    browserify: {
      debug: true,
      transform: ['debowerify']
    },
    frameworks: ['browserify', 'jasmine'],
    files: [
      'test/setup.js',
      'test/**/*.tests.js'
    ],
    preprocessors: {
      'test/**/*.js': ['browserify']
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

My Grunt config (excerpted):

module.exports = function(grunt) {

  grunt.initConfig({
    karma: {
      options: {
        configFile: 'karma.config.js',
      },
      dev: {
        autoWatch: false,
        background: true,
        singleRun: false,
        logLevel: 'DEBUG'
      },
      once: {
        singleRun: true,
        browsers: ['PhantomJS']
      }
    },
    watch: {
      karma: {
        files: ['src/**/*', 'test/**/*.js'],
        tasks: ['karma:dev:run']
      }
    }
  });

  require('load-grunt-tasks')(grunt);
  grunt.registerTask('dev', ['karma:dev:start', 'watch']);
};
@mcoquet
Copy link

mcoquet commented Mar 23, 2015

have you had any success with this? I'm suffering from the same issue.

@levity
Copy link
Author

levity commented Mar 25, 2015

Sorry, I haven't.

On Mon, Mar 23, 2015 at 7:04 AM, Miguel Coquet notifications@github.com
wrote:

have you had any success with this? I'm suffering from the same issue.


Reply to this email directly or view it on GitHub
#127 (comment)
.

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

2 participants