grunt-fixtures2js
Ever wondered how to access static text-based files (e.g. JSON, HTML) from your tests? grunt-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 grunt-fixtures2js via npm:
$ npm install --save-dev grunt-fixtures2js
Usage
You can configure your fixtures2js tasks as follows:
fixtures2js: default: files: "my-fixture-file.js": "fixtures/*"
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.
Examples
If you have a configuration like this:
fixtures2js: default: options: head: "processFixtures(" tail: ");" postProcessors: "**/*.json": "json" files: "my-fixture-file.js": "fixtures/*"
Running grunt fixtures2js:default
will read the contents of the files in the fixtures/
folder, and generate a my-fixture-file.js
like this:
;