Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: bump e2e test runner to React Native 0.74.1 #7985

Merged
merged 20 commits into from
Sep 2, 2024
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
1,197 changes: 597 additions & 600 deletions packages/storage/e2e/StorageReference.e2e.js

Large diffs are not rendered by default.

54 changes: 33 additions & 21 deletions packages/storage/lib/web/RNFBStorageModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,48 @@ const storageInstances = {};
const tasks = {};

function getBucketFromUrl(url) {
const pathWithBucketName = url.substring(5);
const bucket = url.substring(0, pathWithBucketName.indexOf('/') + 5);
return bucket;
// Check if the URL starts with "gs://"
if (url.startsWith('gs://')) {
// Return the bucket name by extracting everything up to the first slash after "gs://"
// and removing the "gs://" prefix
return url.substring(5).split('/')[0];
} else {
// Assume the URL is a path format, strip the leading slash if it exists and extract the bucket name
const strippedUrl = url.startsWith('/') ? url.substring(1) : url;
// Extract the bucket from the path, assuming it ends at the first slash after the domain
return strippedUrl.split('/')[0];
}
}

function getCachedAppInstance(appName) {
return (appInstances[appName] ??= getApp(appName));
}

function emulatorKey(appName, url) {
const bucket = getBucketFromUrl(url);
return `${appName}|${bucket}`;
}

// Returns a cached Storage instance.
function getCachedStorageInstance(appName, url) {
let instance;
const bucket = url ? getBucketFromUrl(url) : getCachedAppInstance(appName).options.storageBucket;

if (!url) {
instance = getCachedStorageInstance(
appName,
getCachedAppInstance(appName).options.storageBucket,
);
} else {
const bucket = getBucketFromUrl(url);
instance = storageInstances[`${appName}|${bucket}`] ??= getStorage(
getCachedAppInstance(appName),
bucket,
);
}
if (emulatorForApp[appName]) {
connectStorageEmulator(instance, emulatorForApp[appName].host, emulatorForApp[appName].port);

const key = emulatorKey(appName, bucket);
if (emulatorForApp[key]) {
connectStorageEmulator(instance, emulatorForApp[key].host, emulatorForApp[key].port);
}
return instance;
}
Expand Down Expand Up @@ -296,11 +312,12 @@ export default {
* @param {number} port - The emulator port.
* @return {Promise<void>}
*/
useEmulator(appName, host, port) {
useEmulator(appName, host, port, url) {
return guard(async () => {
const instance = getCachedStorageInstance(appName);
const instance = getCachedStorageInstance(appName, url);
connectStorageEmulator(instance, host, port);
emulatorForApp[appName] = { host, port };
const key = emulatorKey(appName, url);
emulatorForApp[key] = { host, port };
});
},

Expand All @@ -324,28 +341,23 @@ export default {
putString(appName, url, string, format, metadata = {}, taskId) {
return guard(async () => {
const ref = getReferenceFromUrl(appName, url);
let decodedString = null;

let base64String = null;

// This is always either base64 or base64url
switch (format) {
case 'base64':
base64String = Base64.atob(string);
decodedString = Base64.atob(string);
break;
case 'base64url':
base64String = Base64.atob(string.replace(/_/g, '/').replace(/-/g, '+'));
decodedString = Base64.atob(string.replace(/_/g, '/').replace(/-/g, '+'));
break;
}

const byteArray = new Uint8Array(base64String ? base64String.length : 0);
const encoder = new TextEncoder();

if (base64String) {
for (let i = 0; i < base64String.length; i++) {
byteArray[i] = base64String.charCodeAt(i);
}
}
const arrayBuffer = encoder.encode(decodedString).buffer;

// Start a resumable upload task.
const task = uploadBytesResumable(ref, byteArray, {
const task = uploadBytesResumable(ref, arrayBuffer, {
...makeSettableMetadata(metadata),
md5Hash: metadata.md5Hash,
});
Expand Down
17 changes: 16 additions & 1 deletion tests/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,22 @@ function loadTests(_) {
}
if (platformSupportedModules.includes('storage')) {
const storageTests = require.context('../packages/storage/e2e', true, /\.e2e\.js$/);
storageTests.keys().forEach(storageTests);

if (Platform.other && global.isCI) {
// Skip StorageReference & StorageTask tests on CI for "other" platforms
// uploadBytesResumable is pretty flaky. Crashes macOS app.
// See: https://github.com/facebook/react-native/issues/32784
// and: https://github.com/firebase/firebase-js-sdk/issues/5848
const filteredTests = storageTests.keys().filter(test => {
if (test.includes('StorageReference.e2e') || test.includes('StorageTask.e2e')) {
return false;
}
return true;
});
filteredTests.forEach(storageTests);
} else {
storageTests.keys().forEach(storageTests);
}
}
});
}
Expand Down
Loading
Loading