Skip to content
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

[test-runner/dev-server] JSON.stringify in web socket plugin fails on circular references in object #1356

Open
Nivisnum opened this issue Mar 15, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@Nivisnum
Copy link

Nivisnum commented Mar 15, 2021

Hello!
I've recently started to migrate our tests to web-test-runner (thank you very much for it!) but I've stumbled across a possible bug when I've added chai-dom plugin - whenever assertion on DOM element fails, this plugin returns to the test runner the DOM element in the message object. It then silently fails and test case hangs until the timeout.

Expected behavior:

When assertion fails, the message gets back to test runner and shows assertion error.

Current behavior:

When assertion fails, the sendMessage in web socket plugin throws; the test hangs after finish until the timeout and shows error:

 ❌ Browser tests did not finish within 120000ms. You can increase this timeout with the testsFinishTimeout option. Check the browser logs or open the browser in debug mode for more information. 

When debugging browser throws:

Uncaught TypeError: Converting circular structure to JSON

Where it breaks:

Call to JSON.stringify

sendMessage = async (message) => {
if (!message.type) {
throw new Error('Missing message type');
}
await webSocketOpened;
webSocket.send(JSON.stringify(message));
}

It might possibly break here too:

function setupFetch() {
sendMessage = (message) =>fetch('/__web-test-runner__/wtr-legacy-browser-api', { method: 'POST', body: JSON.stringify(message) });
sendMessageWaitForResponse = (message) => fetch('/__web-test-runner__/wtr-legacy-browser-api', { method: 'POST', body: JSON.stringify(message) });
}

Why it breaks:

It seems there is possibility that message may contain circular references. I've seen that there is a mechanism for serialization in code base that solves it, but I'm not sure if this applies to this flow.

This was mentioned in #437 (comment) after the issue got closed.

I could try contributing a fix (with a bit of guidance where it should be fixed - in plugin on dev server side or in test runner) 😃

@LarsDenBakker LarsDenBakker added the bug Something isn't working label Apr 23, 2021
@LarsDenBakker
Copy link
Member

LarsDenBakker commented Apr 23, 2021

At the least we should have a try catch for this, but it would be nice if we can handle these messages in a proper way as well. The try catch can be added in the code you linked.

@rbquantori
Copy link

It looks like the problem is, actually, not in those mentioned places but rather in Mocha: mochajs/mocha#4910

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants