mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
29085895c9
The `tools/node_compat/node` submodule has been moved to `tests/node_compat/runner/suite` and the remaining files within `tools/node_compat` to `tests/node_compat/runner`. Most of the changes are of the header within `tests/node_compat/test` files. The `setup` and `test` tasks within `tests/node_comapt` execute successfully. Towards #22525 CC @mmastrac
40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
// deno-fmt-ignore-file
|
||
// deno-lint-ignore-file
|
||
|
||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||
// Taken from Node 18.12.1
|
||
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
|
||
|
||
'use strict';
|
||
const common = require('../common');
|
||
const assert = require('assert');
|
||
const { MessageChannel, receiveMessageOnPort } = require('worker_threads');
|
||
|
||
const { port1, port2 } = new MessageChannel();
|
||
|
||
const message1 = { hello: 'world' };
|
||
const message2 = { foo: 'bar' };
|
||
|
||
// Make sure receiveMessageOnPort() works in a FIFO way, the same way it does
|
||
// when we’re using events.
|
||
assert.strictEqual(receiveMessageOnPort(port2), undefined);
|
||
port1.postMessage(message1);
|
||
port1.postMessage(message2);
|
||
assert.deepStrictEqual(receiveMessageOnPort(port2), { message: message1 });
|
||
assert.deepStrictEqual(receiveMessageOnPort(port2), { message: message2 });
|
||
assert.strictEqual(receiveMessageOnPort(port2), undefined);
|
||
assert.strictEqual(receiveMessageOnPort(port2), undefined);
|
||
|
||
// Make sure message handlers aren’t called.
|
||
port2.addEventListener('message', common.mustNotCall());
|
||
port1.postMessage(message1);
|
||
assert.deepStrictEqual(receiveMessageOnPort(port2), { message: message1 });
|
||
port1.close();
|
||
|
||
for (const value of [null, 0, -1, {}, []]) {
|
||
assert.throws(() => receiveMessageOnPort(value), {
|
||
name: 'TypeError',
|
||
code: 'ERR_INVALID_ARG_TYPE',
|
||
message: 'The "port" argument must be a MessagePort instance'
|
||
});
|
||
}
|