mdasberg / ng-apimock

Node plugin that provides the ability to use scenario based api mocking: for local development for protractor testing
MIT License
99 stars 26 forks source link

[WIP]Feature: Re-usability of mocks via JS #80

Closed mstelz closed 4 years ago

mstelz commented 4 years ago

Note: Not done implementing but before I go further with this I wanted to see what people's thoughts on this pattern was.

Problem Statement: So while using this framework for mocks I came across the problem that I have many data-sets with minimal change between scenarios maybe only testing a new field or flag for example. This caused a lot of copy pasting, or redundant code to be necessary while creating new scenarios.

Potential Solution: Provide users the ability to utilize exports / imports to reuse parts of their scenarios that may be shared by allowing for the creation of mocks in Javascript as well as JSON.

The idea behind this is simple in that a user would be able to create some part of their response and then just import that section (such as an array of groceries) into their other scenarios, while only changing the single things they wanted. This is extremely expandable if people were to use the spread operator ... and then just override specific values they were interested in changing.

This PR was me spending all of 10 minutes just hacking something together to see the feasibility of it. I was able to get it to successfully read the JS files and include them as mocks. I need to clean this up entirely so I do not intend for this PR to be improved but I wanted feedback as to the idea or feature before I spend more time on it (as they say time is money).

Also should this be something in @ng-apimock/core?