# Mockoon Config Transforming

Mockoon stores its configuration in a single JSON file (in our case, mock.json). Some lines in this file can become very long (99500 bytes has been observed). This makes it very hard to resolve git merge conflicts if any occur in such a line.

The Mockoon team is not yet planning on changing this file format (opens new window).

In order to mitigate these conflicts, the tool mockoon-config-transformer (opens new window) was developed.

As the frontend development team, we have decided to start using it.

# Mechanism

The mockoon-config-transformer has two modes of action:

  • extract: This extracts the mock.json file into a hierarchy of smaller files under the mock/ subdirectory.
  • bundle: This bundles the files in the mock/ directory to a new mock.json file.

The advantage of extracting the large mock.json into smaller files is that it becomes much easier to resolve git merge conflicts.

# Usage

The two modes of action can be invoked with the following commands:

  • yarn mock:extract
  • yarn mock:bundle

# How to

We want to keep the mock.json file and mock/ subdirectory in sync, in other words: each commit should have a mock/ subdirectory that contains the exact same configuration as its mock.json file.

In order to achieve this, we need to do the following:

# Before committing a change in mock.json

  • Run yarn mock:extract
  • Add these files to the commit: git add mock

# After resolving a merge conflict involving any of the mock files

  • Run yarn mock:bundle
  • Add the new JSON file to the commit: git add mock.json