Skip to content

Commit 725fd84

Browse files
committed
test(storage): fix all storage e2e deprecation warnings
1 parent 98d748b commit 725fd84

File tree

4 files changed

+69
-37
lines changed

4 files changed

+69
-37
lines changed

packages/storage/e2e/StorageReference.e2e.js

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ describe('storage() -> StorageReference', function () {
2121
describe('firebase v8 compatibility', function () {
2222
before(async function () {
2323
await seed(PATH);
24+
25+
// @ts-ignore
26+
globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true;
27+
});
28+
29+
after(async function afterEachTest() {
30+
// @ts-ignore
31+
globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false;
2432
});
2533

2634
describe('toString()', function () {
@@ -671,24 +679,24 @@ describe('storage() -> StorageReference', function () {
671679
});
672680
});
673681
});
674-
});
675682

676-
describe('put secondaryApp', function () {
677-
it('allows valid metadata properties for upload', async function () {
678-
const storageReference = firebase
679-
.storage(firebase.app('secondaryFromNative'))
680-
// .storage()
681-
.ref(`${PATH}/metadataTest.jpeg`);
682-
await storageReference.put(new ArrayBuffer(), {
683-
contentType: 'image/jpg',
684-
md5hash: '123412341234',
685-
cacheControl: 'true',
686-
contentDisposition: 'disposed',
687-
contentEncoding: 'application/octet-stream',
688-
contentLanguage: 'de',
689-
customMetadata: {
690-
customMetadata1: 'metadata1value',
691-
},
683+
describe('put secondaryApp', function () {
684+
it('allows valid metadata properties for upload', async function () {
685+
const storageReference = firebase
686+
.storage(firebase.app('secondaryFromNative'))
687+
// .storage()
688+
.ref(`${PATH}/metadataTest.jpeg`);
689+
await storageReference.put(new ArrayBuffer(), {
690+
contentType: 'image/jpg',
691+
md5hash: '123412341234',
692+
cacheControl: 'true',
693+
contentDisposition: 'disposed',
694+
contentEncoding: 'application/octet-stream',
695+
contentLanguage: 'de',
696+
customMetadata: {
697+
customMetadata1: 'metadata1value',
698+
},
699+
});
692700
});
693701
});
694702
});
@@ -700,8 +708,9 @@ describe('storage() -> StorageReference', function () {
700708
before(async function () {
701709
await seed(PATH);
702710

711+
const { getApp } = modular;
703712
const { getStorage } = storageModular;
704-
secondStorage = getStorage(firebase.app(), secondStorageBucket);
713+
secondStorage = getStorage(getApp(), secondStorageBucket);
705714
});
706715

707716
describe('second storage bucket writes to Storage emulator', function () {
@@ -737,12 +746,12 @@ describe('storage() -> StorageReference', function () {
737746

738747
describe('toString()', function () {
739748
it('returns the correct bucket path to the file', function () {
749+
const { getApp } = modular;
740750
const { getStorage, ref, toString } = storageModular;
741751
const storageReference = ref(getStorage(), `/uploadNope.jpeg`);
742-
const app = firebase.app();
743752

744753
toString(storageReference).should.equal(
745-
`gs://${app.options.storageBucket}/uploadNope.jpeg`,
754+
`gs://${getApp().options.storageBucket}/uploadNope.jpeg`,
746755
);
747756
});
748757
});
@@ -768,10 +777,10 @@ describe('storage() -> StorageReference', function () {
768777

769778
describe('bucket', function () {
770779
it('returns the storage bucket as a string', function () {
780+
const { getApp } = modular;
771781
const { getStorage, ref } = storageModular;
772782
const storageReference = ref(getStorage(), '/foo/uploadNope.jpeg');
773-
const app = firebase.app();
774-
storageReference.bucket.should.equal(app.options.storageBucket);
783+
storageReference.bucket.should.equal(getApp().options.storageBucket);
775784
});
776785
});
777786

@@ -879,14 +888,15 @@ describe('storage() -> StorageReference', function () {
879888

880889
describe('getDownloadURL', function () {
881890
it('should return a download url for a file', async function () {
891+
const { getApp } = modular;
882892
const { getStorage, ref, getDownloadURL } = storageModular;
883893
// This is frequently flaky in CI - but works sometimes. Skipping only in CI for now.
884894
if (!isCI) {
885895
const storageReference = ref(getStorage(), `${PATH}/list/file1.txt`);
886896
const downloadUrl = await getDownloadURL(storageReference);
887897
downloadUrl.should.be.a.String();
888898
downloadUrl.should.containEql('file1.txt');
889-
downloadUrl.should.containEql(firebase.app().options.projectId);
899+
downloadUrl.should.containEql(getApp().options.projectId);
890900
} else {
891901
this.skip();
892902
}
@@ -931,6 +941,7 @@ describe('storage() -> StorageReference', function () {
931941

932942
describe('getMetadata', function () {
933943
it('should return a metadata for a file', async function () {
944+
const { getApp } = modular;
934945
const { getStorage, ref, getMetadata } = storageModular;
935946
const storageReference = ref(getStorage(), `${PATH}/list/file1.txt`);
936947
const metadata = await getMetadata(storageReference);
@@ -950,7 +961,7 @@ describe('storage() -> StorageReference', function () {
950961
metadata.contentEncoding.should.be.a.String();
951962
metadata.contentDisposition.should.be.a.String();
952963
metadata.contentType.should.equal('text/plain');
953-
metadata.bucket.should.equal(`${firebase.app().options.projectId}.appspot.com`);
964+
metadata.bucket.should.equal(`${getApp().options.projectId}.appspot.com`);
954965
metadata.metageneration.should.be.a.String();
955966
metadata.md5Hash.should.be.a.String();
956967
// TODO against cloud storage cacheControl comes back null/undefined by default. Emulator has a difference
@@ -1119,6 +1130,7 @@ describe('storage() -> StorageReference', function () {
11191130

11201131
describe('updateMetadata', function () {
11211132
it('should return the updated metadata for a file', async function () {
1133+
const { getApp } = modular;
11221134
const { getStorage, ref, updateMetadata } = storageModular;
11231135
const storageReference = ref(getStorage(), `${PATH}/list/file1.txt`);
11241136

@@ -1150,7 +1162,7 @@ describe('storage() -> StorageReference', function () {
11501162
metadata.timeCreated.should.be.a.String();
11511163
metadata.metageneration.should.be.a.String();
11521164
metadata.md5Hash.should.be.a.String();
1153-
metadata.bucket.should.equal(`${firebase.app().options.projectId}.appspot.com`);
1165+
metadata.bucket.should.equal(`${getApp().options.projectId}.appspot.com`);
11541166

11551167
// Things we just updated
11561168
metadata.cacheControl.should.equals('cache-control');
@@ -1189,7 +1201,7 @@ describe('storage() -> StorageReference', function () {
11891201
metadata.timeCreated.should.be.a.String();
11901202
metadata.metageneration.should.be.a.String();
11911203
metadata.md5Hash.should.be.a.String();
1192-
metadata.bucket.should.equal(`${firebase.app().options.projectId}.appspot.com`);
1204+
metadata.bucket.should.equal(`${getApp().options.projectId}.appspot.com`);
11931205

11941206
// Things that we may set (or remove)
11951207
should.equal(metadata.cacheControl, undefined);

packages/storage/e2e/StorageTask.e2e.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ describe('storage() -> StorageTask', function () {
3131
describe('firebase v8 compatibility', function () {
3232
before(async function () {
3333
await seed(PATH);
34+
35+
// @ts-ignore
36+
globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true;
37+
});
38+
39+
after(async function afterEachTest() {
40+
// @ts-ignore
41+
globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false;
3442
});
3543

3644
describe('writeToFile()', function () {

packages/storage/e2e/helpers.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ const WRITE_ONLY_NAME = 'writeOnly.jpeg';
88
exports.seed = async function seed(path) {
99
let leakDetectCurrent = globalThis.RNFBDebugInTestLeakDetection;
1010
globalThis.RNFBDebugInTestLeakDetection = false;
11+
const { getStorage, ref } = storageModular;
1112

1213
try {
1314
// Add a write only file
14-
await firebase.storage().ref(WRITE_ONLY_NAME).putString('Write Only');
15+
await ref(getStorage(), WRITE_ONLY_NAME).putString('Write Only');
1516

1617
// Setup list items - Future.wait not working...
17-
await firebase
18-
.storage()
19-
.ref(`${path}/list/file1.txt`)
20-
.putString('File 1', 'raw', { contentType: 'text/plain' });
21-
await firebase.storage().ref(`${path}/list/file2.txt`).putString('File 2');
22-
await firebase.storage().ref(`${path}/list/file3.txt`).putString('File 3');
23-
await firebase.storage().ref(`${path}/list/file4.txt`).putString('File 4');
24-
await firebase.storage().ref(`${path}/list/nested/file5.txt`).putString('File 5');
18+
await ref(getStorage(), `${path}/list/file1.txt`).putString('File 1', 'raw', {
19+
contentType: 'text/plain',
20+
});
21+
await ref(getStorage(), `${path}/list/file2.txt`).putString('File 2');
22+
await ref(getStorage(), `${path}/list/file3.txt`).putString('File 3');
23+
await ref(getStorage(), `${path}/list/file4.txt`).putString('File 4');
24+
await ref(getStorage(), `${path}/list/nested/file5.txt`).putString('File 5');
2525
} catch (e) {
2626
// eslint-disable-next-line no-console
2727
console.error('unable to seed storage service with test fixtures');
@@ -32,7 +32,8 @@ exports.seed = async function seed(path) {
3232
};
3333

3434
exports.wipe = function wipe(path) {
35-
return firebase.storage().ref(path).remove();
35+
const { getStorage, ref } = storageModular;
36+
return ref(getStorage(), path).remove();
3637
};
3738

3839
exports.PATH = PATH;

packages/storage/e2e/storage.e2e.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ const { PATH } = require('./helpers');
1818

1919
describe('storage() modular', function () {
2020
describe('firebase v8 compatibility', function () {
21+
beforeEach(async function beforeEachTest() {
22+
// @ts-ignore
23+
globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true;
24+
});
25+
26+
afterEach(async function afterEachTest() {
27+
// @ts-ignore
28+
globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false;
29+
});
30+
2131
describe('storage()', function () {
2232
describe('namespace', function () {
2333
it('accessible from firebase.app()', function () {
@@ -241,9 +251,10 @@ describe('storage() modular', function () {
241251
describe('modular', function () {
242252
describe('getStorage', function () {
243253
it('pass app as argument', function () {
254+
const { getApp } = modular;
244255
const { getStorage } = storageModular;
245256

246-
const storage = getStorage(firebase.app());
257+
const storage = getStorage(getApp());
247258

248259
storage.constructor.name.should.be.equal('FirebaseStorageModule');
249260
});

0 commit comments

Comments
 (0)