Skip to content

Commit a9a89ed

Browse files
abeisgoatssbushi
authored andcommitted
Add support for FIREBASE_STORAGE_EMULATOR_HOST env var (#1175)
* Add support for FIREBASE_STORAGE_EMULATOR_HOST env var * Fixes lint error * Add test for FIREBASE_STORAGE_EMULATOR_HOST support * Lint fix * Minor fixes to storage tests * Address review comments * Address review suggestion Co-authored-by: Samuel Bushi <[email protected]>
1 parent 0e7d7e8 commit a9a89ed

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/storage/storage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export class Storage implements StorageInterface {
4848
});
4949
}
5050

51+
if (!process.env.STORAGE_EMULATOR_HOST && process.env.FIREBASE_STORAGE_EMULATOR_HOST) {
52+
process.env.STORAGE_EMULATOR_HOST = process.env.FIREBASE_STORAGE_EMULATOR_HOST;
53+
}
54+
5155
let storage: typeof StorageClient;
5256
try {
5357
storage = require('@google-cloud/storage').Storage;

test/unit/storage/storage.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,24 @@ describe('Storage', () => {
113113
expect(storage.bucket('foo').name).to.equal('foo');
114114
});
115115
});
116+
117+
describe('Emulator mode', () => {
118+
const EMULATOR_HOST = 'http://localhost:9199';
119+
120+
before(() => {
121+
delete process.env.STORAGE_EMULATOR_HOST;
122+
process.env.FIREBASE_STORAGE_EMULATOR_HOST = EMULATOR_HOST;
123+
});
124+
125+
it('sets STORAGE_EMULATOR_HOST if FIREBASE_STORAGE_EMULATOR_HOST is set', () => {
126+
new Storage(mockApp);
127+
128+
expect(process.env.STORAGE_EMULATOR_HOST).to.equal(EMULATOR_HOST);
129+
});
130+
131+
after(() => {
132+
delete process.env.STORAGE_EMULATOR_HOST;
133+
delete process.env.FIREBASE_STORAGE_EMULATOR_HOST;
134+
});
135+
})
116136
});

0 commit comments

Comments
 (0)