lazd / gulp-karma

Karma plugin for gulp
MIT License
75 stars 36 forks source link

include file not being included #27

Closed callumacrae closed 9 years ago

callumacrae commented 10 years ago

My karma.conf.js contains this:

        // list of files / patterns to load in the browser
        files: [
            {pattern: 'node_modules/should/should.min.js', include: true},
            'tests/**/*.spec.js'
        ],

It works fine when I run it directly through karma, but when I run it through Gulp, I'm getting the following error:

[gulp] Starting Karma server...
INFO [karma]: Karma v0.12.3 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [launcher]: Starting browser Firefox
INFO [Chrome 33.0.1750 (Mac OS X 10.9.2)]: Connected on socket mlbZmue-cZ-ZzjWbNby2 with id 54290239
Chrome 33.0.1750 (Mac OS X 10.9.2) API meta should return with root FAILED   
        TypeError: Cannot read property 'be' of undefined
            at Context.<anonymous> (/Applications/XAMPP/xamppfiles/htdocs/dirname/tests/api.spec.js:8:16)
            at callFn (/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4338:21)
            at Test.Runnable.run (/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4331:7)
            at Runner.runTest (/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4728:10)
            at /Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4806:12
            at next (/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4653:14)
            at /Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4663:7
            at next (/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4601:23)
            at /Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4630:5
            at timeslice (/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:5761:27)
Chrome 33.0.1750 (Mac OS X 10.9.2): Executed 1 of 1 (1 FAILED) ERROR (0.021 secs / 0.001 secs)
Firefox 26.0.0 (Mac OS X 10.9) API meta should return with root FAILED                          
        "/".should is undefined                                          
        @/Applications/XAMPP/xamppfiles/htdocs/dirname/tests/api.spec.js:8
        callFn@/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4338
        Runnable.prototype.run@/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4331
        Runner.prototype.runTest@/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4728
        next/<@/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4806
        next@/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4653
        next/<@/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4663
        next@/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4601
        Runner.prototype.hook/<@/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:4630
        timeslice@/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/mocha/mocha.js:5761

Chrome 33.0.1750 (Mac OS X 10.9.2): Executed 1 of 1 (1 FAILED) ERROR (0.021 secs / 0.001 secs)
Firefox 26.0.0 (Mac OS X 10.9): Executed 1 of 1 (1 FAILED) ERROR (0.006 secs / 0.001 secs)

/Applications/XAMPP/xamppfiles/htdocs/dirname/gulpfile.js:94
                        throw err;
                              ^
[gulp] Error in plugin 'gulp-karma': karma exited with code 1
    at done (/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/gulp-karma/index.js:56:30)
    at ChildProcess.<anonymous> (/Applications/XAMPP/xamppfiles/htdocs/dirname/node_modules/gulp-karma/index.js:82:7)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at Process.ChildProcess._handle.onexit (child_process.js:789:12)

Here is my test file:

'use strict';

/* global describe, it */

describe('API', function () {
    describe('meta', function () {
        it('should return with root', function () {
            ('/').should.be.exactly('/');
        });
    });
});

Here is my gulp task:

gulp.task('test', function() {
    // Be sure to return the stream
    return gulp.src('tests/**/*.spec.js')
        .pipe(plugins.karma({
            configFile: 'karma.conf.js',
            action: 'run'
        }))
        .on('error', function (err) {
            throw err;
        });
});

To me, it looks like should.js isn't being included at all. I don't know how to debug it, though.

vitalybe commented 10 years ago

I am experiencing the same issue. It looks like Karma ignores the files options completely, when used from gulp-karma.

feugy commented 10 years ago

I've got the same issue: files specified in the configuration are totally ignored. See in the main plugin file.

I'm still searching for a workaround.

callumacrae commented 10 years ago

If I recall correctly, you can add it to the files specified in gulp.src() and that should work around the issue. Can't really remember though, and I'm not using it any more because the author seems to have abandoned it.

lazd commented 10 years ago

@callumacrae, gulp-karma hasn't been abandoned, but it definitely should be killed. Why? It's simply not suited to be a gulp plugin due to the problems mentioned here and over at https://github.com/lazd/gulp-karma/issues/9. Karma has it's own notion of globs that include more that just a path pattern to match, and that's just not compatible with gulp.src.

However, @feugy and @vitalybe, all hope is not lost. For a potentially viable solution, please check out https://github.com/lazd/gulp-karma/issues/21#issuecomment-40786028 . If we can get a few things patched up in Karma, I think this approach will be the best way to use Karma with gulp.

lazd commented 9 years ago

gulp-karma is deprecated (#43). Please use Karma directly: https://github.com/karma-runner/gulp-karma