Skip to content

Add withFunctionsTriggersDisabled method to rules-unit-testing #3928

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

Merged
merged 12 commits into from
Oct 30, 2020

Conversation

samtstern
Copy link
Contributor

@samtstern samtstern commented Oct 13, 2020

Discussion

Note to reviewer: this makes two changes to dev dependencies:

  • Updated to firebase-tools 8.13.0 which has Implement endpoint to enable/disable functions triggers firebase-tools#2706
  • Added firebase-functions because in order to properly test this we needed the functions emulator to run during the tests (even with no functions). The functions emulator refuses to start up if it can't find firebase-functions in the developer's node_modules.

Testing

  • Added unit tests

API Changes

Googlers: See API proposal here

@changeset-bot
Copy link

changeset-bot bot commented Oct 13, 2020

🦋 Changeset detected

Latest commit: 6b6fefa

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

}
}
);
const resp = await requestPromise({
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 also DRY-ed up a lot of the request boillerplate in this file.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 13, 2020

Binary Size Report

Affected SDKs

  • @firebase/rules-unit-testing

    Type Base (973cdfa) Head (793b4f5) Diff
    main 8.00 kB 9.74 kB +1.75 kB (+21.8%)

Test Logs

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 13, 2020

Size Analysis Report

Affected Products

No changes between base commit (602ec18) and head commit (f1c4bd6).

Test Logs

@@ -28,7 +28,8 @@
"@google-cloud/firestore": "4.4.0",
"@types/request": "2.48.5",
"firebase-admin": "9.2.0",
"firebase-tools": "8.12.1",
"firebase-tools": "8.13.0",
"firebase-functions": "3.11.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See note in PR description about this new dev dependency

@samtstern samtstern requested a review from Feiyang1 October 29, 2020 11:28
@github-actions
Copy link
Contributor

Changeset File Check ⚠️

  • Changeset formatting error in following file:
    { ValidationError: Some errors occurred when validating the changesets config:
    The package "@firebase/remote-config-exp" depends on the ignored package "@firebase/app-exp", but "@firebase/remote-config-exp" is not being ignored. Please add "@firebase/remote-config-exp" to the `ignore` option.
    The package "@firebase/remote-config-exp" depends on the ignored package "@firebase/app-types-exp", but "@firebase/remote-config-exp" is not being ignored. Please add "@firebase/remote-config-exp" to the `ignore` option.
    The package "@firebase/remote-config-exp" depends on the ignored package "@firebase/installations-exp", but "@firebase/remote-config-exp" is not being ignored. Please add "@firebase/remote-config-exp" to the `ignore` option.
      name: 'ValidationError',
      _error:
       Error
           at new ExtendableError (/home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/extendable-error/bld/index.js:23:24)
           at new ValidationError (/home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/@changesets/errors/dist/errors.cjs.dev.js:16:1)
           at parse (/home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/@changesets/cli/node_modules/@changesets/config/dist/config.cjs.dev.js:196:11)
           at Object.read (/home/runner/work/firebase-js-sdk/firebase-js-sdk/node_modules/@changesets/cli/node_modules/@changesets/config/dist/config.cjs.dev.js:84:10) }
    

@Feiyang1
Copy link
Member

Feel free to merge. I will fix the changeset warning in a different PR.

@samtstern samtstern merged commit 6ef39d4 into master Oct 30, 2020
@google-oss-bot google-oss-bot mentioned this pull request Nov 3, 2020
wu-hui added a commit that referenced this pull request Nov 9, 2020
* Rolls a node app building bundles.

* Build bundle files for given list of project IDs.

* Build the bundle json map and save it for integration tests.

* Add emulator_settings.ts to gulp

* Move bundle.test.ts to api/

* Bundles passes all tests and expose in classic API

* Add CI project ID to bundles.

* Adhoc string replacement and length re-calculation

* Fix lint errors.

* Delete old changes from make node app

* Address comments

* Update yarn.lock for release (#3998)

Temp fix where database version is bumped before firebase-admin can update deps

* Manually prepares the bundle strings.

* Update API

* Update config.ts

* Use Chrome for karma debugging (#4007)

* Cache emulator between runs (#3956)

* Remote Config Modularization (#3975)

* rc exp init

* Add apis

* register rc exp

* implement funcitonal APIs

* fix tests

* build rc exp

* add api-extractor to rc types

* cast directly witout function

* delete changelog for rc exp

* add code owners to rc exp

* update dep version

* Remove AuthErrorCode from core export (#4013)

* Remove AuthErrorCode from core export

* Api

* Update config.ts to remove bundles

* adds a root changelog (#4009)

* adds a root changelog

* Update CHANGELOG.md

Co-authored-by: Feiyang <[email protected]>

* Update dependency typescript to v4.0.5 (#3846)

Co-authored-by: Renovate Bot <[email protected]>

* Update dependency karma-firefox-launcher to v2 (#3987)

Co-authored-by: Renovate Bot <[email protected]>

* Update dependency google-closure-library to v20200830 (#3765)

* Update dependency google-closure-library to v20200830

* Replace goog.isArray with Array.isArray

https://github.com/google/closure-library/releases/tag/v20200628

Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: Alex Volkovitsky <[email protected]>

* exclude remote config exp packages in changeset (#4014)

* Set 1s timeout for onBackgroundMessage Hook (#3780)

* await onBackgroundMessage hook

* Create fluffy-panthers-hide.md

* block in onPush to let onBackgroundMessage to execute

* polish wording

* Update changeset

to be more specific

* Update fluffy-panthers-hide.md

* Clarify PR is about a bug fix

* Update fluffy-panthers-hide.md

* A whole bunch of things to bring auth (compat) to parity (#3970)

* Handle anonymous auth re-login edge case

* Formatting

* Initial fixes

* Fix redirect

* clean up additional user info

* Formatting

* PR feedback

* Fix some tests

* Fix tests & write some new ones

* Fix broken build

* Formatting

* Formatting

* PR feedback

* Formatting

* PR feedback

Co-authored-by: avolkovi <[email protected]>

* Add withFunctionsTriggersDisabled method to rules-unit-testing (#3928)

* Update integration tests to use free functions

* Functions compat package (#3739)

* Add free functions to exports

* Fix to avoid false failures on changeset checker (#4012)

* Add changeset for Firestore (#4030)

* Update functions-compat dep version and fix changeset script error (#4032)

* Update integration tests. Minified tests fail.

* Bump node memory limit for all test CI (#4035)

* Compat Layer for Firestore (#4003)

* Rename all public API types to PublicX (#4039)

* Update all non-major dependencies (#3953)

Co-authored-by: Renovate Bot <[email protected]>

* Version Packages (#4033)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Set up Storage modularization (#3499)

Refactor storage for modularization.

* Free functions removed from exp database.ts

Co-authored-by: Christina Holland <[email protected]>
Co-authored-by: Sebastian Schmidt <[email protected]>
Co-authored-by: Sam Stern <[email protected]>
Co-authored-by: Feiyang <[email protected]>
Co-authored-by: Sam Horlbeck Olsen <[email protected]>
Co-authored-by: Dimitri Mitropoulos <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: Alex Volkovitsky <[email protected]>
Co-authored-by: Kai Wu <[email protected]>
Co-authored-by: Google Open Source Bot <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@hexetia
Copy link

hexetia commented Nov 13, 2020

This should work with Firestore triggers?

because I tried to call firebase.clearFirestoreData wrapped with withFunctionTriggersDisabled but it didn't work as I expected.

My enviroment
Linux / Ubuntu 20.04
firebase-tools 8.16.1
@firebase/rules-unit-testing 1.1.0
firebase-admin 9.4.0
firebase 8.0.1

Code used (I can create an issue with a proper repo if needed)

beforeEach(async () => {
    await firebase.withFunctionTriggersDisabled(() => firebase.clearFirestoreData({ projectId: APP_ID }));
});
export const onDeleteAffiliate = functions
    .runWith({ memory: '128MB' })
    .firestore.document(`affiliates/{affiliateId}`)
    .onDelete(async (docSnap, context) => {
       ...
    });

Selection_020

@samtstern
Copy link
Contributor Author

samtstern commented Nov 13, 2020

@saculbr I think you have a hanging promise. If you add 'return' or 'await' before clearFirestoreData it should work.

If not, please file a new issue!

@hexetia
Copy link

hexetia commented Nov 13, 2020

@samtstern I tried that too, but don't worked

@samtstern
Copy link
Contributor Author

@saculbr you're totally right, this is broken.

@firebase firebase locked and limited conversation to collaborators Nov 30, 2020
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.

6 participants