Issue running karma task from gulp

前端 未结 10 2210
隐瞒了意图╮
隐瞒了意图╮ 2020-12-25 09:44

I am trying to run karma tests from gulp task and I am getting this error:

Error: 1
   at formatError (C:\\Users\\Tim\\AppData\\Roaming\\npm\\node_modules\\g         


        
相关标签:
10条回答
  • 2020-12-25 10:11
    gulp.task('test', function(done) {
        karma.start({
            configFile: __dirname + '/karma.conf.js',
            singleRun: false 
        }, done);
    });
    

    passing singleRun: false argument will prevent the process from returning a value different of 0 (which would signify an error and exit gulp).

    Run with singleRun: true if you only launching your test from a command line, not part of a continuous integration suite.

    0 讨论(0)
  • 2020-12-25 10:15

    What worked for me and gave a nice formatted error message is to provide an Error instance to the done callback.

    gulp.task('test', function(done) {
        karma.start({
            configFile: __dirname + '/karma.conf.js',
            singleRun: true
        }, function(result) {
            if (result > 0) {
                return done(new Error(`Karma exited with status code ${result}`));
            }
    
            done();
        });
    });
    
    0 讨论(0)
  • 2020-12-25 10:16

    Not sure about Ubuntu, but I was getting a similar error on Windows, and installing one version back fixed it right away like this:

    npm install -g gulp@3.8.8
    npm install gulp@3.8.8
    
    0 讨论(0)
  • 2020-12-25 10:17

    How are you running your tests with Gulp? I came up against this issue recently on OSX, running node v0.11.14 and gulp 3.8.10, whenever there were failing tests.

    Changing from the recommended:

    gulp.task('test', function(done) {
        karma.start({
            configFile: __dirname + '/karma.conf.js',
            singleRun: true
        }, done);
    });
    

    To:

    gulp.task('test', function(done) {
        karma.start({
            configFile: __dirname + '/karma.conf.js',
            singleRun: true
        }, function() {
            done();
        });
    });
    

    ...got rid of this error.

    Seems to be down to how gulp handles error messages when an error is signalled in a callback. See Improve error messages on exit for more information.

    0 讨论(0)
提交回复
热议问题