Development
Mocking & Emulator

Mocking Data & using Emulators

Mock API using MSW

Song Turbo uses MSW to intercept api network requests before reaching the real API and instead return static json. This works only on the DPC Next application since its web only technology. It does work both for server side and browser side requests.

To enable MSW there is a env variable in the DPC Next application folder called NEXT_PUBLIC_API_MOCKING_ENABLED. This should be set to 1 to enable mocking.

MSW also needs to enabled on a API level. This is done in the file /packages/core/api-mocks/src/handlers.ts

The requests intercepted and the data returned is defined in each APIs mock package files. For example /packages/addons/sanity-mocks/src/navigation/handlers.ts defines what should be returned for the footer links API in Sanity.


Firebase emulator

The Firebase Local Emulator is a set of advanced tools for building and testing our app locally. To start the emulator there is a script called:

yarn start:fb-emulator

Emulator UI should be available at http://localhost:4000 (opens in a new tab)

The emulator can be used by the 'firestore' and 'firebase-auth' packages. To enable usage there is a flag in the 'dev' script in each package.json. The values of the flags should be set to 1 to use the emulator.

Be sure to turn of mocking (in the core/api-mocks package) for the package if you'd like to use the emulator. Otherwise the requests to the emulator would be intercepted by MSW and not reach the emulator.

For instruction on how to install the emulator please see (https://firebase.google.com/docs/emulator-suite/install_and_configure (opens in a new tab))