मेरे पास gulp.js का सेट है जो मेरे मोचा परीक्षण चलाने के लिए है जो gulp-mocha के माध्यम से चल रहे आकर्षण की तरह काम करता है। प्रश्न: मैं अपने मोचा परीक्षणों को गलप के माध्यम से कैसे चला सकता हूं? मैं क्या देख रहा हूं यह देखने के लिए कि मेरे स्रोत और परीक्षण फ़ाइलों में ब्रेक पॉइंट सेट करने के लिए node-inspector जैसे कुछ उपयोग करना चाहूंगा। मैं पहले से ही नोड सीधे फोन करके यह पूरा करने में सक्षम हूँ:गुलप: मोचा परीक्षण डीबग करने का लक्ष्य
node --debug-brk node_modules/gulp/bin/gulp.js test
लेकिन मैं एक घूंट लक्ष्य है कि मेरे लिए यह लपेटता, उदा .:
gulp.task('test-debug', 'Run unit tests in debug mode', function (cb) {
// todo?
});
विचार पसंद करते हैं? मैं bash
स्क्रिप्ट या किसी अन्य अलग फ़ाइल से बचना चाहता हूं क्योंकि मैं एक पुन: प्रयोज्य gulpfile
को उन लक्ष्यों के साथ उपयोग करने की कोशिश कर रहा हूं जो किसी ऐसे व्यक्ति द्वारा प्रयोग योग्य हैं जो गल्प को नहीं जानता है।
यहाँ है मेरे वर्तमान gulpfile.js
// gulpfile.js
var gulp = require('gulp'),
mocha = require('gulp-mocha'),
gutil = require('gulp-util'),
help = require('gulp-help');
help(gulp); // add help messages to targets
var exitCode = 0;
// kill process on failure
process.on('exit', function() {
process.nextTick(function() {
var msg = "gulp '" + gulp.seq + "' failed";
console.log(gutil.colors.red(msg));
process.exit(exitCode);
});
});
function testErrorHandler(err) {
gutil.beep();
gutil.log(err.message);
exitCode = 1;
}
gulp.task('test', 'Run unit tests and exit on failure', function() {
return gulp.src('./lib/*/test/**/*.js')
.pipe(mocha({
reporter: 'dot'
}))
.on('error', function (err) {
testErrorHandler(err);
process.emit('exit');
});
});
gulp.task('test-watch', 'Run unit tests', function (cb) {
return gulp.src('./lib/*/test/**/*.js')
.pipe(mocha({
reporter: 'min',
G: true
}))
.on('error', testErrorHandler);
});
gulp.task('watch', 'Watch files and run tests on change', function() {
gulp.watch('./lib/**/*.js', ['test-watch']);
});
शायद childprocess.exec का उपयोग करें? http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback –
@ ब्रायनग्लज़ यह एक अच्छा विचार है। एकमात्र नकारात्मकता यह है कि जब तक आप कार्य के बिना काम पूरा नहीं कर लेते हैं तब तक आपको प्रक्रिया से आउटपुट नहीं मिलता है। क्या स्टडआउट पर प्रगतिशील आउटपुट प्राप्त करते समय ऐसा करने का कोई तरीका है? –
child_process.spawn() http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options देखें। यह बहुत समान है लेकिन कॉलबैक संलग्न करने के लिए एक इवेंट एमिटर के रूप में कार्य करता है। उदाहरण के लिए लिंक देखें। –