Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Error on gulp 4.0 #30

Open
joowh85 opened this issue Feb 18, 2016 · 9 comments
Open

Error on gulp 4.0 #30

joowh85 opened this issue Feb 18, 2016 · 9 comments

Comments

@joowh85
Copy link

joowh85 commented Feb 18, 2016

On gulpfile.js..

gulp.task('karma', function (done){
    var karma_server = new Server({
        configFile: __dirname + '/karma.conf.js',
        singleRun: true
    }, done);

    karma_server.start();
});

Then error.

[15:59:59] 'karma' errored after 2.7 s
[15:59:59] Error: 1
    at formatError (C:\Users\joowh\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0-alpha.2\formatError.js:20:10)
    at Gulp.<anonymous> (C:\Users\joowh\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0-alpha.2\log\events.js:26:15)
    at emitOne (events.js:95:20)
    at Gulp.emit (events.js:182:7)
    at Object.error (C:\Users\joowh\Documents\jimiarts-web\node_modules\undertaker\lib\helpers\createExtensions.js:61:10)
    at handler (C:\Users\joowh\Documents\jimiarts-web\node_modules\now-and-later\lib\map.js:46:14)
    at f (C:\Users\joowh\Documents\jimiarts-web\node_modules\once\once.js:17:25)
    at f (C:\Users\joowh\Documents\jimiarts-web\node_modules\once\once.js:17:25)
    at done (C:\Users\joowh\Documents\jimiarts-web\node_modules\async-done\index.js:24:15)
    at removeAllListeners (C:\Users\joowh\Documents\jimiarts-web\node_modules\karma\lib\server.js:336:7)
    at Server.<anonymous> (C:\Users\joowh\Documents\jimiarts-web\node_modules\karma\lib\server.js:347:9)
    at Server.g (events.js:273:16)
    at emitNone (events.js:85:20)
    at Server.emit (events.js:179:7)
    at emitCloseNT (net.js:1514:8)
    at nextTickCallbackWith1Arg (node.js:464:9)

@kevincaradant
Copy link

Hi

I think that can help you :


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

@ilianaza
Copy link

ilianaza commented Mar 9, 2016

Thanks @kevincaradant!

@pkozlowski-opensource
Copy link
Member

@kevincaradant I'm afraid that what you are proposing here is incorrect as it wouldn't correctly propagate karma's exit code to gulp / shell. As such your build would look like passing while it could be failing.

One thing people could try is to do:

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

but I don't see how it differs from:

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

joowh85 @ilianaza when are you getting those Error: 1 errors, exactly? BTW, I don't think it is Windows-specific.

@kevincaradant
Copy link

@pkozlowski-opensource, +1, you re right, my bad, sorry for that. I didnt see before because i use it in my gulp but i never have an error yet. But i fix it for my self .

@antgonzales
Copy link

@pkozlowski-opensource your solution did not work on my machine:

[09:21:36] Error: 1
    at formatError (/Users/anthonygonzalez/src/glossier-v2/node_modules/gulp/bin/gulp.js:169:10)
    at Gulp.<anonymous> (/Users/anthonygonzalez/src/glossier-v2/node_modules/gulp/bin/gulp.js:195:15)
    at emitOne (events.js:77:13)
    at Gulp.emit (events.js:169:7)
    at Gulp.Orchestrator._emitTaskDone (/Users/anthonygonzalez/src/glossier-v2/node_modules/orchestrator/index.js:264:8)
    at /Users/anthonygonzalez/src/glossier-v2/node_modules/orchestrator/index.js:275:23
    at finish (/Users/anthonygonzalez/src/glossier-v2/node_modules/orchestrator/lib/runTask.js:21:8)
    at cb (/Users/anthonygonzalez/src/glossier-v2/node_modules/orchestrator/lib/runTask.js:29:3)
    at /Users/anthonygonzalez/src/glossier-v2/gulpfile.js:101:5
    at removeAllListeners (/Users/anthonygonzalez/src/glossier-v2/node_modules/karma/lib/server.js:336:7)
    at Server.<anonymous> (/Users/anthonygonzalez/src/glossier-v2/node_modules/karma/lib/server.js:347:9)
    at Server.g (events.js:260:16)
    at emitNone (events.js:72:20)
    at Server.emit (events.js:166:7)
    at emitCloseNT (net.js:1524:8)
    at nextTickCallbackWith1Arg (node.js:467:9)

@kevincaradant your solution worked. I think the readme for this repo needs to be updated.

@ankitmithu005
Copy link

ankitmithu005 commented Dec 21, 2016

@pkozlowski-opensource @kevincaradant
Is there any update on this issue?
I am still facing this problem inspite of trying all the above solution.
It is running fine in windows system but it failing in linux.
Our server is deployed on linux.

@kevincaradant
Copy link

kevincaradant commented Jan 3, 2017

@ankitmithu005 , I don't know, sorry, today, I'm using Webpack, my old template was with gulp but I don't maintain it up to date :/

Try to look on Stackoverflow, I found this (quickly without read in detail), I don't know if this can help you but in case:
http://stackoverflow.com/questions/26614738/issue-running-karma-task-from-gulp
http://stackoverflow.com/questions/31844542/gulp-task-cant-find-karma-conf-js/31880355
Swiip/generator-gulp-angular#498

And to finish:
#18

@djabraham
Copy link

djabraham commented Feb 28, 2017

Can't say exactly why, but this seems to work for me at the moment. Perhaps simply passing the returned error code is causing issues in the done() callback, for all I know. A message or new Error('...') on the other hand, might work just fine.

That might actually be a problem with Gulp, IMHO, since information is lacking on what exactly should be passed into the done() function. Unless I missed something in their docs, of course.

gulp.task('unit-test', function (done) {
    var karmaServer = new karma.Server({
        configFile: __dirname + '/test/karma.conf.js',
        singleRun: true
    }, function (exitCode) {
        done();
        process.exit(exitCode);
    }).start();
}); 

But in the meantime, the README should really be updated. That page is highly visible and it took me a while to find a solution, despite the fact this issue was logged in here.

@doshprompt
Copy link

@djabraham it is better to do only one of the two from exit or done, since we may want to continue running some follow-up tasks and if we always exit even on success that will not be possible.

I have noticed flakiness where calling done before exit sometime causes exitCode 0 to be bubbled up to the caller like when running in a CI environment such as travis regardless of what the actual exitCode is.

Lastly, I don't think done is designed to take any arguments, so that is certainly the root cause of the problem with this design in gulp itself as you rightly pointed out.

gulp.task('unit-test', function (done) {
    var karmaServer = new karma.Server({
        configFile: __dirname + '/test/karma.conf.js',
        singleRun: true
    }, function (exitCode) {
        exitCode ? process.exit(exitCode) : done();
    }).start();
}); 

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants