Explorar o código

add simple test

afrokick %!s(int64=6) %!d(string=hai) anos
pai
achega
108fb8daf4
Modificáronse 7 ficheiros con 45 adicións e 342 borrados
  1. 5 0
      lib/adapter.ts
  2. 20 9
      lib/util.ts
  3. 10 7
      package.json
  4. 0 29
      test/basic_test.js
  5. 0 15
      test/codecept.json
  6. 0 282
      test/steps.d.ts
  7. 10 0
      test/util.ts

+ 5 - 0
lib/adapter.ts

@@ -1,10 +1,15 @@
 import webrtc from "webrtc-adapter";
 
 export const RTCSessionDescription =
+  // @ts-ignore
   window.RTCSessionDescription || window.mozRTCSessionDescription;
 export const RTCPeerConnection =
+  // @ts-ignore
   window.RTCPeerConnection ||
+  // @ts-ignore
   window.mozRTCPeerConnection ||
+  // @ts-ignore
   window.webkitRTCPeerConnection;
 export const RTCIceCandidate =
+  // @ts-ignore
   window.RTCIceCandidate || window.mozRTCIceCandidate;

+ 20 - 9
lib/util.ts

@@ -1,4 +1,4 @@
-import BinaryPack from "js-binarypack";
+import * as BinaryPack from "js-binarypack";
 import { RTCPeerConnection } from "./adapter";
 
 const DEFAULT_CONFIG = {
@@ -92,17 +92,22 @@ export class util {
   static readonly defaultConfig = DEFAULT_CONFIG;
 
   // Returns the current browser.
-  static readonly browser: string = (function() {
-    if (window.mozRTCPeerConnection) {
+  static readonly browser: string = (function(global) {
+    // @ts-ignore
+    if (global.mozRTCPeerConnection) {
       return "Firefox";
-    } else if (window.webkitRTCPeerConnection) {
+    }
+    // @ts-ignore
+    if (global.webkitRTCPeerConnection) {
       return "Chrome";
-    } else if (window.RTCPeerConnection) {
+    }
+
+    if (global.RTCPeerConnection) {
       return "Supported";
-    } else {
-      return "Unsupported";
     }
-  })();
+
+    return "Unsupported";
+  })(window);
 
   // Lists which features are supported
   static readonly supports = (function() {
@@ -115,6 +120,7 @@ export class util {
 
     let binaryBlob = false;
     let sctp = false;
+    // @ts-ignore
     const onnegotiationneeded = !!window.webkitRTCPeerConnection;
 
     let pc, dc;
@@ -274,7 +280,10 @@ export class util {
 
     if (global.addEventListener) {
       global.addEventListener("message", handleMessage, true);
-    } else if (global.attachEvent) {
+    }
+    // @ts-ignore
+    else if (global.attachEvent) {
+      // @ts-ignore
       global.attachEvent("onmessage", handleMessage);
     }
 
@@ -320,6 +329,7 @@ export class util {
     const fr = new FileReader();
 
     fr.onload = function(evt) {
+      // @ts-ignore
       cb(evt.target.result);
     };
 
@@ -330,6 +340,7 @@ export class util {
     const fr = new FileReader();
 
     fr.onload = function(evt) {
+      // @ts-ignore
       cb(evt.target.result);
     };
 

+ 10 - 7
package.json

@@ -13,7 +13,7 @@
     "build": "parcel build lib/exports.ts -d dist --out-file peerjs.min.js",
     "prepublish": "yarn build",
     "postinstall": "opencollective-postinstall",
-    "test": "cd test && codeceptjs run"
+    "test": "mocha -r ts-node/register -r jsdom-global/register test/**/*.ts"
   },
   "husky": {
     "hooks": {}
@@ -25,9 +25,10 @@
     "@commitlint/cli": "^7.2.1",
     "@commitlint/config-angular": "^7.1.2",
     "@commitlint/config-conventional": "^7.1.2",
-    "codeceptjs": "^1.4.2",
+    "@types/chai": "^4.1.7",
+    "@types/mocha": "^5.2.6",
+    "chai": "^4.2.0",
     "commitlint": "^7.2.1",
-    "expect.js": "*",
     "grunt": "^1.0.3",
     "grunt-browserify": "^5.3.0",
     "grunt-cli": "^1.3.1",
@@ -36,15 +37,17 @@
     "grunt-contrib-uglify": "^4.0.0",
     "grunt-ts": "^6.0.0-beta.21",
     "husky": "^1.1.2",
-    "mocha": "*",
-    "selenium-standalone": "^6.15.3",
+    "jsdom": "14.0.0",
+    "jsdom-global": "3.0.2",
+    "mocha": "^6.0.2",
     "standard": "^12.0.1",
     "standard-version": "^4.4.0",
-    "typescript": "^3.3.3",
-    "express": "^4.16.3"
+    "ts-node": "^8.0.3",
+    "typescript": "^3.3.4000"
   },
   "dependencies": {
     "@types/node": "^10.12.0",
+    "@types/webrtc": "0.0.24",
     "eventemitter3": "^0.1.6",
     "js-binarypack": "0.0.9",
     "opencollective": "^1.0.3",

+ 0 - 29
test/basic_test.js

@@ -1,29 +0,0 @@
-/// <reference path="./steps.d.ts" />
-const express = require("express");
-const port = Math.floor(Math.random() * (8000 - 2000 + 1)) + 2000;
-
-BeforeSuite((I) => {
-    const app = express()
-    app.use(express.static('public'))
-    app.listen(port)
-});
-
-Feature('Connection');
-
-Scenario('Data Channel ping pong', async (I) => {
-    I.amOnPage("http://localhost:" + port)
-    I.wait(1)
-    I.openNewTab();
-    I.amOnPage("http://localhost:" + port)
-    I.wait(1)
-    const id2 = await I.grabTextFrom("#id")
-    I.switchToPreviousTab(1)
-    I.wait(1)
-    I.executeScript(`connect("${id2}")`)
-    I.wait(1)
-    I.see("pong")
-});
-
-AfterSuite((I) => {
-    process.exit(0)
-})

+ 0 - 15
test/codecept.json

@@ -1,15 +0,0 @@
-{
-  "tests": "./*_test.js",
-  "timeout": 10000,
-  "output": "./output",
-  "helpers": {
-    "WebDriverIO": {
-      "url": "http://localhost",
-      "browser": "chrome"
-    }
-  },
-  "include": {},
-  "bootstrap": false,
-  "mocha": {},
-  "name": "test"
-}

+ 0 - 282
test/steps.d.ts

@@ -1,282 +0,0 @@
-
-type ICodeceptCallback = (i: CodeceptJS.I) => void;
-
-declare class FeatureConfig {
-  retry(times:number): FeatureConfig
-  timeout(seconds:number): FeatureConfig
-  config(config:object): FeatureConfig
-  config(helperName:string, config:object): FeatureConfig
-}
-
-declare class ScenarioConfig {
-  throws(err:any) : ScenarioConfig;
-  fails() : ScenarioConfig;
-  retry(times:number): ScenarioConfig
-  timeout(timeout:number): ScenarioConfig
-  inject(inject:object): ScenarioConfig
-  config(config:object): ScenarioConfig
-  config(helperName:string, config:object): ScenarioConfig
-}
-
-interface ILocator {
-  xpath?: string;
-  css?: string;
-  name?: string;
-  value?: string;
-  frame?: string;
-  android?: string;
-  ios?: string;
-}
-
-declare class Helper {
-  /** Abstract method to provide required config options */
-  static _config(): any;
-  /** Abstract method to validate config */
-  _validateConfig<T>(config: T): T;
-  /** Sets config for current test */
-  _setConfig(opts: any): void;
-  /** Hook executed before all tests */
-  _init(): void
-  /** Hook executed before each test. */
-  _before(): void
-  /** Hook executed after each test */
-  _after(): void
-  /**
-   * Hook provides a test details
-   * Executed in the very beginning of a test
-   */
-  _test(test): void
-  /** Hook executed after each passed test */
-  _passed(test: () => void): void
-  /** Hook executed after each failed test */
-  _failed(test: () => void): void
-  /** Hook executed before each step */
-  _beforeStep(step: () => void): void
-  /** Hook executed after each step */
-  _afterStep(step: () => void): void
-  /** Hook executed before each suite */
-  _beforeSuite(suite: () => void): void
-  /** Hook executed after each suite */
-  _afterSuite(suite: () => void): void
-  /** Hook executed after all tests are executed */
-  _finishTest(suite: () => void): void
-  /**Access another configured helper: this.helpers['AnotherHelper'] */
-  helpers(): any
-  /** Print debug message to console (outputs only in debug mode) */
-  debug(msg: string): void
-
-  debugSection(section: string, msg: string): void
-}
-
-declare class Locator implements ILocator {
-  xpath?: string;
-  css?: string;
-  name?: string;
-  value?: string;
-  frame?: string;
-  android?: string;
-  ios?: string;
-
-  or(locator:string): Locator;
-  find(locator:string): Locator;
-  withChild(locator:string): Locator;
-  find(locator:string): Locator;
-  at(position:number): Locator;
-  first(): Locator;
-  last(): Locator;
-  inside(locator:string): Locator;
-  before(locator:string): Locator;
-  after(locator:string): Locator;
-  withText(locator:string): Locator;
-  withAttr(locator:object): Locator;
-  as(locator:string): Locator;
-}
-
-declare function actor(customSteps?: {}): CodeceptJS.I;
-declare function Feature(title: string, opts?: {}): FeatureConfig;
-declare const Scenario: {
-	(title: string, callback: ICodeceptCallback): ScenarioConfig;
-	(title: string, opts: {}, callback: ICodeceptCallback): ScenarioConfig;
-	only(title: string, callback: ICodeceptCallback): ScenarioConfig;
-	only(title: string, opts: {}, callback: ICodeceptCallback): ScenarioConfig;
-}
-declare function xScenario(title: string, callback: ICodeceptCallback): ScenarioConfig;
-declare function xScenario(title: string, opts: {}, callback: ICodeceptCallback): ScenarioConfig;
-declare function Data(data: any): any;
-declare function xData(data: any): any;
-declare function Before(callback: ICodeceptCallback): void;
-declare function BeforeSuite(callback: ICodeceptCallback): void;
-declare function After(callback: ICodeceptCallback): void;
-declare function AfterSuite(callback: ICodeceptCallback): void;
-
-declare function locate(selector: string): Locator;
-declare function locate(selector: ILocator): Locator;
-declare function within(selector: string, callback: Function): Promise<any>;
-declare function within(selector: ILocator, callback: Function): Promise<any>;
-declare function session(selector: string, callback: Function): Promise<any>;
-declare function session(selector: ILocator, callback: Function): Promise<any>;
-declare function session(selector: string, config: any, callback: Function): Promise<any>;
-declare function session(selector: ILocator, config: any, callback: Function): Promise<any>;
-declare function pause(): void;
-
-declare const codeceptjs: any;
-
-declare namespace CodeceptJS {
-  export interface I {
-    defineTimeout(timeouts: string) : void,
-    amOnPage(url: string) : void,
-    click(locator: ILocator, context?: ILocator) : void,
-    click(locator: string, context?: ILocator) : void,
-    click(locator: ILocator, context?: string) : void,
-    click(locator: string, context?: string) : void,
-    doubleClick(locator: ILocator, context?: ILocator) : void,
-    doubleClick(locator: string, context?: ILocator) : void,
-    doubleClick(locator: ILocator, context?: string) : void,
-    doubleClick(locator: string, context?: string) : void,
-    rightClick(locator: ILocator) : void,
-    rightClick(locator: string) : void,
-    fillField(field: ILocator, value: string) : void,
-    fillField(field: string, value: string) : void,
-    appendField(field: ILocator, value: string) : void,
-    appendField(field: string, value: string) : void,
-    clearField(field: ILocator) : void,
-    clearField(field: string) : void,
-    selectOption(select: ILocator, option: string) : void,
-    selectOption(select: string, option: string) : void,
-    attachFile(locator: ILocator, pathToFile: string) : void,
-    attachFile(locator: string, pathToFile: string) : void,
-    checkOption(field: ILocator, context?: ILocator) : void,
-    checkOption(field: string, context?: ILocator) : void,
-    checkOption(field: ILocator, context?: string) : void,
-    checkOption(field: string, context?: string) : void,
-    uncheckOption(field: ILocator, context?: ILocator) : void,
-    uncheckOption(field: string, context?: ILocator) : void,
-    uncheckOption(field: ILocator, context?: string) : void,
-    uncheckOption(field: string, context?: string) : void,
-    grabTextFrom(locator: ILocator) : Promise<string>,
-    grabTextFrom(locator: string) : Promise<string>,
-    grabHTMLFrom(locator: ILocator) : Promise<string>,
-    grabHTMLFrom(locator: string) : Promise<string>,
-    grabValueFrom(locator: ILocator) : Promise<string>,
-    grabValueFrom(locator: string) : Promise<string>,
-    grabCssPropertyFrom(locator: ILocator, cssProperty: string) : Promise<string>,
-    grabCssPropertyFrom(locator: string, cssProperty: string) : Promise<string>,
-    grabAttributeFrom(locator: ILocator, attr: string) : Promise<string>,
-    grabAttributeFrom(locator: string, attr: string) : Promise<string>,
-    seeInTitle(text: string) : void,
-    seeTitleEquals(text: string) : void,
-    dontSeeInTitle(text: string) : void,
-    grabTitle() : Promise<string>,
-    see(text: string, context?: ILocator) : void,
-    see(text: string, context?: string) : void,
-    seeTextEquals(text: string, context?: ILocator) : void,
-    seeTextEquals(text: string, context?: string) : void,
-    dontSee(text: string, context?: ILocator) : void,
-    dontSee(text: string, context?: string) : void,
-    seeInField(field: ILocator, value: string) : void,
-    seeInField(field: string, value: string) : void,
-    dontSeeInField(field: ILocator, value: string) : void,
-    dontSeeInField(field: string, value: string) : void,
-    seeCheckboxIsChecked(field: ILocator) : void,
-    seeCheckboxIsChecked(field: string) : void,
-    dontSeeCheckboxIsChecked(field: ILocator) : void,
-    dontSeeCheckboxIsChecked(field: string) : void,
-    seeElement(locator: ILocator) : void,
-    seeElement(locator: string) : void,
-    dontSeeElement(locator: ILocator) : void,
-    dontSeeElement(locator: string) : void,
-    seeElementInDOM(locator: ILocator) : void,
-    seeElementInDOM(locator: string) : void,
-    dontSeeElementInDOM(locator: ILocator) : void,
-    dontSeeElementInDOM(locator: string) : void,
-    seeInSource(text: string) : void,
-    grabSource() : Promise<string>,
-    grabBrowserLogs() : Promise<string>,
-    grabCurrentUrl() : Promise<string>,
-    grabBrowserUrl() : Promise<string>,
-    dontSeeInSource(text: string) : void,
-    seeNumberOfElements(selector: string, num: number) : void,
-    seeNumberOfVisibleElements(locator: ILocator, num: number) : void,
-    seeNumberOfVisibleElements(locator: string, num: number) : void,
-    seeCssPropertiesOnElements(locator: ILocator, cssProperties: string) : void,
-    seeCssPropertiesOnElements(locator: string, cssProperties: string) : void,
-    seeAttributesOnElements(locator: ILocator, attributes: string) : void,
-    seeAttributesOnElements(locator: string, attributes: string) : void,
-    grabNumberOfVisibleElements(locator: ILocator) : Promise<string>,
-    grabNumberOfVisibleElements(locator: string) : Promise<string>,
-    seeInCurrentUrl(url: string) : void,
-    dontSeeInCurrentUrl(url: string) : void,
-    seeCurrentUrlEquals(url: string) : void,
-    dontSeeCurrentUrlEquals(url: string) : void,
-    executeScript(fn: Function) : void,
-    executeAsyncScript(fn: Function) : void,
-    scrollTo(locator: ILocator, offsetX?: number, offsetY?: number) : void,
-    scrollTo(locator: string, offsetX?: number, offsetY?: number) : void,
-    moveCursorTo(locator: ILocator, offsetX?: number, offsetY?: number) : void,
-    moveCursorTo(locator: string, offsetX?: number, offsetY?: number) : void,
-    saveScreenshot(fileName: string, fullPage?: string) : void,
-    setCookie(cookie: string) : void,
-    clearCookie(cookie: string) : void,
-    seeCookie(name: string) : void,
-    dontSeeCookie(name: string) : void,
-    grabCookie(name: string) : Promise<string>,
-    acceptPopup() : void,
-    cancelPopup() : void,
-    seeInPopup(text: string) : void,
-    grabPopupText() : Promise<string>,
-    pressKey(key: string) : void,
-    resizeWindow(width: number, height: number) : void,
-    dragAndDrop(srcElement: string, destElement: string) : void,
-    closeOtherTabs() : void,
-    wait(sec: number) : void,
-    waitForEnabled(locator: ILocator, sec?: number) : void,
-    waitForEnabled(locator: string, sec?: number) : void,
-    waitForElement(locator: ILocator, sec?: number) : void,
-    waitForElement(locator: string, sec?: number) : void,
-    waitUntilExists(locator: ILocator, sec?: number) : void,
-    waitUntilExists(locator: string, sec?: number) : void,
-    waitInUrl(urlPart: string, sec?: number) : void,
-    waitUrlEquals(urlPart: string, sec?: number) : void,
-    waitForText(text: string, sec?: number, aContext?: string) : void,
-    waitForValue(field: ILocator, value: string, sec?: number) : void,
-    waitForValue(field: string, value: string, sec?: number) : void,
-    waitForVisible(locator: ILocator, sec?: number) : void,
-    waitForVisible(locator: string, sec?: number) : void,
-    waitNumberOfVisibleElements(locator: ILocator, num: number, sec?: number) : void,
-    waitNumberOfVisibleElements(locator: string, num: number, sec?: number) : void,
-    waitForInvisible(locator: ILocator, sec?: number) : void,
-    waitForInvisible(locator: string, sec?: number) : void,
-    waitToHide(locator: ILocator, sec?: number) : void,
-    waitToHide(locator: string, sec?: number) : void,
-    waitForStalenessOf(locator: ILocator, sec?: number) : void,
-    waitForStalenessOf(locator: string, sec?: number) : void,
-    waitForDetached(locator: ILocator, sec?: number) : void,
-    waitForDetached(locator: string, sec?: number) : void,
-    waitForFunction(fn: Function, argsOrSec?: string, sec?: number) : void,
-    waitUntil(fn: Function, sec?: number, timeoutMsg?: string) : void,
-    switchTo(locator: ILocator) : void,
-    switchTo(locator: string) : void,
-    switchToNextTab(num?: number, sec?: number) : void,
-    switchToPreviousTab(num?: number, sec?: number) : void,
-    closeCurrentTab() : void,
-    openNewTab() : void,
-    grabNumberOfOpenTabs() : Promise<string>,
-    refreshPage() : void,
-    scrollPageToTop() : void,
-    scrollPageToBottom() : void,
-    grabPageScrollPosition() : Promise<string>,
-    runOnIOS(caps: string, fn: Function) : void,
-    runOnAndroid(caps: string, fn: Function) : void,
-    runInWeb(fn: Function) : void,
-    debug(msg: string) : void,
-    debugSection(section: string, msg: string) : void,
-    say(msg: string) : void,
-    retryStep(opts: string) : void,
-
-  }
-
-}
-
-declare module "codeceptjs" {
-    export = CodeceptJS;
-}

+ 10 - 0
test/util.ts

@@ -0,0 +1,10 @@
+import { expect } from "chai";
+import { util } from "../lib/util";
+
+describe("util", function() {
+  describe("#chunkedMTU", function() {
+    it("should be 16300", function() {
+      expect(util.chunkedMTU).to.eq(16300);
+    });
+  });
+});