I have an abstraction of an adapter. Through an environmeht variable I control which implementation is used. I am not satisfied with this approach, since the mock variant is imported in production code. I would like to have something like in Symfony, where implementation of abstractions can be defined in environmental service configurations.
Currently I have following abstraction:
import HttpERPAdapter from "./HttpERPAdapter";
import MockERPAdapter from "./MockERPAdapter"; // todo, find an abstraction solution to not deploy this in production
import httpClient from "common/HttpClient";
const create = () => {
if (process.env.REACT_APP_ERP_API_URL === 'mock') {
return new MockERPAdapter();
}
return new HttpERPAdapter(httpClient);
}
const erpAdapter = create();
export default erpAdapter;
I am sure that a compilation in a production build will contain the mock class, this is also what I want to prevent.
In general I want that the productive code knows nothing about mocks/fake-services.
Any ideas on how to separate the mock implementation from the productive code?