Skip to content

jussi-kalliokoski/grunt-fixtures2js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"
    }
});

About

Convert your fixtures into a JS object for use in tests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published