0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/test/parallel/test-worker-message-port-transfer-target.js
Ruben Bridgewater baa4b9b425
test: refactor common.expectWarning()
The current API is somewhat confusing at times and simpler usage is
possible. This overloads the arguments further to accept objects
with deprecation codes as property keys. It also adds documentation
for the different possible styles.

Besides that it is now going to validate for the code being present
in case of deprecations but not for other cases. The former validation
was not consistent as it only validated some cases and accepted
undefined instead of `common.noWarnCode`. This check is removed due to
the lack of consistency. `common.noWarnCode` is completely removed
due to just being sugar for `undefined`.

This also verifies that the warning order is identical to the order
in which they are triggered.

PR-URL: https://github.com/nodejs/node/pull/25251
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-01-10 03:22:12 +01:00

23 lines
734 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { MessageChannel } = require('worker_threads');
const { port1, port2 } = new MessageChannel();
const arrayBuf = new ArrayBuffer(10);
common.expectWarning('Warning',
'The target port was posted to itself, and the ' +
'communication channel was lost');
port2.onmessage = common.mustNotCall();
port2.postMessage(null, [port1, arrayBuf]);
// arrayBuf must be transferred, despite the fact that port2 never received the
// message.
assert.strictEqual(arrayBuf.byteLength, 0);
setTimeout(common.mustNotCall('The communication channel is still open'),
common.platformTimeout(1000)).unref();