gulp-fixtures2js
Ever wondered how to access static text-based files (e.g. JSON, HTML) from your tests? gulp-fixtures2js makes things easier for you by creating a JS file out of your fixtures, containing an object where file contents mapped to their filenames. You can then just include that file in your tests and voilá!
Installation
You can install gulp-fixtures2js via npm:
$ npm install --save-dev gulp-fixtures2js
Usage
Include the plugin:
var fixtures2js = ;
This will give you a function that takes the destination filename as its first argument, and options as an optional second argument.
Options
head
(defaults towindow.FIXTURES =
) a string to insert before the generated JSON.tail
(defaults to;
) a string to insert after the generated JSON.postProcessors
(defaults to{}
) a string to string object where keys areminimatch
patterns and values are one ofdefault
,json
,base64
orbytearray
. If a file is not matched by any pattern,default
is used.relativeTo
(defaults to.
) a string file path to base the filenames to (so that you don't get the complete paths as your keys).
Examples
gulp;
This will read the contents of files in ./fixtures/
, and create something like the following ./my-fixture-file.js
:
windowFIXTURES = "myfile.txt": "contents of the file" "myotherfile.txt": "contents of the file";
I grok all the options!
gulp;
Which will generate the following result:
;