-
Notifications
You must be signed in to change notification settings - Fork 45.7k
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
Add test helpers for gating by feature #18574
Conversation
Adds a new test helper, `it.gate`. You pass it the name of a feature flag, and if the flag is enabled, it asserts that the test passes. If the flag is off, it asserts that the test fails. Example: ```js it.gate('enableNewReconciler', 'test that only passes in new reconciler', () => { // ... test goes here }); ``` (`test.gate` is equivalent and makes perhaps makes more grammatical sense, but I'm using `it.gate` in these examples since we use `it` everywhere in our tests.) You can test multiple flags by passing an array: ```js it.gate( ['enableNewReconciler', 'enableModernEventSystem'], 'test that passes only in new reconciler with modern event system', () => { // ... test goes here } ); ``` If any of the flags are disabled, the test is expected to fail. You can check if a flag is off by addding a `!` to the front: ```js it.gate( '!enableNewReconciler', 'test that passes only in the old reconciler', () => { // ... test goes here } ); ``` I also added aliases for `it.old` and `it.new`, for testing the different reconciler forks: ```js it.old('test that passes only in the old reconciler', () => { // ... test goes here }); it.new('test that passes only in the new reconciler', () => { // ... test goes here }); ```
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 8aa9d74:
|
Update: Added this to PR description Longer term I think it would nice if these were implemented as pragmas instead: // @gate enableNewReconciler
it('test that passes only in the new reconciler', () => {
// ... test goes here
}); |
To show that it works
function installGatedTestHelpers(channel) { | ||
const it = global.it; | ||
const fit = global.fit; | ||
const xit = global.xit; |
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.
I kind of was hoping to switch to the test()
form. Does this patch that too? I guess it’s just an alias for it
?
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.
Yeah it
is an alias
I went ahead and opened an alternative PR for the pragma proposal: #18581 I prefer that one, but I'll keep this PR open for reference. |
Closed by #18581 |
Adds a new test helper,
it.gate
. You pass it the name of a feature flag, and if the flag is enabled, it asserts that the test passes. If the flag is off, it asserts that the test fails. Example:(
test.gate
is equivalent and makes perhaps makes more grammatical sense, but I'm usingit.gate
in these examples since we useit
everywhere in our tests.)You can test multiple flags by passing an array:
If any of the flags are disabled, the test is expected to fail.
You can check if a flag is off by adding a
!
to the front:For anything more advanced, you can pass a function:
I also added aliases for
it.old
andit.new
, for testing the different reconciler forks:Next steps
Longer term I think it would nice if these were implemented as pragmas instead: