modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.15k stars 271 forks source link

[@web/test-runner] Tests do not finish when asserting frozen objects #2728

Closed lucaelin closed 1 month ago

lucaelin commented 1 month ago

When asserting frozen objects in WTR, the test-file never finishes according to the cli. Here is a test-case:

import { expect } from '@open-wc/testing';

describe('readonly', () => {
  it('gets stuck when throwing readonly array of objects', () => {
    const obj = [
            {}
        ];
    const frozenObj = Object.freeze(obj);
    expect(frozenObj).to.be.empty;
  });
})

When running this test in puppeteer or playwright, the test never finshes. When inspecting the test-browsers devtools, you can see the following error message: image

The error seems to originate in a websocket handler, that tries to stringify the error message while skipping circular structures. The stringified object is then send to the wtr-cli for printing. But the decircularization and stringification failes in this case, because the target error message is not mutable.

I've uploaded a working repro of this bug in this repo: https://github.com/lucaelin/wtr-readonly-error-bug

A possible solution is also included in the repository, by first running structuredClone on the input prior to stringification.