Sfoglia il codice sorgente

add mock-socket library
add test

afrokick 6 anni fa
parent
commit
c4da635b68
2 ha cambiato i file con 22 aggiunte e 2 eliminazioni
  1. 3 2
      package.json
  2. 19 0
      test/peer.ts

+ 3 - 2
package.json

@@ -22,7 +22,6 @@
     "@types/chai": "^4.1.7",
     "@types/mocha": "^5.2.6",
     "chai": "^4.2.0",
-    "mocha": "^6.0.2",
     "grunt": "^1.0.3",
     "grunt-browserify": "^5.3.0",
     "grunt-cli": "^1.3.1",
@@ -32,6 +31,8 @@
     "grunt-ts": "^6.0.0-beta.21",
     "jsdom": "14.0.0",
     "jsdom-global": "3.0.2",
+    "mocha": "^6.0.2",
+    "mock-socket": "^8.0.5",
     "standard": "^12.0.1",
     "ts-node": "^8.0.3",
     "typescript": "^3.3.4000"
@@ -50,4 +51,4 @@
     "type": "opencollective",
     "url": "https://opencollective.com/peer"
   }
-}
+}

+ 19 - 0
test/peer.ts

@@ -1,14 +1,33 @@
 import { expect } from "chai";
 import { Peer } from "../lib/peer";
+import { util } from '../lib/util';
+import { WebSocket } from 'mock-socket';
+
+//enable support for WebRTC
+util.supports.audioVideo = true;
+
+//stub WebSocket
+//@ts-ignore
+global.WebSocket = WebSocket;
 
 describe("Peer", function () {
     describe("after construct without parameters", function () {
         it("shouldn't contains any connection", function () {
             const peer = new Peer();
+
             expect(peer.connections).to.deep.eq({});
             expect(peer.id).to.be.undefined;
             expect(peer.disconnected).to.be.false;
             expect(peer.destroyed).to.be.false;
         });
     });
+
+    describe("after call to peer #2", function () {
+        it("Peer#1 should has id #1", function () {
+            const peer = new Peer('1', { key: 'anotherKey' });
+
+            expect(peer.id).to.eq('1');
+            expect(peer.options.key).to.eq('anotherKey');
+        });
+    });
 });