0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-worker-message-event.js
Khafra ae8a5ffcfa
deps: update undici to 6.15.0
PR-URL: https://github.com/nodejs/node/pull/52763
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2024-05-02 17:21:22 +00:00

95 lines
2.6 KiB
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const dummyPort = new MessageChannel().port1;
{
for (const [ args, expected ] of [
[
['message'],
{
type: 'message', data: null, origin: '',
lastEventId: '', source: null, ports: []
},
],
[
['message', { data: undefined, origin: 'foo' }],
{
type: 'message', data: null, origin: 'foo',
lastEventId: '', source: null, ports: []
},
],
[
['message', { data: 2, origin: 1, lastEventId: 0 }],
{
type: 'message', data: 2, origin: '1',
lastEventId: '0', source: null, ports: []
},
],
[
['message', { lastEventId: 'foo' }],
{
type: 'message', data: null, origin: '',
lastEventId: 'foo', source: null, ports: []
},
],
[
['messageerror', { lastEventId: 'foo', source: dummyPort }],
{
type: 'messageerror', data: null, origin: '',
lastEventId: 'foo', source: dummyPort, ports: []
},
],
[
['message', { ports: [dummyPort], source: null }],
{
type: 'message', data: null, origin: '',
lastEventId: '', source: null, ports: [dummyPort]
},
],
]) {
const ev = new MessageEvent(...args);
const { type, data, origin, lastEventId, source, ports } = ev;
assert.deepStrictEqual(expected, {
type, data, origin, lastEventId, source, ports
});
}
}
{
assert.throws(() => {
new MessageEvent('message', { source: 1 });
}, {
name: 'TypeError',
message: /MessageEvent constructor: Expected eventInitDict\.source \("1"\) to be an instance of MessagePort\./,
});
assert.throws(() => {
new MessageEvent('message', { source: {} });
}, {
name: 'TypeError',
message: /MessageEvent constructor: Expected eventInitDict\.source \("\{\}"\) to be an instance of MessagePort\./,
});
assert.throws(() => {
new MessageEvent('message', { ports: 0 });
}, {
message: /MessageEvent constructor: eventInitDict\.ports \(0\) is not iterable\./,
});
assert.throws(() => {
new MessageEvent('message', { ports: [ null ] });
}, {
name: 'TypeError',
message: /MessageEvent constructor: Expected eventInitDict\.ports(\[0\])? \("null"\) to be an instance of MessagePort\./,
});
assert.throws(() => {
new MessageEvent('message', { ports: [ {} ] });
}, {
name: 'TypeError',
message: /MessageEvent constructor: Expected eventInitDict\.ports(\[0\])? \("\{\}"\) to be an instance of MessagePort\./,
});
}
{
assert(new MessageEvent('message') instanceof Event);
}