Skip to content

Commit feb0c72

Browse files
authored
Merge pull request #2731 from lucaelin/fix/readonly-error
fix(dev-server-core): fix readonly error serialization
2 parents 6a97a69 + 4a4b699 commit feb0c72

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

.changeset/cool-terms-exercise.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/dev-server-core': patch
3+
---
4+
5+
Fix readonly object serialization
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { expect } from '../../../../../node_modules/@esm-bundle/chai/esm/chai.js';
2+
3+
it('readonly actual', function() {
4+
const fixture = Object.freeze({x: {}});
5+
expect(fixture).to.equal(null);
6+
})

integration/test-runner/tests/test-failure/runTestFailureTest.ts

+12
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,17 @@ export function runTestFailureTest(
208208
expect(session.errors).to.eql([ERROR_NOT_IMPORTABLE]);
209209
}
210210
});
211+
212+
it('handles tests that error with a readonly actual', () => {
213+
const sessions = allSessions.filter(s => s.testFile.endsWith('fail-readonly-actual.test.js'));
214+
expect(sessions.length === browserCount).to.equal(true);
215+
for (const session of sessions) {
216+
expect(session.testResults!.tests.map(t => t.name)).to.eql(['readonly actual']);
217+
expect(session.passed).to.be.false;
218+
expect(session.testResults!.tests![0].error!.message).to.equal(
219+
'expected { x: {} } to equal null',
220+
);
221+
}
222+
});
211223
});
212224
}

packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export function webSocketsPlugin(): Plugin {
4040
}
4141
4242
export function stable (obj, replacer, spacer) {
43-
var tmp = deterministicDecirc(obj, '', [], undefined) || obj
43+
var target = structuredClone(obj)
44+
var tmp = deterministicDecirc(target, '', [], undefined) || target
4445
var res
4546
if (replacerStack.length === 0) {
4647
res = JSON.stringify(tmp, replacer, spacer)

0 commit comments

Comments
 (0)