mirror of
https://github.com/fluencelabs/js-libp2p-websockets
synced 2025-05-10 12:17:31 +00:00
commit
6c6dfc0199
@ -9,3 +9,10 @@ before_install:
|
||||
|
||||
script:
|
||||
- npm test
|
||||
|
||||
addons:
|
||||
firefox: 'latest'
|
||||
|
||||
before_script:
|
||||
- export DISPLAY=:99.0
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
|
38
karma.conf.js
Normal file
38
karma.conf.js
Normal file
@ -0,0 +1,38 @@
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
basePath: '',
|
||||
frameworks: ['mocha'],
|
||||
|
||||
files: [
|
||||
'tests/browser.js'
|
||||
],
|
||||
|
||||
preprocessors: {
|
||||
'tests/*': ['webpack']
|
||||
},
|
||||
|
||||
webpack: {
|
||||
resolve: {
|
||||
extensions: ['', '.js']
|
||||
},
|
||||
node: {
|
||||
Buffer: true
|
||||
}
|
||||
},
|
||||
|
||||
webpackMiddleware: {
|
||||
noInfo: true,
|
||||
stats: {
|
||||
colors: true
|
||||
}
|
||||
},
|
||||
reporters: ['spec'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: config.LOG_INFO,
|
||||
autoWatch: false,
|
||||
browsers: process.env.TRAVIS ? ['Firefox'] : ['Chrome'],
|
||||
captureTimeout: 60000,
|
||||
singleRun: true
|
||||
})
|
||||
}
|
14
package.json
14
package.json
@ -7,7 +7,9 @@
|
||||
"test:compliance:connection": "node tests/connection.js",
|
||||
"test:compliance:transport": "node tests/transport.js",
|
||||
"test:specific": "mocha tests/*-test.js",
|
||||
"test": "npm run test:specific",
|
||||
"test:node": "npm run test:specific",
|
||||
"test:browser": "node tests/karma",
|
||||
"test": "npm run test:node && npm run test:browser",
|
||||
"test-2": "npm run test:specific && npm run test:compliance:transport && npm run test:compliance:connection",
|
||||
"lint": "standard"
|
||||
},
|
||||
@ -38,9 +40,17 @@
|
||||
"interface-connection": "0.0.3",
|
||||
"interface-transport": "^0.1.1",
|
||||
"istanbul": "^0.4.2",
|
||||
"karma": "^0.13.19",
|
||||
"karma-chrome-launcher": "^0.2.2",
|
||||
"karma-cli": "^0.1.2",
|
||||
"karma-firefox-launcher": "^0.1.7",
|
||||
"karma-mocha": "^0.2.1",
|
||||
"karma-spec-reporter": "0.0.23",
|
||||
"karma-webpack": "^1.7.0",
|
||||
"mocha": "^2.4.5",
|
||||
"pre-commit": "^1.1.2",
|
||||
"standard": "^6.0.7",
|
||||
"tape": "^4.2.0"
|
||||
"tape": "^4.2.0",
|
||||
"webpack": "^1.12.14"
|
||||
}
|
||||
}
|
||||
|
28
tests/browser.js
Normal file
28
tests/browser.js
Normal file
@ -0,0 +1,28 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
const expect = require('chai').expect
|
||||
const WSlibp2p = require('../src')
|
||||
const multiaddr = require('multiaddr')
|
||||
|
||||
describe('libp2p-websockets', function () {
|
||||
this.timeout(10000)
|
||||
var ws
|
||||
|
||||
it('create', (done) => {
|
||||
ws = new WSlibp2p()
|
||||
expect(ws).to.exist
|
||||
done()
|
||||
})
|
||||
|
||||
it('echo', (done) => {
|
||||
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets')
|
||||
const conn = ws.dial(mh)
|
||||
const message = 'Hello World!'
|
||||
conn.write(message)
|
||||
conn.on('data', (data) => {
|
||||
expect(data.toString()).to.equal(message)
|
||||
conn.end()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
28
tests/karma.js
Normal file
28
tests/karma.js
Normal file
@ -0,0 +1,28 @@
|
||||
const Server = require('karma').Server
|
||||
const path = require('path')
|
||||
|
||||
const WSlibp2p = require('../src')
|
||||
const multiaddr = require('multiaddr')
|
||||
|
||||
var ws
|
||||
|
||||
function createServer (done) {
|
||||
ws = new WSlibp2p()
|
||||
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets')
|
||||
ws.createListener(mh, (socket) => {
|
||||
socket.pipe(socket)
|
||||
}, done)
|
||||
}
|
||||
|
||||
function stopServer (done) {
|
||||
ws.close(done)
|
||||
}
|
||||
|
||||
function runTests (done) {
|
||||
new Server({
|
||||
configFile: path.join(__dirname, '/../karma.conf.js'),
|
||||
singleRun: true
|
||||
}, done).start()
|
||||
}
|
||||
|
||||
createServer(() => runTests(() => stopServer(() => null)))
|
Loading…
x
Reference in New Issue
Block a user