node.js - Mocking file system contents not working with gulp.src -
i'm trying use mock-fs mock file system contents test gulp tasks. unfortunately, gulp.src
doesn't seem play mock-fs
. specifically, enoent errors:
message: enoent, lstat '/vagrant/study-node-heroku/instances/development/app.json' details: errno: -2 code: enoent path: /vagrant/study-node-heroku/instances/development/app.json domainemitter: [object object] domain: [object object] domainthrown: false stack: error: enoent, lstat '/vagrant/study-node-heroku/instances/development/app.json' @ error (native)
other parts of code , test code access mock-fs
-created files fine.
what doing wrong? suspect problem related gulp's usage of vinyl.
here function under test:
var herokutarball = function(options, done) { var instance = options.instance || 'development'; var tarballname = options.tarballname || instance var tarballpath = path.join(config.temp, tarballname + '.tar.gz'); var files = path.join(config.instances, instance, '**/*'); yassert.file(path.join(config.instances, instance, 'app.json')); async.waterfall([ function(cb) { del([tarballpath], cb); }, function(err, cb) { gulp.src(files) .pipe(tar(tarballname + '.tar')) .pipe(gzip()) .pipe(gulp.dest(config.temp)) .pipe(gcallback(cb)); } ], function(err, result) { if (err) return err; return done(err, tarballpath); }); }
and here test snippet:
describe('gulp heroku:tarball', function() { after('something', function() { mock.restore(); }); before('something', function() { mock({ 'instances/development': { 'app.json': 'test content' } }); }); it('creates tarball', function(done) { var options = {} heroku.herokutarball(options, function(err, result) { expect(result).to.be.a('string'); yassert.file(result); done(); }); }); });
notice yassert (yeoman-assert) calls pass fine -- file there. if take function gulp.src call out of async waterfall, error goes away (and test fails of course).
issue posted @ https://github.com/tschaub/mock-fs/issues/44
you not doing wrong, mock-fs readme states:
note mock-fs not compatible graceful-fs@3.x works graceful-fs@4.x.
looking @ dependencies of gulp get:
$ npm info gulp devdependencies.graceful-fs ^3.0.0
hence, gulp still dependent on graceful-fs@3.x, therefore mock-fs not work.
ymmv, maybe vinyl-fs-mock alternative?
Comments
Post a Comment