# gulp-fixtures2js

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

Latest version **0.0.1** (published 2014-05-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install gulp-fixtures2js
pnpm add gulp-fixtures2js
yarn add gulp-fixtures2js
bun add gulp-fixtures2js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2014-05-27 |
| First published | 2014-04-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jussi Kalliokoski |
| Maintainers | jussi-kalliokoski |
| Keywords | gulpplugin, fixture, testing |

## Links

- npm: https://www.npmjs.com/package/gulp-fixtures2js
- Repository: https://github.com/jussi-kalliokoski/gulp-fixtures2js
- Issues: https://github.com/jussi-kalliokoski/gulp-fixtures2js/issues
- npm.io page: https://npm.io/package/gulp-fixtures2js

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [through](https://npm.io/package/through.md) ^2.3.4
- [gulp-util](https://npm.io/package/gulp-util.md) ^2.2.14
- [fixtures2js](https://npm.io/package/fixtures2js.md) 0.0.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2014-05-27
- 0.0.0 — 2014-04-03

## README

# gulp-fixtures2js

[![Build Status](https://travis-ci.org/jussi-kalliokoski/gulp-fixtures2js.svg?branch=master)](https://travis-ci.org/jussi-kalliokoski/gulp-fixtures2js)
[![Coverage Status](https://img.shields.io/coveralls/jussi-kalliokoski/gulp-fixtures2js.svg)](https://coveralls.io/r/jussi-kalliokoski/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:

```bash
$ npm install --save-dev gulp-fixtures2js
```

## Usage

Include the plugin:

```javascript
var fixtures2js = require("gulp-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 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.
* `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

```javascript
gulp.task("fixtures", function () {
    return gulp.src("./fixtures/*")
        .pipe(fixtures2js("my-fixture-file.js"))
        .pipe(gulp.dest("./"))
});
```

This will read the contents of files in `./fixtures/`, and create something like the following `./my-fixture-file.js`:

```javascript
window.FIXTURES = {
    "myfile.txt": "contents of the file",
    "myotherfile.txt": "contents of the file"
};
```

### I grok **all** the options!

```javascript
gulp.task("fixtures", function () {
    return gulp.src("./fixtures/*")
        .pipe(fixtures2js("my-fixture-file.js", {
            relativeTo: "./fixtures",
            head: "processFixtures(",
            tail: ");",
            postProcessors: {
                "**/*.json": "json"
            }
        }))
        .pipe(gulp.dest("./"))
});
```

Which will generate the following result:

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

---
_Source: https://npm.io/package/gulp-fixtures2js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
