-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 warning
and failing
test decorators
#5929
Conversation
warning
and failing
test decoratorswarning
and failing
test decorators
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.
Looks good, left just one small comment 😄
app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/types.ts
Outdated
Show resolved
Hide resolved
app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/TestRunner.ts
Show resolved
Hide resolved
app/src/examples/RuntimeTests/tests/animations/withSpring/variousConfig.test.tsx
Show resolved
Hide resolved
|
||
render() { | ||
if (this.state.hasError) { | ||
return <Text>Something went wrong.</Text>; |
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.
return <Text>Something went wrong.</Text>; | |
return <Text>Detected exception during component rendering.</Text>; |
app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/TestRunner.ts
Show resolved
Hide resolved
'Error: [Reanimated] The easing function is not a worklet. Please make sure you import `Easing` from react-native-reanimated.', | ||
async () => { | ||
await render( | ||
<ErrorBoundary> |
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.
What will happen if someone doesn't add <ErrorBoundary>
and a component throws an error? Perhaps we should consider adding it by default inside the RuntimeTestsRunner
component.
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.
What will happen if someone doesn't add and a component throws an error?
The tests will stop, you have to somehow catch all the errors to keep the tests execution.
Perhaps we should consider adding it by default inside the RuntimeTestsRunner component.
I was considering it. However our test cases should consist of simple scenarios, and such a wrapper would modify the rendered components. Sometimes we add new tests after fixing bugs, and with a wrapper we can't be sure that all the bugs are going to be reproducible
this.expect(getTrackerCallCount(consoleTrackerRef)).toBeCalled(1); | ||
if (testCase.warningMessage) { | ||
this.expect(message.value).toBe(testCase.warningMessage, ComparisonMode.STRING); | ||
} |
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.
The expect
function should be utilized by the user during testing, not in our internal logic. This functionality is not the responsibility of the expect
method. We can simply use a single shared value for it instead of a callTracker.
console.error = newConsoleFuncJS; | ||
console.warn = newConsoleFuncJS; |
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.
Do you ever restore original implementation of console.warn
?
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.
No, since you have to reload the app to re-run the tests and it resets it.
test.warn( | ||
'Invalid mass and stiffness, config is { mass: -40, stiffness: -400 }', | ||
'[Reanimated] Invalid spring config, stiffness must be grater than zero but got -400, mass must be grater than zero but got -40', | ||
async () => { | ||
await render(<AnimatedComponent animateFrom={30} animateTo={300} config={{ mass: -40, stiffness: -400 }} />); | ||
}, | ||
); |
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.
Why did you choose test.warn
syntax instead of something similar to Jest syntax? I mean:
test('Invalid mass and stiffness, config is { mass: -40, stiffness: -400 }', async () => {
const result = await render(<AnimatedComponent animateFrom={30} animateTo={300} config={{ mass: -40, stiffness: -400 }} />);
expect(result).toThrow('[Reanimated] Invalid spring config...', mode=WARNING);
});
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.
In jest there are two ways to test errors,
try { | ||
this._renderHook(component); | ||
} catch (e) { | ||
console.log(e); |
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.
Do we ignore all exceptions? 🤔
app/src/examples/RuntimeTests/ReanimatedRuntimeTestsRunner/TestRunner.ts
Show resolved
Hide resolved
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [react-native-reanimated](https://togithub.com/software-mansion/react-native-reanimated) | [`~3.11.0` -> `~3.12.0`](https://renovatebot.com/diffs/npm/react-native-reanimated/3.11.0/3.12.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/react-native-reanimated/3.12.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/react-native-reanimated/3.12.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/react-native-reanimated/3.11.0/3.12.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/react-native-reanimated/3.11.0/3.12.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>software-mansion/react-native-reanimated (react-native-reanimated)</summary> ### [`v3.12.0`](https://togithub.com/software-mansion/react-native-reanimated/releases/tag/3.12.0) [Compare Source](https://togithub.com/software-mansion/react-native-reanimated/compare/3.11.0...3.12.0) #### What's Changed - Give more meaningful warning when modifying a Shareable by [@​tjzel](https://togithub.com/tjzel) in [software-mansion/react-native-reanimated#5548 - Make animated components use different tags for events by [@​szydlovsky](https://togithub.com/szydlovsky) in [software-mansion/react-native-reanimated#5960 - Add `warning` and `failing` test decorators by [@​Latropos](https://togithub.com/Latropos) in [software-mansion/react-native-reanimated#5929 - Update useAnimatedKeyboard docs by [@​maciekstosio](https://togithub.com/maciekstosio) in [software-mansion/react-native-reanimated#5866 - Change the docs to mention, that `.springify()` works with `.duration()` by [@​Latropos](https://togithub.com/Latropos) in [software-mansion/react-native-reanimated#5990 - \[Android]\[Keyboard] More consistent inequality check to compute keyboard state by [@​antFrancon](https://togithub.com/antFrancon) in [software-mansion/react-native-reanimated#5874 - fix typo on object key for `targetValues` in custom-animations.mdx by [@​JDMathew](https://togithub.com/JDMathew) in [software-mansion/react-native-reanimated#5994 - Remove outdated code for unsupported React Native versions by [@​tomekzaw](https://togithub.com/tomekzaw) in [software-mansion/react-native-reanimated#5979 - Remove REAInitializer by [@​tomekzaw](https://togithub.com/tomekzaw) in [software-mansion/react-native-reanimated#5681 - Prevent crash on non-existent view updates in Android by [@​thomas-rx](https://togithub.com/thomas-rx) in [software-mansion/react-native-reanimated#5767 - Fix location after shared element transition by [@​piaskowyk](https://togithub.com/piaskowyk) in [software-mansion/react-native-reanimated#6010 - Make `useScrollviewOffset` ref nullable and simplify its code by [@​szydlovsky](https://togithub.com/szydlovsky) in [software-mansion/react-native-reanimated#6009 - fix: use proper classes for bridgeless by [@​WoLewicki](https://togithub.com/WoLewicki) in [software-mansion/react-native-reanimated#5997 - docs: add [@​swmansion/t-rex-ui](https://togithub.com/swmansion/t-rex-ui) by [@​patrycjakalinska](https://togithub.com/patrycjakalinska) in [software-mansion/react-native-reanimated#6015 - Remove `CellRendererComponent` from Animated.FlatList props by [@​Latropos](https://togithub.com/Latropos) in [software-mansion/react-native-reanimated#5951 - Add `useComposedEventHandler` hook by [@​szydlovsky](https://togithub.com/szydlovsky) in [software-mansion/react-native-reanimated#5890 - Align handling colors with RN by [@​maciekstosio](https://togithub.com/maciekstosio) in [software-mansion/react-native-reanimated#5825 - Add more tests - useSharedValue, useAnimatedStyle , useDerivedValue by [@​Latropos](https://togithub.com/Latropos) in [software-mansion/react-native-reanimated#5981 - Make animation RollInLeft work with modifers by [@​Latropos](https://togithub.com/Latropos) in [software-mansion/react-native-reanimated#6039 - Test predefined entering animation by [@​Latropos](https://togithub.com/Latropos) in [software-mansion/react-native-reanimated#5995 - Tests: cancelAnimation, useFrameCallback, measure, withDecay by [@​Latropos](https://togithub.com/Latropos) in [software-mansion/react-native-reanimated#6016 - docs: fix useAnimatedKeyboard page crash by [@​patrycjakalinska](https://togithub.com/patrycjakalinska) in [software-mansion/react-native-reanimated#6056 - \[Web LA] Remove `existingTransform` by [@​m-bert](https://togithub.com/m-bert) in [software-mansion/react-native-reanimated#6060 #### New Contributors [@​antFrancon](https://togithub.com/antFrancon), [@​JDMathew](https://togithub.com/JDMathew), [@​thomas-rx](https://togithub.com/thomas-rx), [@​exploIF](https://togithub.com/exploIF) #### 🙌 Thank you for your contributions! **Full Changelog**: software-mansion/react-native-reanimated@3.11.0...3.12.0 Package build: https://github.com/software-mansion/react-native-reanimated/actions/runs/9287839734 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/GSTJ/react-native-magic-modal). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNzcuOCIsInVwZGF0ZWRJblZlciI6IjM3LjM3Ny44IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
const message = makeMutable(''); | ||
|
||
const newConsoleFuncJS = (warning: string) => { | ||
this.callTracker(consoleTrackerRef); |
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.
it could be just a simple sharedValue (makeMutable) instead of using callTrucker
Summary
After this PR we are going to support the following API:
Describe:
describe("Name of the test suite", ()=>{})
describe.skip("Name of the test suite", ()=>{})
describe.only("Name of the test suite", ()=>{})
Test:
test("Name of the test suite", ()=>{})
test.each([1,2,3])("Name of the test suite", ()=>{})
test.skip("Name of the test suite", ()=>{})
test.skip.each([1,2,3])("Name of the test suite", ()=>{})
test.only("Name of the test suite", ()=>{})
test.only.each([1,2,3])("Name of the test suite", ()=>{})
console.warn
to be calledtest.warn("Name of the test suite", "Expected error message", ()=>{})
test.warn.each([1,2,3])("Name of the test suite", "Expected error message", ()=>{})
test.failing("Name of the test suite", "Expected error message", ()=>{})
test.failing.each([1,2,3])("Name of the test suite", "Expected error message", ()=>{})
Test plan