mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-03-16 13:50:50 +00:00
chore: add basic discovery module for compliance spec
This commit is contained in:
parent
e690d28e0d
commit
b0b54db5b1
34
.travis.yml
34
.travis.yml
@ -2,9 +2,39 @@ language: node_js
|
||||
cache: npm
|
||||
stages:
|
||||
- check
|
||||
- test
|
||||
- cov
|
||||
|
||||
node_js:
|
||||
- '10'
|
||||
- '12'
|
||||
|
||||
script:
|
||||
- npm run lint
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
- windows
|
||||
|
||||
script: npx nyc -s npm run test:node -- --bail
|
||||
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: check
|
||||
script:
|
||||
- npx aegir dep-check
|
||||
- npm run lint
|
||||
|
||||
- stage: test
|
||||
name: chrome
|
||||
addons:
|
||||
chrome: stable
|
||||
script: npx aegir test -t browser -t webworker
|
||||
|
||||
- stage: test
|
||||
name: firefox
|
||||
addons:
|
||||
firefox: latest
|
||||
script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
|
16
package.json
16
package.json
@ -6,13 +6,13 @@
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"lint": "aegir lint",
|
||||
"test": "aegir test",
|
||||
"build": "aegir build",
|
||||
"release": "aegir release --no-test",
|
||||
"release-minor": "aegir release --type minor --no-test",
|
||||
"release-major": "aegir release --type major --no-test",
|
||||
"coverage": "exit(0)",
|
||||
"coverage-publish": "exit(0)"
|
||||
"test": "aegir test",
|
||||
"test:node": "aegir test -t node",
|
||||
"test:browser": "aegir test -t browser -t webworker",
|
||||
"release": "aegir release",
|
||||
"release-minor": "aegir release --type minor",
|
||||
"release-major": "aegir release --type major"
|
||||
},
|
||||
"pre-push": [
|
||||
"lint"
|
||||
@ -40,7 +40,9 @@
|
||||
"devDependencies": {
|
||||
"aegir": "^20.3.1",
|
||||
"chai": "^4.2.0",
|
||||
"dirty-chai": "^2.0.1"
|
||||
"dirty-chai": "^2.0.1",
|
||||
"peer-id": "^0.13.3",
|
||||
"peer-info": "^0.17.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0",
|
||||
|
13
test/compliance.spec.js
Normal file
13
test/compliance.spec.js
Normal file
@ -0,0 +1,13 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const tests = require('../src')
|
||||
const MockDiscovery = require('./mock-discovery')
|
||||
|
||||
describe('compliance tests', () => {
|
||||
tests({
|
||||
setup () {
|
||||
return new MockDiscovery()
|
||||
}
|
||||
})
|
||||
})
|
48
test/mock-discovery.js
Normal file
48
test/mock-discovery.js
Normal file
@ -0,0 +1,48 @@
|
||||
'use strict'
|
||||
|
||||
const { EventEmitter } = require('events')
|
||||
|
||||
const PeerId = require('peer-id')
|
||||
const PeerInfo = require('peer-info')
|
||||
|
||||
/**
|
||||
* Emits 'peer' events on discovery.
|
||||
*/
|
||||
class MockDiscovery extends EventEmitter {
|
||||
/**
|
||||
* Constructs a new Bootstrap.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {number} options.discoveryDelay - the delay to find a peer (in milli-seconds)
|
||||
*/
|
||||
constructor (options = {}) {
|
||||
super()
|
||||
|
||||
this.options = options
|
||||
this._isRunning = false
|
||||
this._timer = null
|
||||
}
|
||||
|
||||
start () {
|
||||
this._isRunning = true
|
||||
this._discoverPeer()
|
||||
}
|
||||
|
||||
stop () {
|
||||
clearTimeout(this._timer)
|
||||
this._isRunning = false
|
||||
}
|
||||
|
||||
async _discoverPeer () {
|
||||
if (!this._isRunning) return
|
||||
|
||||
const peerId = await PeerId.create({ bits: 512 })
|
||||
const peerInfo = new PeerInfo(peerId)
|
||||
|
||||
this._timer = setTimeout(() => {
|
||||
this.emit('peer', peerInfo)
|
||||
}, this.options.discoveryDelay || 1000)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MockDiscovery
|
@ -1 +0,0 @@
|
||||
'use strict'
|
Loading…
x
Reference in New Issue
Block a user