Skip to content

Commit

Permalink
remove async/await from client code
Browse files Browse the repository at this point in the history
  • Loading branch information
darthfiddler committed Jun 19, 2018
1 parent 10abff0 commit 6194986
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/client/debug/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,16 @@ export class Debug extends React.Component {
);
}

simulate = async (iterations = 10000, sleepTimeout = 100) => {
function sleep() {
return new Promise(resolve => setTimeout(resolve, sleepTimeout));
}

for (let i = 0; i < iterations; i++) {
simulate = (iterations = 10000, sleepTimeout = 100) => {
const step = () => {
const action = this.props.step();
if (!action) break;
await sleep(100);
}
if (action && iterations > 1) {
iterations--;
setTimeout(step, sleepTimeout);
}
};

step();
};

renderControls() {
Expand Down
8 changes: 6 additions & 2 deletions src/client/debug/debug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ test('toggle AIDebug', () => {
});

describe('simulate', () => {
jest.useFakeTimers();

test('basic', () => {
const step = jest.fn(() => true);
Enzyme.mount(
Expand All @@ -319,7 +321,8 @@ describe('simulate', () => {
);
expect(step).not.toHaveBeenCalled();
Mousetrap.simulate('5');
expect(step).toHaveBeenCalled();
jest.runAllTimers();
expect(step).toHaveBeenCalledTimes(10000);
});

test('break out if no action is returned', () => {
Expand All @@ -335,6 +338,7 @@ describe('simulate', () => {

expect(step).not.toHaveBeenCalled();
Mousetrap.simulate('5');
expect(step).toHaveBeenCalled();
jest.runAllTimers();
expect(step).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 6194986

Please sign in to comment.