Commit f16678ec authored by Robert Knight's avatar Robert Knight

Use an Error-like object rather than an actual Error in a test

This fixes a slow test on this branch, which appears to be caused by an
interaction between using `postMessage` to serialize native Error
objects and the `source-map-support` Karma plugin that we use.

Sending native Errors via `PortRPC` currently doesn't work in all
browsers so I expect we'll want to implement our own serialization of
errors in `PortRPC` to work around that. That can also work around the
`source-map-support`/`postMessage` issue in Chrome in future.

To move the Browserify => Rollup conversion forwards, this commit just
changes the test to use an Error-like rather than actual Error object.
parent f83ad4af
......@@ -114,8 +114,13 @@ describe('PortRPC-Bridge integration', () => {
it('no longer sends RPC messages to a Bridge channel that has received an error', async () => {
const bridge = createBridge();
const reciprocalBridge = createBridge();
// nb. We send an Error-like object here rather than an error because
// not all browsers (as of 2021-10) support structured cloning of Errors.
// It would be useful to handle this in `PortRPC`.
// See https://github.com/hypothesis/client/pull/3810#issuecomment-940910472.
const errorMessage = 'My error';
bridge.on('method1', (_arg, cb) => cb(new Error(errorMessage)));
bridge.on('method1', (_arg, cb) => cb({ message: errorMessage }));
bridge.createChannel(port1);
const channel = reciprocalBridge.createChannel(port2);
sinon.stub(channel, 'call').callThrough();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment