Skip to content

Commit

Permalink
Fix bug introduced in Roku OS 13.0
Browse files Browse the repository at this point in the history
Add `getRtaConfig` to allow getting full config from components
Improve test screenshot file naming
  • Loading branch information
triwav committed Mar 22, 2024
1 parent 7f6505d commit 81158f7
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 112 deletions.
1 change: 1 addition & 0 deletions client/bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"rootDir": "../device",
"retainStagingFolder": true,
"plugins": [ "@rokucommunity/bslint" ],
"files": [
"components/**/*.+(xml|brs)",
Expand Down
78 changes: 78 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dependencies": {
"@suitest/types": "^4.6.0",
"ajv": "^6.12.6",
"filenamify": "^4.3.0",
"fs-extra": "^7.0.1",
"http-network-proxy": "^1.0.11",
"needle": "^2.9.1",
Expand Down
2 changes: 1 addition & 1 deletion client/rta-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"type": "array"
},
"enabled": {
"description": "Gives a simple way to enable to disable helper injection. Defaults to true",
"description": "Gives a simple way to enable or disable helper injection. Defaults to true",
"type": "boolean"
}
},
Expand Down
9 changes: 7 additions & 2 deletions client/src/ECP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ export class ECP {
this.device.setConfig(config);
}

public getConfig() {
/** Provides a way to get the whole config not just this classes' Config */
public getRtaConfig() {
if (!this.config) {
this.config = utils.getConfigFromEnvironmentOrConfigFile();
}
return this.config?.ECP;
return this.config;
}

public getConfig() {
return this.getRtaConfig()?.ECP;
}

public async sendText(text: string, options?: SendKeypressOptions & {raspTemplateVariable?: 'script-login' | 'script-password'}) {
Expand Down
9 changes: 7 additions & 2 deletions client/src/NetworkProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ export class NetworkProxy {
this.config = config;
}

public getConfig() {
/** Provides a way to get the whole config not just this classes' Config */
public getRtaConfig() {
if (!this.config) {
this.config = utils.getConfigFromEnvironmentOrConfigFile();
}
return this.config?.NetworkProxy;
return this.config;
}

public getConfig() {
return this.getRtaConfig()?.NetworkProxy;
}

/** Starts the proxy server and reads in the Charles config file and tells the Roku to start sending requests to the proxy server */
Expand Down
16 changes: 12 additions & 4 deletions client/src/OnDeviceComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ export class OnDeviceComponent {
this.device.setConfig(config);
}

public getConfig() {
/** Provides a way to get the whole config not just this classes' Config */
public getRtaConfig() {
if (!this.config) {
this.config = utils.getConfigFromEnvironmentOrConfigFile();
}
return this.config?.OnDeviceComponent;
return this.config;
}

public getConfig() {
return this.getRtaConfig()?.OnDeviceComponent;
}

//#region requests run on render thread
Expand Down Expand Up @@ -729,7 +734,7 @@ export class OnDeviceComponent {

const socketConnect = () => {
this.debugLog(`Attempting to connect to Roku at ${host} on port ${port}`);
socket.connect(9000, host);
socket.connect(port, host);
};

socket.on('connect', () => {
Expand Down Expand Up @@ -874,9 +879,12 @@ export class OnDeviceComponent {
const headerBuffer = Buffer.alloc(8);
headerBuffer.writeInt32LE(stringPayload.length, 0); // Write string payload length

const requestBuffers = [headerBuffer, Buffer.from(stringPayload, 'utf-8')];
if (binaryBuffer) {
headerBuffer.writeInt32LE(binaryBuffer.length, 4); // Write binary payload length
}

const requestBuffers = [headerBuffer, Buffer.from(stringPayload, 'utf-8')];
if (binaryBuffer) {
requestBuffers.push(binaryBuffer);
}

Expand Down
21 changes: 14 additions & 7 deletions client/src/RokuDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as fsExtra from 'fs-extra';
import * as querystring from 'needle/lib/querystring';
import type * as mocha from 'mocha';
import * as net from 'net';
import * as path from 'path';

import type { ConfigOptions } from './types/ConfigOptions';
import { utils } from './utils';
Expand All @@ -29,11 +30,16 @@ export class RokuDevice {
this.config = config;
}

public getConfig() {
/** Provides a way to get the whole config not just this classes' Config */
public getRtaConfig() {
if (!this.config) {
this.config = utils.getConfigFromEnvironmentOrConfigFile();
}
return this.config?.RokuDevice;
return this.config;
}

public getConfig() {
return this.getRtaConfig()?.RokuDevice;
}

public getCurrentDeviceConfig() {
Expand Down Expand Up @@ -82,7 +88,7 @@ export class RokuDevice {
fsExtra.writeFileSync(manifestPath, manifestContents);

// update the xml components that we are injecting into
const helperInjection = this.config?.OnDeviceComponent?.helperInjection;
const helperInjection = this.getRtaConfig()?.OnDeviceComponent?.helperInjection;
if (helperInjection && helperInjection.enabled !== false) {
for (const path of helperInjection.componentPaths) {
const xmlComponentContents = fsExtra.readFileSync(`${info.stagingDir}/${path}`, 'utf-8');
Expand Down Expand Up @@ -168,12 +174,13 @@ export class RokuDevice {
return await this.saveScreenshot(outputFilePath);
}

public async getTestScreenshot(contextOrSuite: mocha.Context | mocha.Suite) {
await this.getScreenshot(utils.getTestTitlePath(contextOrSuite).join('/'));
public async getTestScreenshot(contextOrSuite: mocha.Context | mocha.Suite, basePath = '', postFix = '', separator = '_') {
const screenshotPath = path.join(basePath, utils.getTestTitlePath(contextOrSuite).join(separator)) + postFix;
return await this.getScreenshot(screenshotPath);
}

public async getTelnetLog() {
return new Promise((resolve, reject) => {
return new Promise<string>((resolve, reject) => {
const socket = net.createConnection(8085, this.getCurrentDeviceConfig().host);

let content = '';
Expand Down Expand Up @@ -214,7 +221,7 @@ export class RokuDevice {
break;
}
}
return splitContents.join('\n');
return `Telnet output from ${this.getCurrentDeviceConfig().host}\n` + splitContents.join('\n');
}

private async generateScreenshot() {
Expand Down
2 changes: 1 addition & 1 deletion client/src/types/ConfigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface OnDeviceComponentConfigOptions {
/** List of paths to xml components to inject additional helpers into */
componentPaths: string[],

/** Gives a simple way to enable to disable helper injection. Defaults to true */
/** Gives a simple way to enable or disable helper injection. Defaults to true */
enabled?: boolean;
}
}
Expand Down
18 changes: 13 additions & 5 deletions client/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type * as fsExtra from 'fs-extra';
import type * as path from 'path';
import type * as Mocha from 'mocha';
import * as filenamify from 'filenamify';
import * as Ajv from 'ajv';
const ajv = new Ajv();

Expand Down Expand Up @@ -199,7 +200,7 @@ class Utils {
return error;
}

public getTestTitlePath(contextOrSuite: Mocha.Context | Mocha.Suite) {
public getTestTitlePath(contextOrSuite: Mocha.Context | Mocha.Suite, sterilize = true) {
let ctx: Mocha.Context;
if (contextOrSuite.constructor.name === 'Context') {
ctx = contextOrSuite as Mocha.Context;
Expand All @@ -209,16 +210,23 @@ class Utils {
throw new Error('Neither Mocha.Context or Mocha.Suite passed in');
}

if (!(ctx.test?.constructor.name === 'Test')) {
if (!(ctx.currentTest?.constructor.name === 'Test')) {
throw new Error('Mocha.Context did not contain test. At least surrounding Mocha.Suite must use non arrow function');
}

return ctx.test?.titlePath();
const pathParts = ctx.currentTest?.titlePath();
if (sterilize) {
for (const [index, pathPart] of pathParts.entries()) {
pathParts[index] = filenamify(pathPart);
}

}
return pathParts;
}

public generateFileNameForTest(contextOrSuite: Mocha.Context | Mocha.Suite, extension: string) {
public generateFileNameForTest(contextOrSuite: Mocha.Context | Mocha.Suite, extension: string, postFix = '', separator = '_') {
const titlePath = this.getTestTitlePath(contextOrSuite);
return titlePath.join('/') + `.${extension}`;
return titlePath.join(separator) + postFix + `.${extension}`;
}

public async ensureDirExistForFilePath(filePath: string) {
Expand Down
Loading

0 comments on commit 81158f7

Please sign in to comment.