Completed
Push — master ( 7403a2...9afade )
by Taavo-Taur
02:16
created

test/helpers/feathers-socket.js   A

Complexity

Total Complexity 7
Complexity/F 1

Size

Lines of Code 46
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 46
rs 10
wmc 7
mnd 0
bc 7
fnc 7
bpm 1
cpm 1
noi 0
1
import Proto from 'uberproto'
2
import socket from 'feathers-socket-commons'
3
import {Server} from './mock-socket'
4
5
/**
6
 * Mocks a connection between client and server
7
 *
8
 * Based on feathers-socketio
9
 *
10
 * @param {String} url
11
 * @returns {Function}
12
 */
13
export default function localSocketer(url) {
14
	return function () {
15
		const app = this
16
17
		app.configure(socket('io'))
18
19
		Proto.mixin({
20
			setup() {
21
				const io = this.io = new Server(url)
22
23
				io.on('connection', socket => {
24
					socket.feathers = {
25
						provider: 'socketio'
26
					}
27
				})
28
29
				this._socketInfo = {
30
					method: 'emit',
31
					connection() {
32
						return io
33
					},
34
					clients() {
35
						return io.clients()
36
					},
37
					params(socket) {
38
						return socket.feathers
39
					}
40
				}
41
42
				return this._super.apply(this, arguments)
43
			}
44
		}, app)
45
	}
46
}
47