vinyl-fs-fake
A vinyl adapter that extends vinyl-fs to allow for easy debugging by passing in virtual files instead of globs, and calling a function instead of writing to file.
Install
$ npm install vinyl-fs-fake
Usage
Say you have the following gulpfile:
var gulp = ;var plugins = ; var options = JS_SRC: 'assets/js/*.js' JS_DEST: 'dest'; gulp;
If you were using vinyl-fs-fake instead of vinyl-fs, you could test your task
simply by changing the value of the options
object:
var gulp = ;var vfsFake = ;var plugins = ; var options = JS_SRC: 'assets/js/*.js' JS_DEST: 'dest'; gulp;
Then, you can replace the options object:
var options = JS_SRC: path: 'test.js' contents: '...' path: 'test2.js' contents: '...' { assert; assert; };
As it's just a wrapper around vinyl-fs, you can pretty much drop it straight into your code and it will work without needing any actual thinking. Then, when you're ready, you can write tests for your gulp tasks.
This is pretty much only useful if you split your gulpfile into multiple files.
vfsFake.src
If you pass in a glob or an array of globs, it will be given to the src method of vinyl-fs and returned. Basically, it doesn't change that behaviour.
If you pass in an object representing a file, it'll be turned into a vinyl object and piped down the stream. You can also give it a vinyl object directly, or an array of objects or vinyl objects.
In addition to the options accepted by the Vinyl file constructor, you can pass the file content as a string, in which case it will be bufferized for you.
vfsFake.dest
If you pass in a path, it will be given to the dest method of vinyl-fs and returned; again, it doesn't change that behaviour.
However, you can now pass in a function which will be given a files
array,
containing all the files piped through:
...
It won't touch the files, so you can carry on piping that to other stuff.
You can also give it a stream, if you really want. It'll act like
vfsFake.dest
just wasn't called at all, and the stream was just given to
.pipe()
directly.
License
Released under the MIT license.