꿀꺽 꿀꺽에서 카르마 작업 실행 문제
gulp 작업에서 karma 테스트를 실행하려고하는데이 오류가 발생합니다.
Error: 1
at formatError (C:\Users\Tim\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:161:10)
at Gulp.<anonymous> (C:\Users\Tim\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:187:15)
at Gulp.emit (events.js:95:17)
at Gulp.Orchestrator._emitTaskDone (C:\path\to\project\node_modules\gulp\node_modules\orchestrator\index.js:264:8)
at C:\path\to\project\node_modules\gulp\node_modules\orchestrator\index.js:275:23
at finish (C:\path\to\project\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:21:8)
at cb (C:\path\to\project\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:29:3)
at removeAllListeners (C:\path\to\project\node_modules\karma\lib\server.js:216:7)
at Server.<anonymous> (C:\path\to\project\node_modules\karma\lib\server.js:227:9)
at Server.g (events.js:180:16)
내 시스템은 Windows 7, nodejs 버전 은 , gulp 버전입니다 v0.10.32.
[10:26:52] CLI version 3.8.8
[10:26:52] Local version 3.8.9
또한 Ubuntu 12.04 LTS최신 Ubuntu (어떤 버전인지 확실하지 않음) 및 Mac OS 에서 동일한 오류가 발생 하면 정상적으로 작동하는 것 같습니다. 이 오류의 원인은 무엇입니까?
업데이트 5/11/2016 : 수락 된 답변 숨기기 오류에 대한 의견을 작성하기 전에 해당 특정 수락 된 답변에 대한 처음 두 개의 댓글을 참조하십시오. 무엇을하고 있는지 알고있는 경우에만 사용하십시오. 관련 정보 : https://github.com/karma-runner/gulp-karma/pull/15
Gulp로 테스트를 어떻게 실행하고 있습니까? 나는 최근에 OSX에서이 문제에 대해 생각해 v0.11.14냈고 3.8.10, 테스트가 실패 할 때마다 node 및 gulp를 실행했습니다 .
권장 사항에서 변경 :
gulp.task('test', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done);
});
에:
gulp.task('test', function(done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function() {
done();
});
});
...이 오류를 제거했습니다.
콜백에서 오류가 신호를 받았을 때 gulp가 오류 메시지를 처리하는 방법에 대한 것 같습니다. 자세한 정보는 종료시 오류 메시지 개선 을 참조하십시오.
gulp 3.9.1 및 karma 1.1.1을 사용하여 이러한 솔루션 중 어느 것도 올바르게 작동하지 않았습니다. gulp-util에 대한 참조를 추가 npm install --save-dev gulp-util하고 작업을 아래로 업데이트하면 종료 상태를 올바르게 유지하면서 오류 출력이 매우 멋지게 수정됩니다.
var gutil = require('gulp-util');
gulp.task('test', function (done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function(err){
if(err === 0){
done();
} else {
done(new gutil.PluginError('karma', {
message: 'Karma Tests failed'
}));
}
}).start();
});
다음은 Karma 사용에 대한 꿀꺽 꿀꺽 패턴의 코드 스 니펫입니다. 약간 비슷하지만 업장을 시작하는 새로운 방법을 사용합니다.
/**
* Start the tests using karma.
* @param {boolean} singleRun - True means run once and end (CI), or keep running (dev)
* @param {Function} done - Callback to fire when karma is done
* @return {undefined}
*/
function startTests(singleRun, done) {
var child;
var excludeFiles = [];
var fork = require('child_process').fork;
var KarmaServer = require('karma').Server;
var serverSpecs = config.serverIntegrationSpecs;
if (args.startServers) {
log('Starting servers');
var savedEnv = process.env;
savedEnv.NODE_ENV = 'dev';
savedEnv.PORT = 8888;
child = fork(config.nodeServer);
} else {
if (serverSpecs && serverSpecs.length) {
excludeFiles = serverSpecs;
}
}
var server = new KarmaServer({
configFile: __dirname + '/karma.conf.js',
exclude: excludeFiles,
singleRun: singleRun
}, karmaCompleted);
server.start();
////////////////
function karmaCompleted(karmaResult) {
log('Karma completed');
if (child) {
log('shutting down the child process');
child.kill();
}
if (karmaResult === 1) {
done('karma: tests failed with code ' + karmaResult);
} else {
done();
}
}
}
나를 위해 일하고 멋진 형식의 오류 메시지를 준 것은 done콜백에 Error 인스턴스를 제공하는 것 입니다.
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();
});
});
If you want to return with an error code, and want to see Karma's error output but not Gulp's (probably unrelated) stack trace:
gulp.task('test', function() {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function(karmaExitStatus) {
if (karmaExitStatus) {
process.exit(1);
}
});
});
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
this is gulp's way of telling your tests have failed and that karma exited with a return code of 1. Why you would want to call done yourself and not pass the error as a message baffles me.
The right way to solve this according to Karma's documentation and https://github.com/pkozlowski-opensource, is to rely on Karma's watch mechanism rather than Gulp's:
gulp.task('tdd', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js'
}, done);
});
Note the omission of singleRun: true.
@McDamon's workaround will work for gulp.watch, but you don't want to swallow exit codes like that when running on a CI server.
Gulp is also reworking how they handle exit codes in scenarios just like this one. See https://github.com/gulpjs/gulp/issues/71 and the other dozen or so related issues.
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.
In case anyone else comes here, do not use the accepted solution. It will hide failed tests. If you need a quick solution to modify your gulp test task, you can use the solution found in this comment in this github thread.
gulp.src(src)
// pipeline...
.on('error', function (error) {
console.error('' + error);
});
참고URL : https://stackoverflow.com/questions/26614738/issue-running-karma-task-from-gulp
'IT TIP' 카테고리의 다른 글
| 익명 열거 형 사용 (0) | 2020.11.19 |
|---|---|
| Vagrant / VirtualBox / Apache2 이상한 캐시 동작 (0) | 2020.11.19 |
| 더 빠른 해시 조회 또는 이진 검색? (0) | 2020.11.19 |
| mysql 서버 포트 번호 (0) | 2020.11.19 |
| Java에서 main 메소드를 오버로드 할 수 있습니까? (0) | 2020.11.19 |