Previously, the latest commit for branch may be computed multiple times in the `deploy-to-firebase.js` tests. This commit avoids the unnecessary re-computations by computing the latest commits for the necessary branches at the beginning and using the computed values throughout the tests. PR Close #39853