microsoft/BotFramework-DirectLineJS

Mocking the WebSocket URL for end to end testing using playwright/cypress.

Closed this issue · 2 comments

Hey,

I have my Directline object define like this for testing purposes:

    const line = new DirectLine({
      token: token,
      conversationStartProperties: {
        locale: window.navigator.language
      },
      domain:
        process.env['NODE_ENV'] === 'development'
          ? 'http://localhost:3002/mock/v3/directline'
          : undefined
    });

It does successfully changed all the URL on those HTTP calls to localhost, but not the wss: route.

Is there a way we can change the wss route also to locahost so we can use a mock server to perform full end to end testing?

@hughyyyy - Thank you for your patience. I was just reviewing the code and you are right in that changing the domain property does not affect the streamUrl. And, unfortunately, there is no workaround that includes the domain property.

However, that being said, there may be a way to make this work. The DirectLine class exposes the streamUrl property making it available to pass in a value. This means that you could generate your own streamUrl that includes the domain of your mock server. For this, you would need to run a Web Socket server, probably with your mock server, so that when the generated DirectLine object in Web Chat attempts to connect it does so with your mock server and not with the DirectLine service.

If you decide on trying this, I don't know if it is necessary to structure the streamUrl similarly to an actual streamUrl. I also don't know what generates the associated token used in its construction as the actual streamUrl comes from the DirectLine service.

One possible way to mitigate this would be to generate a DirectLine object, access its streamUrl, swap out the domain in the string to that of your Web Socket server, and then use that for testing.

Anyhow, I hope this is helpful. But please be aware that this is theoretical and is presented in the hopes of moving your forward as I'm not in a position to test this.

Closing as resolved.