1.0.0 • Published 7 years ago

karma-graphql-preprocessor v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

karma-graphql-preprocessor

Build Status

Preprocessor for converting GraphQL files into valid GraphQL queries.

Note: If you are using AngularJS, check out karma-ng-html2js-preprocessor.

Installation

The easiest way is to keep karma-html2js-preprocessor as a devDependency in your package.json.

{
  "devDependencies": {
    "karma": "~1.7.0",
    "karma-graphql-preprocessor": "~1.0.0"
  }
}

You can simple do it by:

npm install karma-graphql-preprocessor --save-dev

or

yarn add karma-graphql-preprocessor --dev

Configuration

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

    files: [
      '*.js',
      '*.gql'
    ],

  });
};

How does it work ?

This preprocessor converts HTML files into JS strings and publishes them in the global window.__html__, so that you can use these for testing DOM operations.

For instance this template.html...

<div>something</div>

... will be served as template.html.js:

window.__html__ = window.__html__ || {};
window.__html__['template.html'] = '<div>something</div>';

See the end2end test for a complete example.


For more information on Karma see the homepage.