Grunt and hood.ie test database

263 views Asked by At

I'm currently running my test suite on AngularJS using Grunt, Karma, Jasmine and Protractor. The database library I'm using is hood.ie, which is a library on top of CouchDB. I start hood.ie using the following code in my Gruntfile:

hoodie: {
  start: {
    options: {
      callback: function(config) {
        grunt.config.set('connect.proxies.0.port', config.stack.couch.port);
      }
    }
  }
},

However, I would like to have a separate database for running tests, which automatically resets afterwards. This way, the production data won't conflict with the tests.

How should I approach this? I would assume there's some kind of standard way of doing this, as I can imagine other people have come across the same problem, but I'm unable to find anything on the internet.

2

There are 2 answers

0
Vliegenthart On BEST ANSWER

Currently, this seems to be impossible as the hoodie server does not support it. The best way to go about this is to modify it yourself at Hood.ie server Github repository by adding a parameter to define the folder in which the data will be stored, which is at the moment hardcoded to 'data' (https://github.com/hoodiehq/hoodie-server/blob/master/lib/core/environment.js#L48)

Something similar to this should work:

app_path: path.resolve(project_dir, argv.folder || 'data')
2
muffinresearch On

As the hoodie task is a 'multitask' you could have a test target in your hood.ie grunt task specific to testing, and then reference this in a grunt command used to run tests e.g:

hoodie: {
  start: {
    options: {
      callback: function(config) {
        grunt.config.set('connect.proxies.0.port', config.stack.couch.port);
      }
    }
  },
  test: {
    options: {
      callback: function(config) {
        // Make test specific changes here.
      }
    }
  }
}

// The task that runs tests first starting test deps. 'runtests' can be anything you want.
grunt.registerTask('test', 'Run unit tests', ['hoodie:test', 'runtests']);

Note: this will mean any other times you're referencing the hoodie task you'll need to be explicit as otherwise all the specified targets will be run. See this documentation on multitasks for more info. In this example you'd change hoodie to hoodie:start to run the 'start' task as previously defined.