lensesio / cypress-websocket-testing

Test WebSocket connections with Cypress
Apache License 2.0
83 stars 12 forks source link

I keep getting results as undefined #24

Open kerimdragolj opened 2 years ago

kerimdragolj commented 2 years ago

Hello, I keep getting undefined as result inside of streamRequest code below, even tho I can see in the network that connection is established and I do receive messages

options = {
      takeWhileFn: (message: IMessage) => message && message.type !== "end",
      startUpMessage: {
        id: '9999',
        type: 'start',
        payload: {
          operationName: 'OnUpdateGame',
          query:
            'subscription OnUpdateGame {\n  updateGame {\n    game {\n      ...Game\n      __typename\n    }\n    __typename\n  }\n}\n\nfragment Game on Game {\n  id\n  createdAt\n  scheduledAt\n  status\n  rollValue\n  __typename\n}\n',
        },
      },
    };

cy.wrap(null, { timeout: 20000 }).then(() =>
      cy.streamRequest<IMessage>(config, options).then(results => {
        console.log(results);
        cy.log(JSON.stringify(results));
      })
    );

image

Also Im confused if IMessage interface is supposted to represent messages we get from api or not (if we are able to addapt properties of IMessage to the message that we are getting from our endpoint)? Also why something like takeWhileFn: (message: IMessage) => true, doesnt work, it resolves immediatelly, but i was expecting it to go infinitely? Is there a way to implement this with stream instead of streamRequest, because with stream I dont see a way to subscribe to event (pass startUpMessage)?

dsebastian commented 2 years ago

Hi @kerimdragolj ,sorry for the late reply, missed the messages. For the first question: is it possible to do a mock example to play with? Also does the BE receive properly the startupMessage? For the second: yes, IMessage is the message you get back from the server and is a generic that you can customise. For the third again I would need to be able to reproduce it. If you take the example and change the return to true, you will see that it goes on indefinately.