-
-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEW TEST] WebSockets #14
Comments
A very simple websocket server (single enpoint). Client and server code written and ready to play with fix #14
A very simple websocket server (single enpoint). Client and server code written and ready to play with fix #14
Tere is an issue with e2e testing. To be honest, I can't understand, why this: And what about adding about more "websocket" test. In this test event just return result like usual http endpoint. It'd be more interesting to return WsResponse (emit another event as an answer to subscribed event). |
@ShGKme I'll be 100% honest, I'm not completely sure how it works myself. I believe it has something to do with |
@jmcdo29 // It's an async test, so, it except Promise to be resolved.
it('should call message', async () => {
// Connect to socket server (what server? does it know an address?)
const socket = io.connect();
// Does we connect successfully? connect never throw error itself...
//Ok, let's emit a message
socket.emit('message', { name: 'Test' }, (data) => {
// (!)When(!) it'll receive an acknowledgement, we will check, that it's correct
expect(data).toBe('Hello, Test!');
});
// (!) If we won't receive any acknowledgement from message event, we will check nothing :D
// By the way, disconnect doesn't return Promise.
return socket.disconnect();
}); The test will finish earler, than we will receive anything and won't check for any errors.
More fun? This will pass :D it('should call message', async () => {
const socket = io.connect('http://THE_URL_THAT_DOES_NOT_EXISTS:67000');
socket.emit('NO-EVENT', { name: 'Test' }, (data) => {
expect(data).toBe('LITERALLY ANY VALUE');
throw new Error('JUST GO THROW AN ERROR HERE');
});
return socket.disconnect();
}); I will make my example soon today. |
@jmcdo29 Check out this repository: Or this repl (run it in browser): |
Because I was using `io.connect()` without a properport, socketIo was not properly disconnecting after the test. Now that I am useing `io.connect(await app.getUrl())` everything works just fine fix #14
Because I was using `io.connect()` without a properport, socketIo was not properly disconnecting after the test. Now that I am useing `io.connect(await app.getUrl())` everything works just fine fix #14
* chore: moves to eslint and starts dockerization * fix(websocket): fix jest not exiting properly Because I was using `io.connect()` without a properport, socketIo was not properly disconnecting after the test. Now that I am useing `io.connect(await app.getUrl())` everything works just fine fix #14 * ci: starts dockerizing the e2e testing process I'm tired of seeing CRON failures so I'm also adding in the necessary service to the cron.yml for the moment. I'll get it all fixed in the future * test(typeorm): fixes up typeorm e2e tests with docker-compose * feat: removes typeorm-graphql-sample The TypeOrm-GraphQL-Sample project is removed as there is no need for two sample projects to use TypeORM. The point of the repository is to show how testing can be done with NestJS. As there is a fully working typeorm-sample project and a graphql-sample project, there is no need to combine the two. BREAKING CHANGE: removal of the typeorm-graphql-sample * feat(e2e): adds docker-compose for e2e tests There's still some bugs with how the microservices tests were implemented, I'll need to spend more time on that, but now the TypeORM test has an actual database to query and use. Mongo is next, but I want to get rid of the failing CRON test for now. * fix: fixes microservice tests
Feature Test To Be Requested
A test repository showing how to test web sockets could be really useful for some people. Full End to End testing too if possible
The text was updated successfully, but these errors were encountered: