-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add connectionsCount and documentsCount methods to server
- Loading branch information
Showing
5 changed files
with
99 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// import assert from 'assert' | ||
import * as Y from 'yjs' | ||
import WebSocket from 'ws' | ||
import { assert } from 'chai' | ||
import { Hocuspocus } from '../../packages/server/src' | ||
import { HocuspocusProvider } from '../../packages/provider/src' | ||
|
||
const ydoc = new Y.Doc() | ||
|
||
context('server/connectionsCount', () => { | ||
it('outputs the total connections', done => { | ||
const Server = new Hocuspocus() | ||
|
||
Server.configure({ | ||
port: 4000, | ||
}) | ||
|
||
Server.listen() | ||
|
||
const client = new HocuspocusProvider({ | ||
url: 'ws://127.0.0.1:4000', | ||
name: 'hocuspocus-test', | ||
document: ydoc, | ||
WebSocketPolyfill: WebSocket, | ||
onSynced() { | ||
assert.strictEqual(Server.connectionsCount(), 1) | ||
|
||
const client2 = new HocuspocusProvider({ | ||
url: 'ws://127.0.0.1:4000', | ||
name: 'hocuspocus-test2', | ||
document: ydoc, | ||
WebSocketPolyfill: WebSocket, | ||
onSynced() { | ||
assert.strictEqual(Server.connectionsCount(), 2) | ||
|
||
client2.destroy() | ||
client.destroy() | ||
Server.destroy() | ||
done() | ||
}, | ||
}) | ||
}, | ||
}) | ||
}) | ||
}) |
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,34 @@ | ||
// import assert from 'assert' | ||
import * as Y from 'yjs' | ||
import WebSocket from 'ws' | ||
import { assert } from 'chai' | ||
import { Hocuspocus } from '../../packages/server/src' | ||
import { HocuspocusProvider } from '../../packages/provider/src' | ||
|
||
const ydoc = new Y.Doc() | ||
|
||
context('server/documentsCount', () => { | ||
it('outputs the total active documents', done => { | ||
const Server = new Hocuspocus() | ||
|
||
Server.configure({ | ||
port: 4000, | ||
}) | ||
|
||
Server.listen() | ||
|
||
const client = new HocuspocusProvider({ | ||
url: 'ws://127.0.0.1:4000', | ||
name: 'hocuspocus-test', | ||
document: ydoc, | ||
WebSocketPolyfill: WebSocket, | ||
onSynced() { | ||
assert.strictEqual(Server.documentsCount(), 1) | ||
|
||
client.destroy() | ||
Server.destroy() | ||
done() | ||
}, | ||
}) | ||
}) | ||
}) |