Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a CLI to Rooibos! #294

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions bsc-plugin/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,54 @@
"configurations": [
{
"name": "Run tests",
"type": "pwa-node",
"type": "node",
"request": "launch",
"smartStep": false,
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"sourceMaps": true,
"args": [
"--timeout",
"0"
],
"args": ["--timeout", "0"],
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js",
"<node_internals>/**/*.js"
],
"cwd": "${workspaceRoot}",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "Run Cli",
"type": "node",
"request": "launch",
"smartStep": false,
"program": "${workspaceFolder}/src/cli.ts",
"sourceMaps": true,
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"args": [
"src/cli.ts",
"--project=../tests/bsconfig.json",
"--host=${input:roku_host}",
"--password=${input:roku_password}"
],
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/typescript/**",
"!**/node_modules/vscode-languageserver/**"
],
"skipFiles": ["<node_internals>/**/*.js"],
"internalConsoleOptions": "openOnSessionStart"
}
],
"inputs": [
{
"id": "roku_host",
"type": "promptString",
"description": "Enter the IP address of your Roku device",
"default": ""
},
{
"id": "roku_password",
"type": "promptString",
"description": "Enter the password for your Roku device",
"default": ""
}
]
}
}
9,650 changes: 4,052 additions & 5,598 deletions bsc-plugin/package-lock.json

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions bsc-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,46 @@
"dist/**/!(*.spec.*)*"
],
"main": "dist/plugin.js",
"bin": {
"bsc": "dist/cli.js"
},
"directories": {
"test": "test"
},
"dependencies": {
"roku-debug": "^0.21.10",
"roku-deploy": "^4.0.0-alpha.1",
"source-map": "^0.7.3",
"undent": "^0.1.0",
"vscode-languageserver": "~6.1.1",
"vscode-languageserver-protocol": "~3.15.3"
"vscode-languageserver-protocol": "~3.15.3",
"yargs": "^16.2.0"
},
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/events": "^3.0.0",
"@types/fs-extra": "^5.0.1",
"@types/mocha": "^9.1.1",
"@types/node": "^14.18.41",
"@types/yargs": "^15.0.5",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"brighterscript": "^1.0.0-alpha.36",
"chai": "^4.2.0",
"chai-subset": "^1.6.0",
"coveralls": "^3.0.0",
"cz-conventional-changelog": "^3.3.0",
"cz-conventional-changelog": "^3.0.1",
"eslint": "^8.16.0",
"eslint-plugin-no-only-tests": "^2.4.0",
"fs-extra": "^10.1.0",
"minimatch": "^3.0.4",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"release-it": "^15.10.3",
"release-it": "^17.6.0",
"source-map-support": "^0.5.13",
"trim-whitespace": "^1.3.3",
"ts-node": "^9.0.0",
"typescript": "^4.9.5"
"typescript": "^4.7.2"
},
"preferGlobal": true,
"keywords": [
Expand Down
132 changes: 132 additions & 0 deletions bsc-plugin/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/env node

import { RendezvousTracker, TelnetAdapter } from 'roku-debug';
import type { BsConfig } from 'brighterscript';
import { LogLevel, util, ProgramBuilder } from 'brighterscript';
import * as yargs from 'yargs';
import { RokuDeploy } from 'roku-deploy';
import * as fs from 'fs';

let options = yargs
.usage('$0', 'Rooibos: a simple, flexible, fun Brightscript test framework for Roku Scenegraph apps')
.help('help', 'View help information about this tool.')
.option('project', { type: 'string', description: 'Path to a bsconfig.json project file.' })
.option('host', { type: 'string', description: 'Host of the Roku device to connect to. Overrides value in bsconfig file.' })
.option('password', { type: 'string', description: 'Password of the Roku device to connect to. Overrides value in bsconfig file.' })
.option('log-level', { type: 'string', defaultDescription: '"log"', description: 'The log level. Value can be "error", "warn", "log", "info", "debug".' })
.check((argv) => {
if (!argv.host) {
return new Error('You must provide a host. (--host)');
}
if (!argv.password) {
return new Error('You must provide a password. (--host)');
TwitchBronBron marked this conversation as resolved.
Show resolved Hide resolved
}
if (!argv.project) {
console.log('No project file specified. Using "./bsconfig.json"');

}
let bsconfigPath = argv.project || './bsconfig.json';

if (!fs.existsSync(bsconfigPath)) {
return new Error(`Unable to load ${bsconfigPath}`);
}
return true;
})
.argv;


async function main() {
let currentErrorCode = 0;
let bsconfigPath = options.project ?? 'bsconfig.json';

console.log(`Using bsconfig: ${bsconfigPath}`);

const rawConfig: BsConfig = util.loadConfigFile(bsconfigPath);
const bsConfig = util.normalizeConfig(rawConfig);

const host = options.host ?? bsConfig.host;
const password = options.password ?? bsConfig.password;

const logLevel = LogLevel[options['log-level']] ?? bsConfig.logLevel;
const builder = new ProgramBuilder();

builder.logger.logLevel = logLevel;


await builder.run(<any>{ ...options, retainStagingDir: true });

const rokuDeploy = new RokuDeploy();
const deviceInfo = await rokuDeploy.getDeviceInfo({ host: host });
const rendezvousTracker = new RendezvousTracker({ softwareVersion: deviceInfo['software-version'] }, { host: host, remotePort: 8085 } as any);
const telnet = new TelnetAdapter({ host: options.host }, rendezvousTracker);

telnet.logger.logLevel = logLevel;
await telnet.activate();
await telnet.connect();

const failRegex = /RESULT: Fail/g;
const endRegex = /\[END TEST REPORT\]/g;

async function doExit(emitAppExit = false) {
if (emitAppExit) {
(telnet as any).beginAppExit();
}
await rokuDeploy.keyPress({ host: options.host, key: 'home' });
process.exit(currentErrorCode);
}

telnet.on('console-output', (output) => {
console.log(output);

//check for Fails or Crashes
let failMatches = failRegex.exec(output);
if (failMatches && failMatches.length > 0) {
currentErrorCode = 1;
}

let endMatches = endRegex.exec(output);
if (endMatches && endMatches.length > 0) {
doExit(true).catch(e => {
console.error(e);
process.exit(1);
});
}
});

telnet.on('runtime-error', (error) => {
console.error(`Runtime Error: ${error.errorCode} - ${error.message}`);
currentErrorCode = 1;
doExit(true).catch(e => {
console.error(e);
process.exit(1);
});
});

telnet.on('app-exit', () => {
doExit(false).catch(e => {
console.error(e);
process.exit(1);
});
});

// Actually start the unit tests

//deploy a .zip package of your project to a roku device
async function deployBuiltFiles() {
const outFile = bsConfig.outFile;

await rokuDeploy.sideload({
password: password,
host: host,
outFile: outFile,
outDir: process.cwd()
});
}

await deployBuiltFiles();
}

main().catch(e => {
console.error(e);
process.exit(1);
});
106 changes: 41 additions & 65 deletions tests/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,43 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "tests",
"type": "brightscript",
"request": "launch",
"consoleOutput": "full",
"internalConsoleOptions": "neverOpen",
"preLaunchTask": "build-tests",
"envFile": "${workspaceFolder}/.env",
"host": "${env:ROKU_HOST}",
"password": "${env:ROKU_PASSWORD}",
"retainStagingFolder": true,
"stopOnEntry": false,
"files": [
"!**/images/*.*",
"!**/fonts/*.*",
"!*.jpg",
"!*.png",
"*",
"*.*",
"**/*.*",
"!*.zip",
"!**/*.zip"
],
"rootDir": "${workspaceFolder}/build",
"sourceDirs": ["${workspaceFolder}/src"],
"enableDebuggerAutoRecovery": true,
"stopDebuggerOnAppExit": true,
"enableVariablesPanel": false,
"injectRaleTrackerTask": false,
"enableDebugProtocol": true
},
{
"name": "watch tests",
"type": "brightscript",
"request": "launch",
"consoleOutput": "full",
"internalConsoleOptions": "neverOpen",
"preLaunchTask": "build-tests-watch",
"envFile": "${workspaceFolder}/.vscode/.env",
"host": "${env:ROKU_DEV_TARGET}",
"password": "${env:ROKU_DEVPASSWORD}",
"retainStagingFolder": true,
"stopOnEntry": false,
"files": [
"!**/images/*.*",
"!**/fonts/*.*",
"!*.jpg",
"!*.png",
"*",
"*.*",
"**/*.*",
"!*.zip",
"!**/*.zip"
],
"rootDir": "${workspaceFolder}/build",
"sourceDirs": ["${workspaceFolder}/src"],
"enableDebuggerAutoRecovery": true,
"stopDebuggerOnAppExit": true,
"enableVariablesPanel": false,
"injectRaleTrackerTask": false,
"enableDebugProtocol": true
}
]
"version": "0.2.0",
"configurations": [
{
"name": "tests",
"type": "brightscript",
"request": "launch",
"consoleOutput": "full",
"internalConsoleOptions": "neverOpen",
"preLaunchTask": "build-tests",
"envFile": "${workspaceFolder}/.env",
"host": "${env:ROKU_HOST}",
"password": "${env:ROKU_PASSWORD}",
"retainStagingFolder": true,
"stopOnEntry": false,
"rootDir": "${workspaceFolder}/build",
"enableDebuggerAutoRecovery": true,
"stopDebuggerOnAppExit": true,
"enableVariablesPanel": false,
"injectRaleTrackerTask": false,
"enableDebugProtocol": true
},
{
"name": "watch tests",
"type": "brightscript",
"request": "launch",
"consoleOutput": "full",
"internalConsoleOptions": "neverOpen",
"preLaunchTask": "build-tests-watch",
"envFile": "${workspaceFolder}/.env",
"host": "${env:ROKU_HOST}",
"password": "${env:ROKU_PASSWORD}",
"retainStagingFolder": true,
"stopOnEntry": false,
"rootDir": "${workspaceFolder}/build",
"enableDebuggerAutoRecovery": true,
"stopDebuggerOnAppExit": true,
"enableVariablesPanel": false,
"injectRaleTrackerTask": false,
"enableDebugProtocol": true
}
]
}
1 change: 0 additions & 1 deletion tests/bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"components/**/*.*"
],
"autoImportComponentScript": true,
"createPackage": false,
"stagingDir": "build",
"diagnosticFilters": [
{
Expand Down
5 changes: 2 additions & 3 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "bsc",
"clean": "rm -rf build && rm -rf out",
"watch": "npx bsc --project bsconfig.json --watch",
"test": "npm run build && npx ts-node ./scripts/runRooibosTests.ts --verbose"
"test": "source .env && npx ts-node ../bsc-plugin/src/cli.ts --host=$ROKU_HOST --password=$ROKU_PASSWORD"
},
"devDependencies": {
"@rokucommunity/bslint": "^1.0.0-alpha.36",
Expand All @@ -15,8 +15,7 @@
"dotenv": "^16.4.5",
"roku-debug": "^0.21.10",
"roku-deploy": "^4.0.0-alpha.1",
"ts-node": "^10.7.0",
"typescript": "^4.6.4"
"ts-node": "^10.7.0"
},
"repository": {
"type": "git",
Expand Down
Loading