diff --git a/src/storage/storage.ts b/src/storage/storage.ts index 4364658a8c..aabf9dd30b 100644 --- a/src/storage/storage.ts +++ b/src/storage/storage.ts @@ -48,6 +48,10 @@ export class Storage implements StorageInterface { }); } + if (!process.env.STORAGE_EMULATOR_HOST && process.env.FIREBASE_STORAGE_EMULATOR_HOST) { + process.env.STORAGE_EMULATOR_HOST = process.env.FIREBASE_STORAGE_EMULATOR_HOST; + } + let storage: typeof StorageClient; try { storage = require('@google-cloud/storage').Storage; diff --git a/test/unit/storage/storage.spec.ts b/test/unit/storage/storage.spec.ts index 997d44846e..69ea28b217 100644 --- a/test/unit/storage/storage.spec.ts +++ b/test/unit/storage/storage.spec.ts @@ -113,4 +113,24 @@ describe('Storage', () => { expect(storage.bucket('foo').name).to.equal('foo'); }); }); + + describe('Emulator mode', () => { + const EMULATOR_HOST = 'http://localhost:9199'; + + before(() => { + delete process.env.STORAGE_EMULATOR_HOST; + process.env.FIREBASE_STORAGE_EMULATOR_HOST = EMULATOR_HOST; + }); + + it('sets STORAGE_EMULATOR_HOST if FIREBASE_STORAGE_EMULATOR_HOST is set', () => { + new Storage(mockApp); + + expect(process.env.STORAGE_EMULATOR_HOST).to.equal(EMULATOR_HOST); + }); + + after(() => { + delete process.env.STORAGE_EMULATOR_HOST; + delete process.env.FIREBASE_STORAGE_EMULATOR_HOST; + }); + }) });