nikku/karma-browserify

karma-browserify and require-globify

Closed this issue · 11 comments

I'm pulling my hair out over this issue and I would really appreciate some help. I added the require-globify transform to my regular Browserify config and the project builds fine. However, when trying to incorporate it into browserify-karma, the plugin doesn't seem to run. I'm sure I'm doing something dumb with the config, but I can't figure out what the problem is.

Here's my karma.config.js file:

'use strict';

module.exports = function(config) {

  config.set({

    basePath: '../',

    frameworks: ['browserify', 'jasmine'],

    preprocessors: {
      'app/js/**/*.js': ['browserify'],
      'test/**/*.js': [ 'browserify' ],
      '**/*.json'   : ['html2js']
    },

    browserify: {
      debug: true,
      transform: ['brfs', 'require-globify']
    },

    browsers: ['PhantomJS'],

    plugins: [
      'karma-phantomjs-launcher',
      'karma-jasmine',
      'karma-browserify',
      'karma-chrome-launcher',
      'karma-firefox-launcher',
      'karma-fixture',
      'karma-html2js-preprocessor'
    ],

    files: [
      'app/js/main.js',
      'test/unit/**/*.js',
      'fixtures/api/*.json'
    ]
  });
};

Here's the Gulp task I'm using to run the tests:

'use strict';

var gulp = require('gulp');
var KarmaServer = require('karma').Server;
var path = require('path');

gulp.task('test', function(callback) {
  new KarmaServer({
    configFile: path.join(__dirname, "../../test/karma.conf.js"),
    singleRun: true
  }, function() { callback(); }).start();
});

Thanks in advance!

Can you try this with https://github.com/substack/bulkify to make sure it's not just this transform? FWIW, bulkify is also going to be a better choice since it'll let you write valid CommonJS as opposed to what you have which won't run in Node.

Bulkify seemed to do the trick! Thanks for the quick reply @bendrucker.

I take that back. I still seem to be having a different issue with Bulkify:

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  TypeError: undefined is not a constructor (evaluating 'fs.readdirSync(abs)')
  at /var/folders/6r/8b6sxn4s6jg0ydh00jh63vd40000gn/T/37dcc2c245c2e5295e8d4b01288997c2.browserify:1448 <- node_modules/bulk-require/node_modules/glob/glob.js:662:0

Thanks again for the help!

nikku commented

Please upload your example somewhere on GitHub for inspection. This way we can have a quick look into what you are doing and see what may be wrong.

I have almost the same issue with Karma-Browserify. On my case the firing library is Jasmine.

PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
TypeError: undefined is not a constructor (evaluating 'fs.readdirSync(rootPath)')
at C:/Users/Antonio/AppData/Local/Temp/985b09a67adf62ae751a83aa8c033b23.browserify:1485 <- node_modules/jasmine-core/lib/jasmine-core.js:14:0

Sorry if this little information does not provide much insight. My karma.conf.js file is similar to the one posted by @LandonSchropp. This issue is hampering me to run tests for React. Unfortunately I have not found any other relevant troubleshooting apart from this issue.

Hey, sorry to disappoint, but we ended up switching to Webpack after running into this and a couple other issues. I'm afraid I won't be much more help on this thread, so feel free to close it or answer @AntonioRedondo's question instead. Thanks!

This is an update to the issue of my above comment. The issue was not created by any possible bug on Karma Browserify but for something much pettier (and random). Before import JasmineAjax from "jasmine-ajax" I was including import Jasmine from "jasmine". This last import was not required and was spoiling everything. Don't ask why.

So I want to try to bring this thread back. Example code for the original issue would be a huge help @LandonSchropp. The idea here would be to remove gulp et al and just narrow this issue down to the transform + karma-browserify.

@bendrucker I'm sorry, but I don't have any more example code that what I posted above. Like I said, I ended up pulling karma-browserify from our app when we ran into these issues.

Ok. I'm going to close this out and we can investigate further if someone with this setup wants to help in the future.

@LandonSchropp Did you manage this with the require-globify transformation? I am getting an error, because browserify does not understand the glob pattern. :S