Tools to manage fixtures during app development for Cozy


Manage easily the data fixtures for your Cozy developments!


Please note that the "load" process do the following:

  • removing all the data for the concerned doctypes
  • adding the fixtures for the concerned doctypes

The "concerned doctypes" are the ones found in the fixture files or the ones you gaves through parameters.

When you develop an application you might want to feed the Data System with data.

npm install -g cozy-fixtures
cozy-fixtures load # will load all the fixtures inside ./tests/fixtures/
cozy-fixtures load ./fixtures/ # you can specify a folder
cozy-fixtures load ./fixtures/my-super-fixtures.json # or a file
cozy-fixtures load -d contact # only load the documents for a specified doctype
cozy-fixtures load -s # run the script quietly
cozy-fixutres -l load # doesn't remove documents before loading

You can use cozy-fixtures programatically to ease automatic testing:

  • First, add it to your dev dependencies:
npm install cozy-fixtures --save-dev
  • Then use it where you need it
fixtures = require 'cozy-fixtures'
    dirPath: 'path/to/fixtures' # default is './tests/fixtures/' 
    doctypeTarget: 'doctypeName' # default is null 
    silent: true # default is false 
    removeBeforeLoad: false # default is true. Remove docs for concerned doctypes before loading the data 
    callback: yourCallback # default is null 

You can also do more precise action like:

  • deleting all the documents for a specified doctype
fixtures = require 'cozy-fixtures'
fixtures.removeDocs "doctypeName"(err) ->
    console.log err if err?
  • deleting all the documents from the database
fixtures = require 'cozy-fixtures'
        callback: (err) -> console.log err if err?
        designsToRemove: true # default is false, removes all the design docs in the database (and related) views 

If you want to have the same configuration for every call, use the setDefaultValues method:

fixtures = require 'cozy-fixtures'
            target: './a/custom/target.json'
            silent: true
            removeBeforeLoad: false
fixtures.load callback: (err) -> console.log "fixtures loaded !"

You can still override the defautl values by passing the arguments to the load function.

How to format the fixtures

  • You must put the fixtures into files
  • Fixtures must be described in valid JSON
  • Don't forget the "docType" field in the fixtures

A simple example:

        "docType": "Alarm",
        "action": "DISPLAY",
        "trigg": "Tue Jul 02 2013 16:00:00",
        "description": "Réunion review scopyleft",
        "related": null
        "docType": "Contact",
        "fn": "John Doe",
        "datapoints": [
                "name": "about",
                "type": "birthday",
                "value": "02/02/1980",
                "id": 1
                "name": "tel",
                "type": "main",
                "value": "+33 12 34 56 78",
                "id": 2
        "note": "Données complémentaires sur le contact."
        "_id": "2",
        "docType": "File",
        "_attachments": "tests/fixtures/files/fixtures.json",
        "class": "document",
        "lastModification": "Thu Oct 17 2013 08:29:21 GMT+0200 (CEST)",
        "name": "fixtures.json",
        "path": "",
        "size": 2413

Note that you can add files as attachments. In order to achieve this, add a "_attachments" field to your fixture and put the path relatively to where you run the command.

Cozy is a platform that brings all your web services in the same private space. With it, your web apps and your devices can share data easily, providing you with a new experience. You can install Cozy on your own hardware where no one profiles you.

You can reach the Cozy Community by:

  • Chatting with us on IRC #cozycloud on
  • Posting on our Forum
  • Posting issues on the Github repos
  • Mentioning us on Twitter