mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
Merge pull request #82 from prymitive/error-limit
fix(ui): don't let multiple exceptions set multiple timers
This commit is contained in:
@@ -35,6 +35,7 @@ class ErrorBoundary extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.timer = null;
|
||||
this.state = { cachedError: null, reloadSeconds: 60 };
|
||||
}
|
||||
|
||||
@@ -55,7 +56,10 @@ class ErrorBoundary extends Component {
|
||||
});
|
||||
Sentry.captureException(error);
|
||||
// reload after 60s, this is to fix wall monitors automatically
|
||||
setInterval(this.reloadApp, 1000);
|
||||
// but only if the timer isn't set yet
|
||||
if (this.timer === null) {
|
||||
this.timer = setInterval(this.reloadApp, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -70,4 +70,19 @@ describe("<ErrorBoundary />", () => {
|
||||
expect(reloadSpy).toHaveBeenCalled();
|
||||
expect(consoleSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reloadSeconds is 40 after 20s with multiple exceptions", () => {
|
||||
jest.spyOn(console, "error").mockImplementation(() => {});
|
||||
const tree = MountedFailingComponent();
|
||||
const instance = tree.instance();
|
||||
|
||||
instance.componentDidCatch("foo", { foo: "bar" });
|
||||
jest.runTimersToTime(1000 * 10);
|
||||
instance.componentDidCatch("foo", { foo: "bar" });
|
||||
jest.runTimersToTime(1000 * 5);
|
||||
instance.componentDidCatch("foo", { foo: "bar" });
|
||||
jest.runTimersToTime(1000 * 5);
|
||||
instance.componentDidCatch("foo", { foo: "bar" });
|
||||
expect(tree.instance().state.reloadSeconds).toBe(40);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user