Skip to content

Commit e8a16a1

Browse files
committed
Fix Console Hang
1 parent cf4661e commit e8a16a1

5 files changed

Lines changed: 315 additions & 280 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"devtools-source-editor": "0.0.7",
8080
"devtools-source-map": "^0.14.5",
8181
"devtools-splitter": "^0.0.5",
82-
"devtools-utils": "^0.0.9",
82+
"devtools-utils": "^0.0.10",
8383
"fuzzaldrin-plus": "^0.4.1",
8484
"immutable": "^3.7.6",
8585
"lodash": "^4.17.4",

src/actions/ast.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ export function setSymbols(sourceId: SourceId) {
7676
source,
7777
symbols
7878
});
79+
80+
dispatch(setEmptyLines(source.id));
81+
dispatch(setSourceMetaData(source.id));
7982
};
8083
}
8184

src/actions/sources/loadSourceText.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// @flow
66

77
import { PROMISE } from "../utils/middleware/promise";
8-
import { setEmptyLines, setSymbols, setSourceMetaData } from "../ast";
8+
import { setSymbols } from "../ast";
99
import { getSource } from "../../selectors";
1010
import { setSource } from "../../workers/parser";
1111
import type { Source } from "../../types";
@@ -48,8 +48,6 @@ export function loadSourceText(source: Source) {
4848
}
4949

5050
await setSource(newSource);
51-
await dispatch(setSymbols(source.id));
52-
await dispatch(setEmptyLines(source.id));
53-
await dispatch(setSourceMetaData(source.id));
51+
dispatch(setSymbols(source.id));
5452
};
5553
}

src/actions/tests/ast.spec.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
/* eslint max-nested-callbacks: ["error", 6] */
2+
13
import {
24
createStore,
35
selectors,
46
actions,
5-
makeSource
7+
makeSource,
8+
waitForState
69
} from "../../utils/test-head";
710

811
import readFixture from "./helpers/readFixture";
@@ -48,42 +51,64 @@ const evaluationResult = {
4851
describe("ast", () => {
4952
describe("setEmptyLines", () => {
5053
it("scopes", async () => {
51-
const { dispatch, getState } = createStore(threadClient);
54+
const store = createStore(threadClient);
55+
const { dispatch, getState } = store;
56+
5257
const source = makeSource("scopes.js");
5358
await dispatch(actions.newSource(source));
5459
await dispatch(actions.loadSourceText({ id: "scopes.js" }));
5560

61+
await waitForState(store, state => {
62+
const lines = getEmptyLines(state, source);
63+
return lines && lines.length > 0;
64+
});
65+
5666
const emptyLines = getEmptyLines(getState(), source);
5767
expect(emptyLines).toMatchSnapshot();
5868
});
5969
});
6070
describe("setSourceMetaData", () => {
6171
it("should detect react components", async () => {
62-
const { dispatch, getState } = createStore(threadClient);
72+
const store = createStore(threadClient);
73+
const { dispatch, getState } = store;
6374
const source = makeSource("reactComponent.js");
6475
await dispatch(actions.newSource(source));
76+
6577
await dispatch(actions.loadSourceText({ id: "reactComponent.js" }));
78+
await waitForState(store, state => {
79+
const metaData = getSourceMetaData(state, source.id);
80+
return metaData && metaData.isReactComponent;
81+
});
6682

6783
const sourceMetaData = getSourceMetaData(getState(), source.id);
6884
expect(sourceMetaData).toEqual({ isReactComponent: true });
6985
});
86+
7087
it("should not give false positive on non react components", async () => {
71-
const { dispatch, getState } = createStore(threadClient);
88+
const store = createStore(threadClient);
89+
const { dispatch, getState } = store;
7290
const source = makeSource("base.js");
7391
await dispatch(actions.newSource(source));
7492
await dispatch(actions.loadSourceText({ id: "base.js" }));
93+
await waitForState(store, state => {
94+
const metaData = getSourceMetaData(state, source.id);
95+
return metaData && metaData.isReactComponent === false;
96+
});
7597

7698
const sourceMetaData = getSourceMetaData(getState(), source.id);
7799
expect(sourceMetaData).toEqual({ isReactComponent: false });
78100
});
79101
});
102+
80103
describe("setSymbols", () => {
81104
describe("when the source is loaded", () => {
82105
it("should be able to set symbols", async () => {
83-
const { dispatch, getState } = createStore(threadClient);
106+
const store = createStore(threadClient);
107+
const { dispatch, getState } = store;
84108
const base = makeSource("base.js");
85109
await dispatch(actions.newSource(base));
86110
await dispatch(actions.loadSourceText({ id: "base.js" }));
111+
await waitForState(store, state => getSymbols(state, base));
87112

88113
const baseSymbols = getSymbols(getState(), base);
89114
expect(baseSymbols).toMatchSnapshot();

0 commit comments

Comments
 (0)