roku-test-automation
Advanced tools
Comparing version 1.0.17 to 1.0.19
@@ -14,16 +14,17 @@ import { RokuDevice } from './RokuDevice'; | ||
private app; | ||
private server?; | ||
constructor(device: RokuDevice, config: ConfigOptions); | ||
getValueAtKeyPath(base: keyof typeof KeyPathBaseTypes, keyPath: string): Promise<any>; | ||
getValueAtKeyPath(base: KeyPathBaseTypes, keyPath: string): Promise<any>; | ||
getValuesAtKeyPaths(requests: { | ||
[key: string]: { | ||
base: keyof typeof KeyPathBaseTypes; | ||
base: KeyPathBaseTypes; | ||
keyPath: string; | ||
}; | ||
}): Promise<any>; | ||
setValueAtKeyPath(keyPath: string, value: string | number | boolean | [string]): Promise<void>; | ||
setValueAtKeyPath(base: KeyPathBaseTypes, keyPath: string, value: any): Promise<any>; | ||
private sendHandShakeRequest; | ||
private sendRequest; | ||
setupConnections(): Promise<void>; | ||
private onSocketClosed; | ||
shutdown(): void; | ||
private setupExpress; | ||
} |
@@ -55,7 +55,7 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, json; | ||
var result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.sendRequest({ | ||
type: OnDeviceComponentRequest_1.RequestType.getValueAtKeyPath, | ||
type: 'getValueAtKeyPath', | ||
args: { | ||
@@ -68,6 +68,3 @@ base: base, | ||
result = _a.sent(); | ||
json = result.body; | ||
if (!json.success) | ||
throw new Error(json.error.message); | ||
return [2 /*return*/, json.value]; | ||
return [2 /*return*/, result.body.value]; | ||
} | ||
@@ -79,7 +76,7 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, json; | ||
var result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.sendRequest({ | ||
type: OnDeviceComponentRequest_1.RequestType.getValuesAtKeyPaths, | ||
type: 'getValuesAtKeyPaths', | ||
args: { | ||
@@ -91,6 +88,3 @@ requests: requests | ||
result = _a.sent(); | ||
json = result.body; | ||
if (!json.success) | ||
throw new Error(json.error.message); | ||
return [2 /*return*/, json]; | ||
return [2 /*return*/, result.body]; | ||
} | ||
@@ -100,7 +94,23 @@ }); | ||
}; | ||
OnDeviceComponent.prototype.setValueAtKeyPath = function (keyPath, value) { | ||
OnDeviceComponent.prototype.setValueAtKeyPath = function (base, keyPath, value) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var keyPathParts, args, result; | ||
return __generator(this, function (_a) { | ||
console.log('Not implemented yet'); | ||
return [2 /*return*/]; | ||
switch (_a.label) { | ||
case 0: | ||
keyPathParts = keyPath.split('.'); | ||
args = { | ||
base: base, | ||
field: keyPathParts.pop(), | ||
keyPath: keyPathParts.join('.'), | ||
value: value | ||
}; | ||
return [4 /*yield*/, this.sendRequest({ | ||
type: 'setValueAtKeyPath', | ||
args: args | ||
})]; | ||
case 1: | ||
result = _a.sent(); | ||
return [2 /*return*/, result.body]; | ||
} | ||
}); | ||
@@ -115,3 +125,3 @@ }); | ||
case 0: return [4 /*yield*/, this.sendRequest({ | ||
type: OnDeviceComponentRequest_1.RequestType.handshake, | ||
type: 'handshake', | ||
args: { | ||
@@ -137,3 +147,3 @@ version: OnDeviceComponent.version | ||
_a.sent(); | ||
if (request.type !== OnDeviceComponentRequest_1.RequestType.handshake && !this.handshakeComplete) { | ||
if (request.type !== OnDeviceComponentRequest_1.RequestEnum[OnDeviceComponentRequest_1.RequestEnum.handshake] && !this.handshakeComplete) { | ||
throw new Error("Handshake not complete. Can't continue"); | ||
@@ -145,3 +155,3 @@ } | ||
callbackPort: this.callbackListenPort, | ||
type: OnDeviceComponentRequest_1.RequestType[request.type], | ||
type: request.type, | ||
args: request.args | ||
@@ -172,3 +182,3 @@ }; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var callbackListenPort, server; | ||
var callbackListenPort; | ||
var _this = this; | ||
@@ -180,3 +190,3 @@ return __generator(this, function (_a) { | ||
callbackListenPort = this.config.server.callbackListenPort; | ||
server = this.app.listen(callbackListenPort, function () { | ||
this.server = this.app.listen(callbackListenPort, function () { | ||
console.log("Listening for callbacks on " + callbackListenPort); | ||
@@ -203,6 +213,3 @@ }); | ||
e_1 = _a.sent(); | ||
server.close(); | ||
this.callbackListenPort = undefined; | ||
this.client.end(); | ||
this.socketConnected = false; | ||
this.shutdown(); | ||
reject(e_1.message); | ||
@@ -214,5 +221,5 @@ return [3 /*break*/, 4]; | ||
}); }); | ||
_this.client.on('error', _this.onSocketClosed); | ||
_this.client.on('close', _this.onSocketClosed); | ||
_this.client.on('end', _this.onSocketClosed); | ||
_this.client.once('error', function (e) { | ||
console.log(e); | ||
}); | ||
})]; | ||
@@ -222,6 +229,10 @@ }); | ||
}; | ||
OnDeviceComponent.prototype.onSocketClosed = function () { | ||
console.log("onSocketClosedonSocketClosedonSocketClosedonSocketClosedonSocketClosed"); | ||
this.callbackListenPort = undefined; | ||
this.socketConnected = false; | ||
OnDeviceComponent.prototype.shutdown = function () { | ||
var _a; | ||
if (this.socketConnected) { | ||
this.callbackListenPort = undefined; | ||
this.socketConnected = false; | ||
this.client.end(); | ||
(_a = this.server) === null || _a === void 0 ? void 0 : _a.close(); | ||
} | ||
}; | ||
@@ -239,2 +250,3 @@ OnDeviceComponent.prototype.setupExpress = function () { | ||
res.send('OK'); | ||
delete _this.sentRequests[id]; | ||
} | ||
@@ -241,0 +253,0 @@ else { |
import * as express from 'express'; | ||
export declare enum RequestType { | ||
export declare enum RequestEnum { | ||
callFunc = 0, | ||
hasFocus = 1, | ||
isInFocusChain = 2, | ||
getValueAtKeyPath = 3, | ||
getValuesAtKeyPaths = 4, | ||
handshake = 5, | ||
observeField = 6, | ||
observeFocus = 7, | ||
setFocus = 8, | ||
setValueAtKeyPath = 9 | ||
getRoots = 3, | ||
getValueAtKeyPath = 4, | ||
getValuesAtKeyPaths = 5, | ||
handshake = 6, | ||
observeField = 7, | ||
observeFocus = 8, | ||
setFocus = 9, | ||
setValueAtKeyPath = 10 | ||
} | ||
export declare enum KeyPathBaseTypes { | ||
export declare type RequestTypes = keyof typeof RequestEnum; | ||
export declare enum KeyPathBaseEnum { | ||
global = 0, | ||
scene = 1 | ||
} | ||
export declare type KeyPathBaseTypes = keyof typeof KeyPathBaseEnum; | ||
export interface OnDeviceComponentRequest { | ||
type: RequestType; | ||
type: RequestTypes; | ||
args: object; | ||
@@ -21,0 +24,0 @@ callback?: OnDeviceComponentRequestCallback; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var RequestType; | ||
(function (RequestType) { | ||
RequestType[RequestType["callFunc"] = 0] = "callFunc"; | ||
RequestType[RequestType["hasFocus"] = 1] = "hasFocus"; | ||
RequestType[RequestType["isInFocusChain"] = 2] = "isInFocusChain"; | ||
RequestType[RequestType["getValueAtKeyPath"] = 3] = "getValueAtKeyPath"; | ||
RequestType[RequestType["getValuesAtKeyPaths"] = 4] = "getValuesAtKeyPaths"; | ||
RequestType[RequestType["handshake"] = 5] = "handshake"; | ||
RequestType[RequestType["observeField"] = 6] = "observeField"; | ||
RequestType[RequestType["observeFocus"] = 7] = "observeFocus"; | ||
RequestType[RequestType["setFocus"] = 8] = "setFocus"; | ||
RequestType[RequestType["setValueAtKeyPath"] = 9] = "setValueAtKeyPath"; | ||
})(RequestType = exports.RequestType || (exports.RequestType = {})); | ||
var KeyPathBaseTypes; | ||
(function (KeyPathBaseTypes) { | ||
KeyPathBaseTypes[KeyPathBaseTypes["global"] = 0] = "global"; | ||
KeyPathBaseTypes[KeyPathBaseTypes["scene"] = 1] = "scene"; | ||
})(KeyPathBaseTypes = exports.KeyPathBaseTypes || (exports.KeyPathBaseTypes = {})); | ||
var RequestEnum; | ||
(function (RequestEnum) { | ||
RequestEnum[RequestEnum["callFunc"] = 0] = "callFunc"; | ||
RequestEnum[RequestEnum["hasFocus"] = 1] = "hasFocus"; | ||
RequestEnum[RequestEnum["isInFocusChain"] = 2] = "isInFocusChain"; | ||
RequestEnum[RequestEnum["getRoots"] = 3] = "getRoots"; | ||
RequestEnum[RequestEnum["getValueAtKeyPath"] = 4] = "getValueAtKeyPath"; | ||
RequestEnum[RequestEnum["getValuesAtKeyPaths"] = 5] = "getValuesAtKeyPaths"; | ||
RequestEnum[RequestEnum["handshake"] = 6] = "handshake"; | ||
RequestEnum[RequestEnum["observeField"] = 7] = "observeField"; | ||
RequestEnum[RequestEnum["observeFocus"] = 8] = "observeFocus"; | ||
RequestEnum[RequestEnum["setFocus"] = 9] = "setFocus"; | ||
RequestEnum[RequestEnum["setValueAtKeyPath"] = 10] = "setValueAtKeyPath"; | ||
})(RequestEnum = exports.RequestEnum || (exports.RequestEnum = {})); | ||
var KeyPathBaseEnum; | ||
(function (KeyPathBaseEnum) { | ||
KeyPathBaseEnum[KeyPathBaseEnum["global"] = 0] = "global"; | ||
KeyPathBaseEnum[KeyPathBaseEnum["scene"] = 1] = "scene"; | ||
})(KeyPathBaseEnum = exports.KeyPathBaseEnum || (exports.KeyPathBaseEnum = {})); |
{ | ||
"name": "roku-test-automation", | ||
"version": "1.0.17", | ||
"version": "1.0.19", | ||
"description": "Helps with automating functional tests", | ||
@@ -9,4 +9,5 @@ "main": "dist/index.js", | ||
"build": "rimraf out && tsc", | ||
"preversion": "npm run build && npm run tslint && npm run test", | ||
"prepublishOnly": "npm run build && npm run tslint && cp -r ../device ./dist/device", | ||
"test": "nyc --exclude src/RokuDevice.ts mocha --full-trace --exclude src/RokuDevice.spec.ts src/**/*.spec.ts", | ||
"tslint": "tslint \"./src/**/*.ts\" --outputAbsolutePaths --project tsconfig.json", | ||
"test:device": "nyc mocha --full-trace src/RokuDevice.spec.ts", | ||
@@ -51,3 +52,3 @@ "test:all": "nyc mocha --full-trace src/**/*.spec.ts", | ||
"ts-node": "^8.8.2", | ||
"tslint": "^5.9.1", | ||
"tslint": "^5.20.1", | ||
"typescript": "^3.8.3" | ||
@@ -54,0 +55,0 @@ }, |
138505
40
1238