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

Storage Emulator support in rules-unit-testing #4863

Merged
merged 11 commits into from
May 6, 2021
Merged

Conversation

samtstern
Copy link
Contributor

@samtstern samtstern commented May 4, 2021

Discussion

Adds support for Storage emulator to the rules-unit-testing library.

TODO:

Nice to have:

Testing

See unit tests. Currently we have the following failures, so we have to skip a test in CI:

  1) Testing Module Tests
       initializeAdminApp() has admin access to storage:
     Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
      at GoogleAuth.getApplicationDefaultAsync (/home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/google-auth-library/build/src/auth/googleauth.js:173:19

(1) is a known issue with Storage not being able to work without credentials even when using the emulator. @abeisgoat or @hiranya911 do you know of any way to fix this without adding service account credentials to the JS SDK test environment?

API Changes

initializeAdminApp() has always been returning a firebase.app.App type from the client SDK but that has not been correct for a few releases! So I did change the type which is an API change, but it's to fix a bug.

@changeset-bot
Copy link

changeset-bot bot commented May 4, 2021

🦋 Changeset detected

Latest commit: 9a885a5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@firebase/rules-unit-testing Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 2021

Changeset File Check ⚠️

  • Package @firebase/rules-unit-testing has a minor bump which requires an additional line to bump the main "firebase" package to minor.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 4, 2021

Binary Size Report

Affected SDKs

  • @firebase/analytics

    Type Base (d095ad3) Head (3939af1) Diff
    esm2017 ? 18.7 kB ? (?)
    main ? 24.2 kB ? (?)
    module ? 23.4 kB ? (?)
  • @firebase/api-documenter

    Type Base (d095ad3) Head (3939af1) Diff
    main ? 3.72 kB ? (?)
  • @firebase/app

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 10.9 kB ? (?)
    esm2017 ? 9.63 kB ? (?)
    lite ? 8.95 kB ? (?)
    lite-esm2017 ? 7.93 kB ? (?)
    main ? 9.99 kB ? (?)
    module ? 10.9 kB ? (?)
    react-native ? 9.70 kB ? (?)
  • @firebase/auth

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 181 kB ? (?)
    main ? 181 kB ? (?)
    module ? 181 kB ? (?)
  • @firebase/component

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 7.24 kB ? (?)
    esm2017 ? 5.55 kB ? (?)
    main ? 7.57 kB ? (?)
    module ? 7.24 kB ? (?)
  • @firebase/database

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 296 kB ? (?)
    esm2017 ? 264 kB ? (?)
    main ? 298 kB ? (?)
    module ? 296 kB ? (?)
  • @firebase/database-compat

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 86.3 kB ? (?)
    main ? 102 kB ? (?)
    module ? 86.3 kB ? (?)
  • @firebase/database-exp

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 246 kB ? (?)
    main ? 278 kB ? (?)
    module ? 246 kB ? (?)
  • @firebase/firestore

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 283 kB ? (?)
    esm2017 ? 226 kB ? (?)
    main ? 530 kB ? (?)
    module ? 283 kB ? (?)
    react-native ? 226 kB ? (?)
  • @firebase/firestore-compat

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 28.6 kB ? (?)
    main ? 37.6 kB ? (?)
    module ? 28.6 kB ? (?)
    react-native ? 28.3 kB ? (?)
  • @firebase/firestore-exp

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 223 kB ? (?)
    main ? 506 kB ? (?)
    module ? 223 kB ? (?)
    react-native ? 224 kB ? (?)
  • @firebase/firestore-lite

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 72.0 kB ? (?)
    main ? 146 kB ? (?)
    module ? 72.0 kB ? (?)
    react-native ? 72.2 kB ? (?)
  • @firebase/firestore/bundle

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 289 kB ? (?)
    esm2017 ? 176 kB ? (?)
    main ? 526 kB ? (?)
    module ? 289 kB ? (?)
    react-native ? 176 kB ? (?)
  • @firebase/firestore/memory

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 215 kB ? (?)
    esm2017 ? 172 kB ? (?)
    main ? 324 kB ? (?)
    module ? 215 kB ? (?)
    react-native ? 172 kB ? (?)
  • @firebase/firestore/memory-bundle

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 224 kB ? (?)
    esm2017 ? 176 kB ? (?)
    main ? 321 kB ? (?)
    module ? 224 kB ? (?)
    react-native ? 176 kB ? (?)
  • @firebase/functions

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 10.6 kB ? (?)
    esm2017 ? 8.15 kB ? (?)
    main ? 11.0 kB ? (?)
    module ? 10.6 kB ? (?)
  • @firebase/installations

    Type Base (d095ad3) Head (3939af1) Diff
    esm2017 ? 16.6 kB ? (?)
    main ? 22.2 kB ? (?)
    module ? 21.6 kB ? (?)
  • @firebase/logger

    Type Base (d095ad3) Head (3939af1) Diff
    esm2017 ? 3.25 kB ? (?)
    main ? 5.38 kB ? (?)
    module ? 4.65 kB ? (?)
  • @firebase/messaging

    Type Base (d095ad3) Head (3939af1) Diff
    esm2017 ? 26.2 kB ? (?)
    main ? 34.9 kB ? (?)
    module ? 34.4 kB ? (?)
  • @firebase/performance

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 27.7 kB ? (?)
    esm2017 ? 25.9 kB ? (?)
    main ? 28.0 kB ? (?)
    module ? 27.7 kB ? (?)
  • @firebase/polyfill

    Type Base (d095ad3) Head (3939af1) Diff
    main ? 747 B ? (?)
    module ? 705 B ? (?)
  • @firebase/remote-config

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 22.4 kB ? (?)
    esm2017 ? 17.4 kB ? (?)
    main ? 23.0 kB ? (?)
    module ? 22.4 kB ? (?)
  • @firebase/rules-unit-testing

    Type Base (d095ad3) Head (3939af1) Diff
    main ? 14.6 kB ? (?)
  • @firebase/storage

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 63.4 kB ? (?)
    esm2017 ? 54.6 kB ? (?)
    main ? 63.8 kB ? (?)
    module ? 63.4 kB ? (?)
  • @firebase/storage-compat

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 10.2 kB ? (?)
    main ? 29.1 kB ? (?)
    module ? 10.2 kB ? (?)
  • @firebase/storage-exp

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 51.5 kB ? (?)
    main ? 52.6 kB ? (?)
    module ? 51.5 kB ? (?)
  • @firebase/util

    Type Base (d095ad3) Head (3939af1) Diff
    browser ? 21.2 kB ? (?)
    esm2017 ? 20.0 kB ? (?)
    main ? 25.8 kB ? (?)
    module ? 21.2 kB ? (?)
  • @firebase/webchannel-wrapper

    Type Base (d095ad3) Head (3939af1) Diff
    esm2017 ? 39.5 kB ? (?)
    main ? 46.9 kB ? (?)
    module ? 40.8 kB ? (?)
  • firebase

    Click to show 15 binary size changes.
    Type Base (d095ad3) Head (3939af1) Diff
    firebase-analytics.js ? 35.8 kB ? (?)
    firebase-app.js ? 21.2 kB ? (?)
    firebase-auth.js ? 177 kB ? (?)
    firebase-database.js ? 187 kB ? (?)
    firebase-firestore.js ? 332 kB ? (?)
    firebase-firestore.memory.js ? 266 kB ? (?)
    firebase-functions.js ? 10.7 kB ? (?)
    firebase-installations.js ? 19.3 kB ? (?)
    firebase-messaging.js ? 41.0 kB ? (?)
    firebase-performance-standalone.es2017.js ? 72.9 kB ? (?)
    firebase-performance-standalone.js ? 49.2 kB ? (?)
    firebase-performance.js ? 38.3 kB ? (?)
    firebase-remote-config.js ? 36.9 kB ? (?)
    firebase-storage.js ? 41.6 kB ? (?)
    firebase.js ? 874 kB ? (?)

Test Logs

@IchordeDionysos
Copy link
Contributor

Very nice 😍
Thanks Sam

packages/rules-unit-testing/src/api/index.ts Outdated Show resolved Hide resolved
};
/** Construct an App authenticated as an admin user. */
export function initializeAdminApp(options: AdminAppOptions): firebase.app.App {
export function initializeAdminApp(options: AdminAppOptions): app.App {
Copy link
Contributor Author

@samtstern samtstern May 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type has been wrong for a while! We can't live with it anymore because of Storage, which has a totally different API between client and Admin.

ssl: false
});
const { hostname, port } = parseHost(getFirestoreHost());
app.firestore().useEmulator(hostname, port);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving to consistently use useEmulator across the board.

@@ -216,7 +220,24 @@ describe('Testing Module Tests', function () {
});
});

it('initializeAdminApp() has admin access', async function () {
it('initializeAdminApp() has admin access to RTDB', async function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated this into three tests so we can tell failures apart.

@@ -15,7 +15,7 @@
"build:deps": "lerna run --scope @firebase/rules-unit-testing --include-dependencies build",
"dev": "rollup -c -w",
"test:nyc": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --config ../../config/mocharc.node.js",
"test": "firebase --project=foo --debug emulators:exec 'yarn test:nyc'",
"test": "FIREBASE_CLI_PREVIEWS=storageemulator STORAGE_EMULATOR_HOST=http://localhost:9199 firebase --project=foo --debug emulators:exec 'yarn test:nyc'",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add the STORAGE_EMULATOR_HOST variable to compensate for firebase/firebase-tools#3337

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"test": "FIREBASE_CLI_PREVIEWS=storageemulator STORAGE_EMULATOR_HOST=http://localhost:9199 firebase --project=foo --debug emulators:exec 'yarn test:nyc'",
"test": "FIREBASE_CLI_PREVIEWS=storageemulator firebase --project=foo --debug emulators:exec 'yarn test:nyc'",

Gotta clean this up now we've released the CLI with the fix

@google-oss-bot
Copy link
Contributor

Size Analysis Report

Affected Products

  • @firebase/app-exp

    • initializeApp

      Size Table

      TypeBase (d095ad3)Head (8be7b22)Diff
      size-with-ext-deps
      10.8 kB
      11.0 kB
      +229 B (+2.1%)

@yuchenshi yuchenshi merged commit 66deb25 into master May 6, 2021
@yuchenshi yuchenshi deleted the ss-rut-storage branch May 6, 2021 17:57
@google-oss-bot google-oss-bot mentioned this pull request May 11, 2021
@firebase firebase locked and limited conversation to collaborators Jun 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants