This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from xicombd/browser-tests
Add browser tests
- Loading branch information
Showing
5 changed files
with
132 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module.exports = function (config) { | ||
config.set({ | ||
basePath: '', | ||
frameworks: ['mocha'], | ||
|
||
files: [ | ||
'tests/multiplex-test.js', | ||
'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 | ||
}) | ||
} |
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,35 @@ | ||
/* eslint-env mocha */ | ||
|
||
const expect = require('chai').expect | ||
const WSlibp2p = require('libp2p-websockets') | ||
const multiplex = require('../src') | ||
const multiaddr = require('multiaddr') | ||
|
||
describe('browser + server', () => { | ||
var ws | ||
before((done) => { | ||
ws = new WSlibp2p() | ||
done() | ||
}) | ||
|
||
it('create a stream and wait for server to create another', (done) => { | ||
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets') | ||
const dialerSocket = ws.dial(mh) | ||
|
||
const dialer = multiplex(dialerSocket, false) | ||
dialer.on('stream', (conn) => { | ||
conn.on('data', (data) => { | ||
expect(data.toString()).to.equal('hey') | ||
conn.end() | ||
done() | ||
}) | ||
}) | ||
|
||
const conn = dialer.newStream() | ||
conn.write('hey') | ||
|
||
conn.on('error', (err) => { | ||
expect(err).to.not.exist | ||
}) | ||
}) | ||
}) |
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,38 @@ | ||
const Server = require('karma').Server | ||
const path = require('path') | ||
const WSlibp2p = require('libp2p-websockets') | ||
const multiaddr = require('multiaddr') | ||
const multiplex = require('../src') | ||
|
||
var ws | ||
|
||
function createServer (done) { | ||
ws = new WSlibp2p() | ||
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/websockets') | ||
ws.createListener(mh, (socket) => { | ||
const listener = multiplex(socket, true) | ||
|
||
listener.on('stream', (connA) => { | ||
listener.newStream((err, connB) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
connA.pipe(connB) | ||
}) | ||
}) | ||
}, 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))) |