From 4a4b6995350eaef920d85924ffbf99a030c231e9 Mon Sep 17 00:00:00 2001 From: Luca Haneklau Date: Sun, 12 May 2024 21:36:51 +0200 Subject: [PATCH] fix(dev-server-core): fix readonly error serialization --- .changeset/cool-terms-exercise.md | 5 +++++ .../browser-tests/fail-readonly-actual.test.js | 6 ++++++ .../tests/test-failure/runTestFailureTest.ts | 12 ++++++++++++ .../src/web-sockets/webSocketsPlugin.ts | 3 ++- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .changeset/cool-terms-exercise.md create mode 100644 integration/test-runner/tests/test-failure/browser-tests/fail-readonly-actual.test.js diff --git a/.changeset/cool-terms-exercise.md b/.changeset/cool-terms-exercise.md new file mode 100644 index 000000000..7af291bbb --- /dev/null +++ b/.changeset/cool-terms-exercise.md @@ -0,0 +1,5 @@ +--- +'@web/dev-server-core': patch +--- + +Fix readonly object serialization diff --git a/integration/test-runner/tests/test-failure/browser-tests/fail-readonly-actual.test.js b/integration/test-runner/tests/test-failure/browser-tests/fail-readonly-actual.test.js new file mode 100644 index 000000000..70fa5e72b --- /dev/null +++ b/integration/test-runner/tests/test-failure/browser-tests/fail-readonly-actual.test.js @@ -0,0 +1,6 @@ +import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js'; + +it('readonly actual', function() { + const fixture = Object.freeze({x: {}}); + expect(fixture).to.equal(null); +}) diff --git a/integration/test-runner/tests/test-failure/runTestFailureTest.ts b/integration/test-runner/tests/test-failure/runTestFailureTest.ts index 50aad98ca..85be1a0c2 100644 --- a/integration/test-runner/tests/test-failure/runTestFailureTest.ts +++ b/integration/test-runner/tests/test-failure/runTestFailureTest.ts @@ -208,5 +208,17 @@ export function runTestFailureTest( expect(session.errors).to.eql([ERROR_NOT_IMPORTABLE]); } }); + + it('handles tests that error with a readonly actual', () => { + const sessions = allSessions.filter(s => s.testFile.endsWith('fail-readonly-actual.test.js')); + expect(sessions.length === browserCount).to.equal(true); + for (const session of sessions) { + expect(session.testResults!.tests.map(t => t.name)).to.eql(['readonly actual']); + expect(session.passed).to.be.false; + expect(session.testResults!.tests![0].error!.message).to.equal( + 'expected { x: {} } to equal null', + ); + } + }); }); } diff --git a/packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts b/packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts index d2ca58aa3..ce760d4db 100644 --- a/packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts +++ b/packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts @@ -40,7 +40,8 @@ export function webSocketsPlugin(): Plugin { } export function stable (obj, replacer, spacer) { - var tmp = deterministicDecirc(obj, '', [], undefined) || obj + var target = structuredClone(obj) + var tmp = deterministicDecirc(target, '', [], undefined) || target var res if (replacerStack.length === 0) { res = JSON.stringify(tmp, replacer, spacer)