Skip to content

Commit

Permalink
fix(dev-server-core): fix readonly error serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaelin committed May 12, 2024
1 parent 6a97a69 commit 4a4b699
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cool-terms-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/dev-server-core': patch
---

Fix readonly object serialization
Original file line number Diff line number Diff line change
@@ -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);
})
12 changes: 12 additions & 0 deletions integration/test-runner/tests/test-failure/runTestFailureTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}
});
});
}
3 changes: 2 additions & 1 deletion packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4a4b699

Please sign in to comment.