capaj / require-globify

transform for browserify, which allows to require files with globbing expressions
MIT License
70 stars 11 forks source link

karma-browserify support? #27

Open ghost opened 8 years ago

ghost commented 8 years ago

Is it possible to use this lib with karma-browserify? It does not seem to work. I am trying with this karma.conf.js:

module.exports = function (config) {
    config.set({
        plugins: [
            "karma-browserify",
            "karma-chrome-launcher",
            "karma-mocha"
        ],
        frameworks: ["browserify", "mocha"],
        files: [
            "yadda.js",
            "index.js",
            "lib/**/*.js",
            {pattern: "lib/**/!(*.js)", included: false},
            "features/**/*.js",
            {pattern: "features/**/!(*.js)", included: false}
        ],
        preprocessors: {
            "index.js": ["browserify"],
            "yadda.js": ["browserify"],
            "lib/**/*.js": ["browserify"],
            "features/**/*.js": ["browserify"]
        },
        client: {
            mocha: {
                reporter: "html",
                ui: "bdd"
            }
        },
        browserify: {
            debug: true,
            transform: ["require-globify"]
        },
        browsers: ["Chrome"],
        reporters: ["progress"],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: false,
        captureTimeout: 6000,
        singleRun: true
    });
};

and I got bundle error by adding a function to the yadda.js file

function fixDynamicRequire() {
    require('./features/**/*.js', {mode: "expand"});
}

What am I missing?

ghost commented 8 years ago

Others use the same settings so I still don't understand. https://github.com/kaasbaardje/gherkin-karma-example/blob/master/test/test.spec.js

ghost commented 8 years ago

The module is loaded at least browserify is looking for it if I uninstall it. So there is a bug somewhere in the system I wasn't able to identify. I decided to do this manually since I have only 4 step definitions, so I added a temporary fix to the end of the file:

function fixDynamicRequireByBrowserify() {
    // note: require_globify did not work, so I have to do this manually until I find a better solution. :S
    require("./features/step_definitions/noop");
    require("./features/step_definitions/Class");
    require("./features/step_definitions/UserError");
    require("./features/step_definitions/CompositeError");
}