Skip to content

Commit

Permalink
Support pasting of dumps from the simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jul 24, 2019
1 parent 5b5e431 commit 88d8f4c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class App extends React.Component<Props, State> {

this.setState({ source: source, explain: explain, problem: "" });
} catch (e) {
this.setState({ source: this.state.source, explain: null, problem: e });
this.setState({ source: this.state.source, explain: null, problem: e.message });
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/utils/GoFlow.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ReadSession } from './GoFlow';

it('loads session from JSON', () => {
// loads when top-level object is session
expect(ReadSession('{"status": "complete", "runs": []}')).toMatchObject({ status: "complete", runs: [] });

// loads when session is nested object
expect(ReadSession('{"session": {"status": "complete", "runs": []}}')).toMatchObject({ status: "complete", runs: [] });
})
5 changes: 5 additions & 0 deletions src/utils/GoFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export function ReadSession(src: string): Session {
throw new Error(`invalid JSON: ${e}`);
}

// could be an output from simulator which has nested session
if (typeof obj.session === "object") {
obj = obj.session
}

if (!isSession(obj)) {
throw new Error("not a valid session object")
}
Expand Down

0 comments on commit 88d8f4c

Please sign in to comment.