Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use gulp with tape?

I'm trying to integrate Gulp with Tape (https://github.com/substack/tape), the NodeJs test harness.

How can I do this? There doesn't seem to be an existing gulp plugin.

I've see this, but it looks really inelegant:

var shell = require('gulp-shell')

gulp.task('exec-tests', shell.task([
  'tape test/* | faucet',
]));

gulp.task('autotest', ['exec-tests'], function() {
  gulp.watch(['app/**/*.js', 'test/**/*.js'], ['exec-tests']);
});

I've tried this, which looks like it should work:

var tape = require('tape');
var spec = require('tap-spec');


gulp.task('test', function() {
    return gulp.src(paths.serverTests, {
            read: false
        })
        .pipe(tape.createStream())
        .pipe(spec())
        .pipe(process.stdout);
});

but I get a TypeError: Invalid non-string/buffer chunk error

like image 763
Joseph Avatar asked Mar 17 '23 23:03

Joseph


2 Answers

Your "inelegant" answer is the best one. Not every problem can be best solved with streams, and using gulp just as a wrapper is not a sin.

like image 71
gotofritz Avatar answered Mar 29 '23 05:03

gotofritz


Right, your task won't work because gulp streams are based on vinyl, a virtual file abstraction. I don't really think there's a good way of handling this in gulp, it seems like you should be using the tape API directly. I mean, you could put some gulp task sugar around it if you wish:

var test = require('tape');
var spec = require('tap-spec');
var path = require('path');
var gulp = require('gulp');
var glob = require('glob');

gulp.task('default', function () {
    var stream = test.createStream()
        .pipe(spec())
        .pipe(process.stdout);

    glob.sync('path/to/tests/**/*.js').forEach(function (file) {
        require(path.resolve(file));
    });

    return stream;
});

Seems kind of messy to me; not only because we're not using any of gulp's streaming abstractions, but we're not even putting it into a way that could hook into a gulp pipeline afterwards. Furthermore, you can't get gulp's task finished message when using this code either. If anyone knows a way around that then, please, be my guest. :-)

I think I would prefer to use tape on the command line. But, if you want all of your build step tasks in your gulpfile this might be the route to go.

like image 24
Ben Avatar answered Mar 29 '23 06:03

Ben