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

@firebase/rules-unit-testing fails when loaded as es6 module with firebase-js-sdk >= 9.2.0 #5825

Open
kenkunz opened this issue Dec 20, 2021 · 8 comments
Labels

Comments

@kenkunz
Copy link

kenkunz commented Dec 20, 2021

[REQUIRED] Describe your environment

  • Operating System version: macOS Monterey 12.0.1
  • Browser version: n/a
  • Firebase SDK version: >= 9.2.0
  • Firebase Product: rules-unit-testing, firestore

[REQUIRED] Describe the problem

With @firebase/rules-unit-testing@2.0.1 and firebase >=9.0.0 <=9.1.3, the test utilities work
whether loaded as a cjs require or an es6 module. After upgrading to firebase >=9.2.0, the
utilities no longer work when loaded as es6 module, but still work when loaded with cjs require.

Since other firebase modules support es6 module loading, it seems surprising for rules-unit-testing
not to fully support this as well.

Current workaround

Using cjs require for my firestore rules tests.

Steps to reproduce:

  1. install dependency: Firebase Emulators

  2. clone kenkunz/firestore-testing-repro and install npm modules

    git clone https://github.com/kenkunz/firestore-testing-repro.git
    cd firestore-testing-repro
    npm install
  3. run the tests

    npm run test

    Note that both test.js and test.cjs complete successfully

  4. upgrade to firebase@9.2.0 (or greater)

    npm i -D firebase@9.2.0
  5. run the tests again

    npm run test

    Note that test.cjs still passes but test.js fails (see error output below)

Error output:

FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore
at doc (file:///Users/ken/Code/firestore-testing-repro/node_modules/@firebase/firestore/dist/index.node.mjs:19998:19)
at file:///Users/ken/Code/firestore-testing-repro/test.js:8:20
at RulesTestEnvironmentImpl.<anonymous> (node_modules/@firebase/rules-unit-testing/dist/index.cjs.js:310:46)
at step (node_modules/@firebase/rules-unit-testing/dist/index.cjs.js:74:23)
at Object.next (node_modules/@firebase/rules-unit-testing/dist/index.cjs.js:55:53)
at /Users/ken/Code/firestore-testing-repro/node_modules/@firebase/rules-unit-testing/dist/index.cjs.js:48:71
at new Promise (<anonymous>)
at __awaiter (node_modules/@firebase/rules-unit-testing/dist/index.cjs.js:44:12)
at RulesTestEnvironmentImpl.withSecurityRulesDisabled (node_modules/@firebase/rules-unit-testing/dist/index.cjs.js:300:16)
at Context.<anonymous> (file:///Users/ken/Code/firestore-testing-repro/test.js:7:19)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@jbalidiong jbalidiong added testing-sdk testing with emulator v9 and removed needs-triage labels Dec 20, 2021
@jbalidiong
Copy link
Contributor

Hi @kenkunz, thanks for the report. I was able to reproduce the behavior now. Let me check what we can do for this issue or bring someone here that can provide more context about it. I’ll update this thread if I have any information to share.

@jbalidiong jbalidiong added the bug label Dec 23, 2021
@angrycat9000
Copy link

Thanks for the work around @kenkunz. I hit this bug when upgrading to the new 9.0 API

@ChromeQ
Copy link

ChromeQ commented Aug 29, 2022

Noticed this is old but it is still an issue with firebase v9.9.3 and @firebase/rules-unit-testing v2.0.4 so it would be good to see an update or a fix here

@ghinda
Copy link

ghinda commented Nov 7, 2024

Seems to be fixed with with the latest firebase 11.0.1 and @firebase/rules-unit-testing 4.0.0.

@DellaBitta
Copy link
Contributor

@kenkunz,

Can you confirm that this was fixed in v11?

@kenkunz
Copy link
Author

kenkunz commented Nov 8, 2024

@kenkunz,

Can you confirm that this was fixed in v11?

Sorry, I haven't been actively using Firebase for a while, and don't have bandwidth to dust this off to test atm.

@DellaBitta
Copy link
Contributor

Ok, thanks @kenkunz.

I'll leave this issue open for now. If someone else has any more information then please post it here, otherwise I'll assume this is fixed and we'll let the bot auto close it in a few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants