npm

grunt-fixtures2js

0.1.3 • Public • Published

grunt-fixtures2js

Build Status

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 to window.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 are minimatch patterns and values are one of default, json, base64 or bytearray. 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:

processFixtures({
    "fixtures/one-fixture-file.txt": "The contents of the fixture file here",
    "fixtures/other-fixture-file.txt": "The contents of another fixture file here",
    "fixtures/stuff.json": {
        "foo": "bar"
    }
});

Dependencies (1)

Dev Dependencies (4)

Package Sidebar

Install

npm i grunt-fixtures2js

Weekly Downloads

1

Version

0.1.3

License

ISC

Last publish

Collaborators

  • jussi-kalliokoski