karma-json-fixtures-preprocessor
A Karma plugin to compile JSON files and make them accessible from Javascript code
Last updated 5 years ago by dmitriiabramov .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install karma-json-fixtures-preprocessor 
SYNC missed versions from official npm registry.

karma-json-fixtures-preprocessor

Build Status

Preprocessor for converting .json files into .js files and making them accessible from karma test environment

Installation

{
    "devDependencies": {
        "karma": "~0.12.1",
        "karma-json-fixtures-preprocessor": "0.0.4"
    }
}

Configuration

// karma.conf.js
module.exports = function(config) {
  config.set({
    preprocessors: {
      './fixtures/**/*.json': ['json_fixtures']
    },

    files: [
      './fixtures/**/*.json'
    ],
    jsonFixturesPreprocessor: {
      // strip this from the file path \ fixture name
      stripPrefix: 'test/fixtures',
      // strip this to the file path \ fixture name
      prependPrefix: 'mock/',
      // change the global fixtures variable name
      variableName: '__mocks__',
      // camelize fixture filenames (e.g 'fixtures/aa-bb_cc.json' becames __fixtures__['fixtures/aaBbCc'])
      camelizeFilenames: true,
      // transform the filename
      transformPath: function(path) {
        return path + '.js';
      }
    }
  });
};

How it works

Preprocessor requires .json files and converts them into .js files by storing json data as javascript objects under __fixtures__ namespace.

the following file: ./fixtures/test.json

{
    "a": "test"
}

will be accessible in your test environment:

var fixture = window.__fixtures__['fixtures/test'];
fixture["a"] // => 'test'

Current Tags

  • 0.0.6                                ...           latest (5 years ago)

6 Versions

  • 0.0.6                                ...           5 years ago
  • 0.0.5                                ...           5 years ago
  • 0.0.4                                ...           5 years ago
  • 0.0.3                                ...           5 years ago
  • 0.0.1                                ...           6 years ago
  • 0.0.0                                ...           6 years ago

Copyright 2014 - 2016 © taobao.org |