This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: apply suggestions from code review
Co-authored-by: Jacob Heun <[email protected]>
- Loading branch information
1 parent
f209d04
commit d5ffc49
Showing
8 changed files
with
93 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const { expect } = require('aegir/utils/chai') | ||
|
||
const { | ||
createPeerId, | ||
mockRegistrar, | ||
PubsubImplementation | ||
} = require('./utils') | ||
|
||
const uint8ArrayFromString = require('uint8arrays/from-string') | ||
|
||
const protocol = '/pubsub/1.0.0' | ||
const topic = 'foo' | ||
const data = uint8ArrayFromString('bar') | ||
const shouldNotHappen = (_) => expect.fail() | ||
|
||
describe('emitSelf', () => { | ||
let pubsub | ||
|
||
describe('enabled', () => { | ||
before(async () => { | ||
const peerId = await createPeerId() | ||
|
||
pubsub = new PubsubImplementation(protocol, { | ||
peerId, | ||
registrar: mockRegistrar | ||
}, { emitSelf: true }) | ||
}) | ||
|
||
before(() => { | ||
pubsub.start() | ||
pubsub.subscribe(topic) | ||
}) | ||
|
||
after(() => { | ||
pubsub.stop() | ||
}) | ||
|
||
it('should emit to self on publish', () => { | ||
const promise = new Promise((resolve) => pubsub.once(topic, resolve)) | ||
|
||
pubsub.publish(topic, data) | ||
|
||
return promise | ||
}) | ||
}) | ||
|
||
describe('disabled', () => { | ||
before(async () => { | ||
const peerId = await createPeerId() | ||
|
||
pubsub = new PubsubImplementation(protocol, { | ||
peerId, | ||
registrar: mockRegistrar | ||
}, { emitSelf: false }) | ||
}) | ||
|
||
before(() => { | ||
pubsub.start() | ||
pubsub.subscribe(topic) | ||
}) | ||
|
||
after(() => { | ||
pubsub.stop() | ||
}) | ||
|
||
it('should not emit to self on publish', () => { | ||
pubsub.once(topic, (m) => shouldNotHappen) | ||
|
||
pubsub.publish(topic, data) | ||
|
||
// Wait 1 second to guarantee that self is not noticed | ||
return new Promise((resolve) => setTimeout(() => resolve(), 1000)) | ||
}) | ||
}) | ||
}) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters