grunt-ngmock

1.0.7 • Public • Published

grunt-ngmock v1.0.7

Concatenates mocked data spanned across multiple json files and generates an angular service.

Getting Started

This plugin requires Grunt >=0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-ngmock --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-ngmock');

ng-mock task

Task targets, files specified according to the Grunt Configuring tasks guide.

concatenates angular mocked json files and generate an angular service;

Usage Examples

Set up your project with multiple data mocks/json, one for each API as shown below and a config that tells which json file should be server for each API call. It just needs config and json files and the rest is taken care automatically.

// mocked data for profiles API.
app/E2EMocks/mock-data/profiles.mock.json
[
 {..},{..}
]
//mocked data for assets API.
app/E2EMocks/mock-data/assets.mock.json
[
 {..},{..}
]
app/E2EMocks/config.json
{
    "get":{
      "/profiles: "profiles.mock.json"
    },
    "post":{
	  "/assests": "assets.mock.json"
    },
    "passthru": ["/templates\.*/"]
}

Include ngmock tasks to your grunt file and run it.

// Project configuration.
grunt.initConfig({
    json: {
        src: [
           "app/E2EMocks/mock-data/**/*.json"
        ],
        dest: 'dist/data-mocks.js'
    }
  },
});

Now the task concatenates all the json files and generates an angular service as below. Apart from this, it generates an E2EMock module that handles all the http/API requests.

(function(){ 
  'use strict';
 angular.module('E2EMocks').service('E2EMocksService', function(){  
	var mocks = {}; 
	mocks['config'] = {..};
	mocks['profiles_json'] =[...]; 
	mocks['assets_json'] =[...];
	return mocks; 
 }) })();

Each API request is served from the mocked data.

Source code: https://github.com/nasangam/grunt-tasks

Sample App: https://github.com/nasangam/ngmock-demos/

Release History

  • 2015-08-2015 first release

Task submitted by Nagaraju Sangam;

Package Sidebar

Install

npm i grunt-ngmock

Weekly Downloads

1

Version

1.0.7

License

none

Last publish

Collaborators

  • nagaraju_sangam