Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test native <-> polyfill publish/subscribe #7

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions test/cross-communication.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const test = require('tape');

const { hasDiagnosticsChannel } = require('../checks');

if (!hasDiagnosticsChannel()) {
test('cross-communication', t => {
t.comment(`The current version of Node.js, ${process.version}, does not include diagnostics_channel. Skipping test.`);
t.end();
});

return;
}

const polyfill = require('../dc-polyfill.js');
const native = require('../dc-polyfill.js');

test('subscribe in native, publish from polyfill', t => {
const native_ch = native.channel('foo');
const polyfill_ch = polyfill.channel('foo');

t.equal(native_ch.hasSubscribers, false, 'native ch should have no subscribers yet');
t.equal(polyfill_ch.hasSubscribers, false, 'polyfill ch should have no subscribers yet');

native.subscribe('foo', (msg) => {
t.equal(msg, 'bar');
t.end();
});

t.equal(native_ch.hasSubscribers, true, 'native ch should now have subscribers');
t.equal(polyfill_ch.hasSubscribers, true, 'polyfill ch should now have subscribers');

polyfill_ch.publish('bar');
});

test('subscribe in polyfill, publish from native', t => {
const native_ch = native.channel('foo2');
const polyfill_ch = polyfill.channel('foo2');

t.equal(native_ch.hasSubscribers, false, 'native ch should have no subscribers yet');
t.equal(polyfill_ch.hasSubscribers, false, 'polyfill ch should have no subscribers yet');

polyfill.subscribe('foo2', (msg) => {
t.equal(msg, 'bar');
t.end();
});

t.equal(native_ch.hasSubscribers, true, 'native ch should now have subscribers');
t.equal(polyfill_ch.hasSubscribers, true, 'polyfill ch should now have subscribers');

native_ch.publish('bar');
});

Loading