Kaynağa Gözat

Merge pull request #497 from afrokick/refactoring/classes

Refactoring: util.ts
afrokick 6 yıl önce
ebeveyn
işleme
d62ee923f6
8 değiştirilmiş dosya ile 193 ekleme ve 450 silme
  1. 5 0
      README.md
  2. 5 0
      lib/adapter.ts
  3. 163 117
      lib/util.ts
  4. 10 7
      package.json
  5. 0 29
      test/basic_test.js
  6. 0 15
      test/codecept.json
  7. 0 282
      test/steps.d.ts
  8. 10 0
      test/util.ts

+ 5 - 0
README.md

@@ -82,6 +82,11 @@ peer.on('call', function(call) {
   });
 });
 ```
+
+## Run tests
+
+`npm test`
+
 ## Links
 
 ### [Documentation / API Reference](http://peerjs.com/docs)

+ 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;

+ 163 - 117
lib/util.ts

@@ -1,41 +1,60 @@
-var defaultConfig = { iceServers: [{ urls: "stun:stun.l.google.com:19302" }] };
-var dataCount = 1;
-
-import BinaryPack from "js-binarypack";
+import * as BinaryPack from "js-binarypack";
 import { RTCPeerConnection } from "./adapter";
 
-export const util = {
-  noop: function() {},
+const DEFAULT_CONFIG = {
+  iceServers: [{ urls: "stun:stun.l.google.com:19302" }]
+};
 
-  CLOUD_HOST: "0.peerjs.com",
-  CLOUD_PORT: 443,
+/*
+Prints log messages depending on the debug level passed in. Defaults to 0.
+0  Prints no logs.
+1  Prints only errors.
+2  Prints errors and warnings.
+3  Prints all logs.
+*/
+const enum DebugLevel {
+  Disabled,
+  Errors,
+  Warnings,
+  All
+}
+
+export class util {
+  static noop(): void {}
+
+  static readonly CLOUD_HOST = "0.peerjs.com";
+  static readonly CLOUD_PORT = 443;
 
   // Browsers that need chunking:
-  chunkedBrowsers: { Chrome: 1 },
-  chunkedMTU: 16300, // The original 60000 bytes setting does not work when sending data from Firefox to Chrome, which is "cut off" after 16384 bytes and delivered individually.
+  static readonly chunkedBrowsers = { Chrome: 1 };
+  static readonly chunkedMTU = 16300; // The original 60000 bytes setting does not work when sending data from Firefox to Chrome, which is "cut off" after 16384 bytes and delivered individually.
 
   // Logging logic
-  logLevel: 0,
-  setLogLevel: function(level) {
-    var debugLevel = parseInt(level, 10);
+  static readonly debug = false;
+  static logLevel = DebugLevel.Disabled;
+
+  static setLogLevel(level: string): void {
+    const debugLevel = parseInt(level, 10);
+
     if (!isNaN(parseInt(level, 10))) {
       util.logLevel = debugLevel;
     } else {
       // If they are using truthy/falsy values for debug
-      util.logLevel = level ? 3 : 0;
+      util.logLevel = level ? DebugLevel.All : DebugLevel.Disabled;
     }
     util.log = util.warn = util.error = util.noop;
-    if (util.logLevel > 0) {
+    if (util.logLevel > DebugLevel.Disabled) {
       util.error = util._printWith("ERROR");
     }
-    if (util.logLevel > 1) {
+    if (util.logLevel > DebugLevel.Errors) {
       util.warn = util._printWith("WARNING");
     }
-    if (util.logLevel > 2) {
+    if (util.logLevel > DebugLevel.Warnings) {
       util.log = util._print;
     }
-  },
-  setLogFunction: function(fn) {
+  }
+
+  static setLogFunction(fn): void {
     if (fn.constructor !== Function) {
       util.warn(
         "The log function you passed in is not a function. Defaulting to regular logs."
@@ -43,63 +62,71 @@ export const util = {
     } else {
       util._print = fn;
     }
-  },
+  }
 
-  _printWith: function(prefix) {
+  private static _printWith(prefix) {
     return function() {
-      var copy = Array.prototype.slice.call(arguments);
+      const copy = Array.prototype.slice.call(arguments);
       copy.unshift(prefix);
       util._print.apply(util, copy);
     };
-  },
-  _print: function() {
-    var err = false;
-    var copy = Array.prototype.slice.call(arguments);
+  }
+
+  private static _print(...rest): void {
+    let err = false;
+    const copy = [...rest];
+
     copy.unshift("PeerJS: ");
-    for (var i = 0, l = copy.length; i < l; i++) {
+
+    for (let i in copy) {
       if (copy[i] instanceof Error) {
         copy[i] = "(" + copy[i].name + ") " + copy[i].message;
         err = true;
       }
     }
+
     err ? console.error.apply(console, copy) : console.log.apply(console, copy);
-  },
-  //
+  }
 
   // Returns browser-agnostic default config
-  defaultConfig: defaultConfig,
-  //
+  static readonly defaultConfig = DEFAULT_CONFIG;
 
   // Returns the current browser.
-  browser: (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
-  supports: (function() {
+  static readonly supports = (function() {
     if (typeof RTCPeerConnection === "undefined") {
       return {};
     }
 
-    var data = true;
-    var audioVideo = true;
+    let data = true;
+    let audioVideo = true;
 
-    var binaryBlob = false;
-    var sctp = false;
-    var onnegotiationneeded = !!window.webkitRTCPeerConnection;
+    let binaryBlob = false;
+    let sctp = false;
+    // @ts-ignore
+    const onnegotiationneeded = !!window.webkitRTCPeerConnection;
+
+    let pc, dc;
 
-    var pc, dc;
     try {
-      pc = new RTCPeerConnection(defaultConfig, {
+      pc = new RTCPeerConnection(DEFAULT_CONFIG, {
         optional: [{ RtpDataChannels: true }]
       });
     } catch (e) {
@@ -125,9 +152,9 @@ export const util = {
       // Reliable test.
       // Unfortunately Chrome is a bit unreliable about whether or not they
       // support reliable.
-      var reliablePC = new RTCPeerConnection(defaultConfig, {});
+      const reliablePC = new RTCPeerConnection(DEFAULT_CONFIG, {});
       try {
-        var reliableDC = reliablePC.createDataChannel(
+        const reliableDC = reliablePC.createDataChannel(
           "_PEERJSRELIABLETEST",
           {}
         );
@@ -175,23 +202,15 @@ export const util = {
       sctp: sctp,
       onnegotiationneeded: onnegotiationneeded
     };
-  })(),
-  //
+  })();
 
   // Ensure alphanumeric ids
-  validateId: function(id) {
+  static validateId(id: string): boolean {
     // Allow empty ids
-    return !id || /^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(id);
-  },
-
-  validateKey: function(key) {
-    // Allow empty keys
-    return !key || /^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(key);
-  },
-
-  debug: false,
+    return !id || /^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(id);
+  }
 
-  inherits: function(ctor, superCtor) {
+  static inherits(ctor, superCtor): void {
     ctor.super_ = superCtor;
     ctor.prototype = Object.create(superCtor.prototype, {
       constructor: {
@@ -201,38 +220,44 @@ export const util = {
         configurable: true
       }
     });
-  },
-  extend: function(dest, source) {
-    for (var key in source) {
+  }
+
+  static extend(dest, source): any {
+    for (let key in source) {
       if (source.hasOwnProperty(key)) {
         dest[key] = source[key];
       }
     }
     return dest;
-  },
-  pack: BinaryPack.pack,
-  unpack: BinaryPack.unpack,
-
-  log: function() {
-    if (util.debug) {
-      var err = false;
-      var copy = Array.prototype.slice.call(arguments);
-      copy.unshift("PeerJS: ");
-      for (var i = 0, l = copy.length; i < l; i++) {
-        if (copy[i] instanceof Error) {
-          copy[i] = "(" + copy[i].name + ") " + copy[i].message;
-          err = true;
-        }
+  }
+
+  static pack = BinaryPack.pack;
+  static unpack = BinaryPack.unpack;
+
+  static log(...rest): void {
+    if (!util.debug) return;
+
+    let err = false;
+    const copy = [...rest];
+
+    copy.unshift("PeerJS: ");
+
+    for (let i in copy) {
+      if (copy[i] instanceof Error) {
+        copy[i] = "(" + copy[i].name + ") " + copy[i].message;
+        err = true;
       }
-      err
-        ? console.error.apply(console, copy)
-        : console.log.apply(console, copy);
     }
-  },
 
-  setZeroTimeout: (function(global) {
-    var timeouts = [];
-    var messageName = "zero-timeout-message";
+    err ? console.error.apply(console, copy) : console.log.apply(console, copy);
+  }
+
+  static warn(...rest): void {}
+  static error(...rest): void {}
+
+  static setZeroTimeout = (global => {
+    const timeouts = [];
+    const messageName = "zero-timeout-message";
 
     // Like setTimeout, but only takes a function argument.	 There's
     // no time argument (always zero) and no arguments (you have to
@@ -243,7 +268,7 @@ export const util = {
     }
 
     function handleMessage(event) {
-      if (event.source == global && event.data == messageName) {
+      if (event.source === global && event.data === messageName) {
         if (event.stopPropagation) {
           event.stopPropagation();
         }
@@ -252,29 +277,38 @@ export const 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);
     }
+
     return setZeroTimeoutPostMessage;
-  })(window),
+  })(window);
 
   // Binary stuff
 
+  private static _dataCount = 1;
+
   // chunks a blob.
-  chunk: function(bl) {
-    var chunks = [];
-    var size = bl.size;
-    var index;
-    var start = (index = 0);
-    var total = Math.ceil(size / util.chunkedMTU);
+  static chunk(bl: Blob): any[] {
+    const chunks = [];
+    const size = bl.size;
+    const total = Math.ceil(size / util.chunkedMTU);
+
+    let index;
+    let start = (index = 0);
+
     while (start < size) {
-      var end = Math.min(size, start + util.chunkedMTU);
-      var b = bl.slice(start, end);
+      const end = Math.min(size, start + util.chunkedMTU);
+      const b = bl.slice(start, end);
 
-      var chunk = {
-        __peerData: dataCount,
+      const chunk = {
+        __peerData: this._dataCount,
         n: index,
         data: b,
         total: total
@@ -283,41 +317,53 @@ export const util = {
       chunks.push(chunk);
 
       start = end;
-      index += 1;
+      index++;
     }
-    dataCount += 1;
+
+    this._dataCount++;
+
     return chunks;
-  },
+  }
+
+  static blobToArrayBuffer(blob: Blob, cb: (arg: any) => void): void {
+    const fr = new FileReader();
 
-  blobToArrayBuffer: function(blob, cb) {
-    var fr = new FileReader();
     fr.onload = function(evt) {
+      // @ts-ignore
       cb(evt.target.result);
     };
+
     fr.readAsArrayBuffer(blob);
-  },
-  blobToBinaryString: function(blob, cb) {
-    var fr = new FileReader();
+  }
+
+  static blobToBinaryString(blob: Blob, cb: (arg: any) => void): void {
+    const fr = new FileReader();
+
     fr.onload = function(evt) {
+      // @ts-ignore
       cb(evt.target.result);
     };
+
     fr.readAsBinaryString(blob);
-  },
-  binaryStringToArrayBuffer: function(binary) {
-    var byteArray = new Uint8Array(binary.length);
-    for (var i = 0; i < binary.length; i++) {
+  }
+
+  static binaryStringToArrayBuffer(binary): ArrayBuffer | SharedArrayBuffer {
+    let byteArray = new Uint8Array(binary.length);
+
+    for (let i = 0; i < binary.length; i++) {
       byteArray[i] = binary.charCodeAt(i) & 0xff;
     }
+
     return byteArray.buffer;
-  },
-  randomToken: function() {
+  }
+
+  static randomToken(): string {
     return Math.random()
       .toString(36)
       .substr(2);
-  },
-  //
+  }
 
-  isSecure: function() {
+  static isSecure(): boolean {
     return location.protocol === "https:";
   }
-};
+}

+ 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);
+    });
+  });
+});