make db interface async#86
Conversation
|
Sorry, I haven't had time to look more closely at this. Are you stuck trying to fix the tests? |
| }); | ||
|
|
||
| test('action', () => { | ||
| test('action', async () => { |
There was a problem hiding this comment.
async not needed, because not await exist
There was a problem hiding this comment.
Agree, but I forgot to remove it after I clean await s when it didn't work
| // Sync causes the server to respond. | ||
| expect(io.socket.emit).toHaveBeenCalledTimes(0); | ||
| io.socket.receive('sync', 'gameID'); | ||
| expect(io.socket.emit).toHaveBeenCalledTimes(1); |
There was a problem hiding this comment.
Hi @nicolodavis sorry for my delayed reply
Wrapping this assertion inside a timeout works fine but I think there should be a better solution for async behavior of socket callbacks
There was a problem hiding this comment.
Just use await in the tests. The trick is to make the function explicitly have a return statement. Then you can use await to wait for its execution and then test what it did. I wrapped receive in this way to make the tests to work.
| "babel-plugin-external-helpers": "^6.22.0", | ||
| "babel-plugin-module-resolver": "^3.0.0", | ||
| "babel-plugin-transform-es2015-modules-commonjs": "^6.26.0", | ||
| "babel-polyfill": "^6.26.0", |
There was a problem hiding this comment.
Is it possible to do this without babel-polyfill? Recent versions of Node support async / await out of the box.
There was a problem hiding this comment.
After running examples I got regeneratorRuntime error.
I tried to solve it by testing all options from babel docs and finally this one worked.
There was a problem hiding this comment.
babel-polyfill shouldn't be used in a library, so we should find another way to do this. Have you tried babel-preset-env?
There was a problem hiding this comment.
The other option would be to not use Babel on anything in src/server and write it without ES5 features. I can take a look at this later.
|
I think this is working correctly now! |
* persist game state inside db * undo some unnecessary changes * fix merge * fix tests * no babel on src/server * reset package-lock.json * remove stage-0 preset
No description provided.