-
Notifications
You must be signed in to change notification settings - Fork 915
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
initializeTestEnvironment @firebase/rules-unit-testing should not require node process.env #8795
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
If there are no serious objections to my suggested changes, I would be happy to open a PR. |
Also, doing this results in this warning when running my tests:
Which is just noise that I would prefer not to have in my logs. |
Hi @rgant, can you elaborate on why your use case requires you to run these tests in the browser? |
I need to setup and check test data in Firestore without worrying about the firestore.rules in an Angular application. For example, So in my tests I want to have both Quizzes owned by the User logged in during testing, and Quizzes that are shared but owned by another user. Which I have done by exporting a specific setup of Quizzes in Firestore emulator. Also, to test that empty list case, I need to un-share some Quizzes, which is easier to do with a NoRulesContext. Otherwise this test needs to login as multiple users to change the quizzes, and change them back. |
@rgant Thanks for the detailed explanation. I believe all of this behaviour could be tested in a Node environment (please correct/explain if i'm wrong). Have you ran into issues running these tests in a Node environment? You have mentioned multiple issues you're experiencing with rules-unit-testing. Could we keep this issue focused on the discussion of rules-unit-testing requiring |
Angular tests are done in a browser environment. That is the default for Angular testing setup at this time. IIRC, Angular plans to continue to focus on real browser testing. Using some other testing setup would require me to leave the official Angular setup, which is not possible for my project. My review of the |
BTW, I'm not asking that the tool to not use environment variables. I'm just asking for it to not require them. If you are open to that possibility I am happy to open a PR. If you have other requirements then I would appreciate understanding them. It could be as straightforward as adding: function hasEnv(): boolean {
return typeof process !== 'undefined' &&
typeof process.env !== 'undefined';
} |
The main purpose of the rules-unit-testing library is to let you run a number of scenarios where the rules should either prevent or an allow the operation to go through, to ensure your rules are written correctly and are blocking/allowing what they should. It seems like that's not what you're interested in testing. Please let me know if I misunderstood, but you seem to be interested in testing the app functionality itself and what you really want is to be able to use the emulators with the rules turned off. Unfortunately that's not really what the rules-unit-testing library is designed for. If you were interested in testing your rules, we'd recommend two sets of tests - a set of app tests, as you currently have, in the browser, that test app functionality, and another set of tests, in Node, that test whether various scenarios successfully make it through your rules or not. These would be testing for two different things. I can see how it would be convenient to have more tools that allow you to customize emulators for special cases in application testing and we can add any suggestions you have as a feature request. This isn't a code decision the SDK team can make by ourselves as it would change the nature of the product and broaden the environments this SDK supports, which needs product buy-in, but if we get enough demand (comments, upvotes on the FR issue), I'm sure that would factor into the decision. In the meantime, some workarounds might be:
I'll mark this as a feature request in the meantime, and will keep track of how much demand we get on it. |
That won't work because the functionality of the rules influences the functionality of the application. With rules, the list query throws a
I already have a work around, it is just ugly. If you all do not wish to support this use case then I guess I just document and move on. But since it is a small change I hoped you would be willing to allow it.
Understood, but it also exposes the |
Operating System
macOS
Environment (if applicable)
Any Modern Browser, Chrome
Firebase SDK Version
@firebase/[email protected]
Firebase SDK Product(s)
Firestore, Storage
Project Tooling
Angular App
Detailed Problem Description
emulatorFromEnvVar
assumes that it is running in a Node.js environment with access toprocess.env
, however this test library is useful for browser based applications.It would be nice if this method could check for
process
to be defined before attempting to use it. It would also be nice ifinitializeTestEnvironment
config (TestEnvironmentConfig
) would allow you to skip configurations that you don't need. For example, I am running the emulator with--only auth,firestore,storage
. So ifhub
could figure out that I havefirestore
andstorage
but notdatabase
running and just configure those that would be less noise in my code.Steps and code to reproduce issue
See the full app: https://github.com/rgant/brainfry/blob/47c25d00814520c4f90e7565bd9d601d2cb5c9dd/src/testing/firestore-data.ts#L28
The text was updated successfully, but these errors were encountered: