-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
feat(cli): add test permissions to Deno.test #10188
feat(cli): add test permissions to Deno.test #10188
Conversation
@caspervonb Whatever happens - thanks for you contribution, we appreciate the time & effort you're putting into Deno! That said, I don't really understand why this change is necessary. Maybe I'm just ignorant. However, can you give me the layman's explanation? |
Thanks @piscisaureus. This basic premise is to set up the permissions for a specific test case. We can't do this with Deno.permissions.revoke because once permission is revoked you can't go back so there's no way to set up a test case with a certain set of permissions with the current permission API (@bartlomieju was kicking around the idea of adding it to The question of "How do I run a test case with x, y, and z" permissions does come up every now and then altho not that frequently it is something users find themselves needing when working with APIs that require certain permissions. We set up these preconditions internally in our unit tests by not using The existence of the unit test runner is causing us to leak a bunch of internal details about the test runner as well which is not great. TL;DR it is needed to set up the preconditions for a test that expects to have X permissions. As a side effect, this will let us drop a few thousand lines of code that is used to support and implement our custom ad-hoc unit test runner and dogfood the user-facing test runner in our own test suite. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanly implemented. I think it's ready to land after addressing Bert's question regarding JSdoc. Nice work @caspervonb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
This adds adds permissions to the test definitions which allows tests to run with different permission sets than the process's permission.
The change will only be in effect within the test function, once the test has completed the original process permission set is restored.
Test permissions cannot exceed the process's permission.
You can only narrow or drop permissions, failure to acquire a permission results in an error being thrown and the test case will fail.
Closes #9859