UNPKG

jest-firestore

Version:

Run your tests using Jest & Firestore Emulator

26 lines (22 loc) 1.13 kB
"use strict"; var _helpers = require("./helpers"); var _emulator = require("./emulator"); const debug = require('debug')('jest-firestore:setup'); module.exports = async config => { const options = (0, _helpers.getFirestoreEmulatorOptions)(config.rootDir); const _shouldUseSharedDBForAllJestWorkers = (0, _helpers.shouldUseSharedDBForAllJestWorkers)(config.rootDir); debug(`shouldUseSharedDBForAllJestWorkers: ${_shouldUseSharedDBForAllJestWorkers}`); // this one is controversial, might override what user really wants, let's see process.env.GCLOUD_PROJECT = options.project_id; // if we have FIRESTORE_EMULATOR_HOST already passed from env, bypass starting emulator if (process.env.FIRESTORE_EMULATOR_HOST) { debug(`FIRESTORE_EMULATOR_HOST is set to ${process.env.FIRESTORE_EMULATOR_HOST}, bypassing emulator start`); return; } // if we run one emulator instance for all tests if (_shouldUseSharedDBForAllJestWorkers) { debug(`Starting Firestore Emulator`); process.env['FIRESTORE_EMULATOR_HOST'] = await (0, _emulator.startEmulator)(options); global.__isEmulatorStarted = true; } };