Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions test/unit/storage/storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
})
});