Test report#2780
Conversation
| export type State = { | ||
| pause: PauseState, | ||
| sources: SourcesState, | ||
| breakpoints: BreakpointsState |
There was a problem hiding this comment.
I should add the remaining reducers
| it("asm", async () => await asm(ctx)); | ||
|
|
||
| it("breakpoints - toggle", async () => await breakpoints.toggle(ctx)); | ||
| it.only("breakpoints - toggle", async () => await breakpoints.toggle(ctx)); |
| } | ||
|
|
||
| export function formatDisplayName(frame: Frame) { | ||
| export function formatDisplayName(frame: LocalFrame): string { |
There was a problem hiding this comment.
I should make sure this is imported
| const isEmpty = require("lodash/isEmpty"); | ||
| const uniq = require("lodash/uniq"); | ||
|
|
||
| import type { Node, Path, Program } from "babylon"; |
There was a problem hiding this comment.
adding babylon types
| pendingSelectedLocation: Object, | ||
| pendingBreakpoints: any[], | ||
| expressions: Object | ||
| }; |
There was a problem hiding this comment.
adding pref types is really helpful
|
|
||
| There have been a couple places where flow types have been difficult to get right. | ||
|
|
||
| 1. **contravariants** `this.toggleFramesDisplay = this.toggleFramesDisplay.bind(this)` |
There was a problem hiding this comment.
yeah - i think that's right :)
@thejameskyle did i get it right?
There was a problem hiding this comment.
Class methods are covariant in Flow by default, which in effect means they are "read-only" and cannot be assigned to.
class Error extends React.Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this); // Error
// ^ property `onClick`. Covariant property `onClick` incompatible with contravariant use in
// assignment of property `onClick`
}
onClick(event: ButtonClickEvent) {
// ...
}
render() {
return <button onClick={this.onClick}>Click Me</button>;
}
}In order to make this work, you need to use an additional class field, which are invariant (read & write) by default, like this:
class WorksWithClassPropertyType extends React.Component {
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this); // Works!
}
onClick: (ButtonClickEvent) => void;
onClick(event) {
// ...
}
}Alternatively you can use the class properties proposal to get around all of this:
class WorksWithClassPropertyArrowFunction extends React.Component {
onClick = (event: ButtonClickEvent) => {
// ...
};
}There was a problem hiding this comment.
@thejameskyle Great explanation, was wondering about why this happens myself too.
Is it the same case when I try to set custom toString() on some function?
const createActionCreator = (type, actionCreator) = {
actionCreator.toString = () => type // error!
return actionCreator
}is there any workaround for this?
| There have been a couple places where flow types have been difficult to get right. | ||
|
|
||
| 1. **contravariants** `this.toggleFramesDisplay = this.toggleFramesDisplay.bind(this)` | ||
| 2. **defaultProps** and other class properties. |
There was a problem hiding this comment.
What was the difficulty with defaultProps?
There was a problem hiding this comment.
adding static props in the class definition. I'll add that
There was a problem hiding this comment.
I would also like to know what was difficult
| We are not currently typing our test files, but I think it would be helpful if | ||
| we did. In this example, we are searching for all of the functions in a given | ||
| source, but because we did not provide a type for `getSourceText`, flow can | ||
| not use `getSymbols`'s types to tell us if we're writing a reasonable test. |
There was a problem hiding this comment.
The only caveat here is that it's sometimes useful to be able to "cheat" in tests, like pass in a mock object that doesn't match the full type but does just what this particular unit test needs.
There was a problem hiding this comment.
true, I'm finding that now...
There was a problem hiding this comment.
Generally type systems eliminate the need to do things like that. But you can do one of two things in that scenario:
- Use Flow's
suppress_commentoption - Pass the value through
anyto stop type checking – I'd recommend doing this along with a comment explaining why itanyis needed. Usinganymeans you're less tied to configuration
function method(value: string) {
if (typeof value === 'number') throw new TypeError('Support for numbers has been removed');
return value;
}
test('throws deprecation error', () => {
expect(() => {
// Passing through `any` because we want to make sure we're throwing an error.
method((42: any));
}).toThrow(TypeError);
});| breakpoints: I.Map<string, Breakpoint>, | ||
| pendingBreakpoints: any[], | ||
| breakpointsDisabled: false | ||
| }; |
There was a problem hiding this comment.
There are still a lot of anys, especially for callback functions and items stored in Immutable structures. Might be good to either review if they are trivially removable or, if there are real impediments, make a list of what they are.
There was a problem hiding this comment.
Yes - there are. We should file bugs based on some of these next steps
| * **80+** coverage | ||
| * **60** files of coverage | ||
|
|
||
| We use Jest to test our react Component. We mostly do snapshot testing to |
| 2. **defaultProps** and other class properties. | ||
|
|
||
| Overall, typing our components has been a nice win though as it gives us additional confidence our UI will behave appropriately and catches several lifecycle edge-cases | ||
| where properties could be null or racey. |
There was a problem hiding this comment.
I think this means that some related data can be set in a non-deterministic order based on how async actions happen to fire. (Especially true for things like parsing that happen in a separate web worker thread.) Flow makes us declare which things have to be present together and prove that all possible state transitions meet those rules.
There was a problem hiding this comment.
Might want to explain it a bit more
Codecov Report
@@ Coverage Diff @@
## master #2780 +/- ##
=========================================
Coverage ? 47.59%
=========================================
Files ? 97
Lines ? 4036
Branches ? 828
=========================================
Hits ? 1921
Misses ? 2115
Partials ? 0Continue to review full report at Codecov.
|
Summary of Changes
This starts a blog post on the state of our testing and type coverage. I hope to write one quarterly to summarize our progress and next steps.
This is helping me better understand what some good next steps are:
Statetypes in our actions