From c2d6986ec61e5f95129f9e1fa519671ac7e71a9a Mon Sep 17 00:00:00 2001 From: Sander de Waal Date: Fri, 15 Jun 2018 13:24:04 +0200 Subject: [PATCH] Add selenium-standalone typings. --- types/selenium-standalone/index.d.ts | 80 ++++++++++++++++ .../selenium-standalone-tests.ts | 95 +++++++++++++++++++ types/selenium-standalone/tsconfig.json | 23 +++++ types/selenium-standalone/tslint.json | 1 + 4 files changed, 199 insertions(+) create mode 100644 types/selenium-standalone/index.d.ts create mode 100644 types/selenium-standalone/selenium-standalone-tests.ts create mode 100644 types/selenium-standalone/tsconfig.json create mode 100644 types/selenium-standalone/tslint.json diff --git a/types/selenium-standalone/index.d.ts b/types/selenium-standalone/index.d.ts new file mode 100644 index 0000000000..261a331922 --- /dev/null +++ b/types/selenium-standalone/index.d.ts @@ -0,0 +1,80 @@ +// Type definitions for selenium-standalone 6.15 +// Project: https://github.com/vvo/selenium-standalone +// Definitions by: Sander de Waal +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as http from "http"; +import { URL } from "url"; +import { ChildProcess, SpawnOptions } from "child_process"; + +export function install(cb: (error: Error | undefined, fsPaths: FsPaths) => void): void; +export function install(opts: InstallOpts, cb: (error: Error | undefined, fsPaths: FsPaths) => void): void; +export function install(optsCb: InstallOpts | ((error: Error | undefined, fsPaths: FsPaths) => void), cb?: (error: Error | undefined, fsPaths: FsPaths) => void): void; + +export function start(cb: (error: Error | null, selenium: ChildProcess) => void): void; +export function start(opts: StartOpts, cb: (error: Error | null, selenium: ChildProcess) => void): void; +export function start(optsCb: StartOpts | ((error: Error | null, selenium: ChildProcess) => void), cb?: (error: Error | null, selenium: ChildProcess) => void): void; + +export interface InstallOpts { + baseURL?: string; + basePath?: string; + version?: string; + drivers?: { + [browser: string]: { + version?: string; + arch: string | "ia32" | "x64"; + baseURL: string; + } + }; + progressCb?: (totalLength: number, progressLength: number, chunkLength: number) => void; + logger?: (message: string) => void; + requestOpts?: http.RequestOptions | string | URL; + cb?: (error: Error) => void; +} + +export interface StartOpts { + basePath?: string; + version?: string; + drivers?: { + [browser: string]: { + version?: string; + arch: string | "ia32" | "x64"; + baseURL: string; + } + }; + seleniumArgs?: string[]; + javaArgs?: string[]; + spawnOptions?: SpawnOptions; + spawnCb?: (selenium?: ChildProcess) => void; + javaPath?: string; + requestOpts?: http.RequestOptions | string | URL; + cb?: (error: Error, child: ChildProcess) => void; +} + +export interface FsPaths { + [x: string]: any; + chrome?: { + [x: string]: any; + installPath: string; + }; + ie?: { + [x: string]: any; + installPath: string; + }; + edge?: { + [x: string]: any; + installPath: string; + }; + firefox?: { + [x: string]: any; + installPath: string; + }; + selenium?: { + [x: string]: any; + installPath: string; + }; +} + +export { ChildProcess, SpawnOptions } from "child_process"; diff --git a/types/selenium-standalone/selenium-standalone-tests.ts b/types/selenium-standalone/selenium-standalone-tests.ts new file mode 100644 index 0000000000..543f3be983 --- /dev/null +++ b/types/selenium-standalone/selenium-standalone-tests.ts @@ -0,0 +1,95 @@ +"use strict"; +import { install, start, ChildProcess, FsPaths, InstallOpts, StartOpts } from "selenium-standalone"; + +// InstallOpts interface +let installOpts: InstallOpts = { + baseURL: "baseURL", + basePath: "basePath", + version: "version", + drivers: { + chrome: { + version: "chrome_version", + arch: "ia32", + baseURL: "baseURL a", + }, + firefox: { + version: "version", + arch: "ia64", + baseURL: "baseURL b", + } + }, + progressCb: (totalLength: number, progressLength: number, chunkLength: number) => {}, + logger: (message: string) => {}, + requestOpts: "requestOpts", + cb: (error: Error) => {}, +}; + +installOpts = {}; + +installOpts = { + requestOpts: { + agent: true, + host: "host", + family: 5 + }, +}; + +// StartOpts interface +let startOpts: StartOpts = { + basePath: "basePath", + version: "version", + drivers: { + chrome: { + version: "chrome_version", + arch: "ia32", + baseURL: "baseURL a", + }, + firefox: { + version: "version", + arch: "ia64", + baseURL: "baseURL b", + } + }, + seleniumArgs: ["bla", "foo"], + javaArgs: ["bla", "foo"], + spawnOptions: {}, + spawnCb: (selenium?: ChildProcess) => {}, + javaPath: "javaPath", + requestOpts: "requestOpts", + cb: (error: Error, child: ChildProcess) => {}, +}; +startOpts = {}; + +// FsPaths interface +let fsPaths: FsPaths = { + bla: "foo", + chrome: { + installPath: "installPath", + bla: "foo", + }, + ie: { + installPath: "installPath", + bla: "foo", + }, + edge: { + installPath: "installPath", + bla: "foo", + }, + firefox: { + installPath: "installPath", + bla: "foo", + }, + selenium: { + installPath: "installPath", + bla: "foo", + }, +}; +fsPaths = {}; + +// start method +start(startOpts, (error: Error | null, selenium: ChildProcess) => {}); +start((error: Error | null, selenium: ChildProcess) => {}); + +// install method +install(installOpts, (error: Error | undefined, fsPaths: FsPaths) => {}); +install((error: Error | undefined, fsPaths: FsPaths) => {}); diff --git a/types/selenium-standalone/tsconfig.json b/types/selenium-standalone/tsconfig.json new file mode 100644 index 0000000000..40a7f2cb34 --- /dev/null +++ b/types/selenium-standalone/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "selenium-standalone-tests.ts" + ] +} diff --git a/types/selenium-standalone/tslint.json b/types/selenium-standalone/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/selenium-standalone/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }