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

feat(framework-tests): Improve framework tests by making it a bsc com… #114

Merged
merged 1 commit into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
38 changes: 38 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "test",
"type": "brightscript",
"request": "launch",
"consoleOutput": "full",
"internalConsoleOptions": "neverOpen",
"preLaunchTask": "build-tests",
"envFile": "${workspaceFolder}/frameworkTests/.vscode/.env",
"host": "${env:ROKU_DEV_TARGET}",
"password": "${env:ROKU_DEVPASSWORD}",
"retainStagingFolder": true,
"stopOnEntry": false,
"files": [
"!**/images/*.*",
"!**/fonts/*.*",
"!*.jpg",
"!*.png",
"*",
"*.*",
"**/*.*",
"!*.zip",
"!**/*.zip"
],
"rootDir": "${workspaceFolder}/frameworkTests/build",
"sourceDirs": [
"${workspaceFolder}/frameworkTests/src",
],
"enableDebuggerAutoRecovery": true,
"stopDebuggerOnAppExit": true,
"enableVariablesPanel": false,
"injectRaleTrackerTask": false,
"enableDebugProtocol": false
}
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"jira-plugin.workingProject": "",
"workbench.colorCustomizations": {
"statusBar.background": "#551A8B",
"statusBar.debuggingBackground": "#551A8B",
"panelTitle.activeBorder": "#ff0000",
"activityBar.background": "#452613",
"titleBar.activeBackground": "#61351A",
"titleBar.activeForeground": "#FDFAF9"
}
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build-tests",
"type": "shell",
"command": "gulp build && cd frameworkTests && export TS_NODE_COMPILER_OPTIONS='{\"incremental\":true, \"allowJs\":false}' && export TS_NODE_TRANSPILE_ONLY=true && gulp prePublishTests",
"problemMatcher": [],
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "build-tests-with-coverage",
"type": "shell",
"command": "gulp build && cd frameworkTests && export TS_NODE_COMPILER_OPTIONS='{\"incremental\":true, \"allowJs\":false}' && export TS_NODE_TRANSPILE_ONLY=true && gulp prepareCodeCoverageTests",
"problemMatcher": [],
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
"group": {
"kind": "test",
"isDefault": true
}
}
]
}
38 changes: 38 additions & 0 deletions frameworkTests/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "test",
"type": "brightscript",
"request": "launch",
"consoleOutput": "full",
"internalConsoleOptions": "neverOpen",
"preLaunchTask": "build-tests",
"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": false
}
]
}
41 changes: 41 additions & 0 deletions frameworkTests/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build-tests",
"type": "shell",
"command": "export TS_NODE_COMPILER_OPTIONS='{\"incremental\":true, \"allowJs\":false}' && export TS_NODE_TRANSPILE_ONLY=true && gulp prePublishTests",
"problemMatcher": [],
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "build-tests-with-coverage",
"type": "shell",
"command": "export TS_NODE_COMPILER_OPTIONS='{\"incremental\":true, \"allowJs\":false}' && export TS_NODE_TRANSPILE_ONLY=true && gulp prepareCodeCoverageTests",
"problemMatcher": [],
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
"group": {
"kind": "test",
"isDefault": true
}
}
]
}
18 changes: 18 additions & 0 deletions frameworkTests/bsConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"rootDir": "src",
"autoImportComponentScript": true,
"files": [
"manifest",
"source/**/*.*",
"components/**/*.*",
"images/**/*.*",
"font/**/*.*"
],
"diagnosticFilters": [
"source/tests/rooibosFunctionMap.brs",
"source/tests/rooibosDist.brs",
"**/RALETrackerTask.*",
"**/TestGlobalInitializer.*"
],
"logLevel": "warn"
}
2 changes: 0 additions & 2 deletions frameworkTests/components/tests/NodeExampleTests.bs

This file was deleted.

10 changes: 0 additions & 10 deletions frameworkTests/components/tests/NodeExampleTests.xml

This file was deleted.

182 changes: 182 additions & 0 deletions frameworkTests/gulpfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { series } from 'gulp';
import { FileProcessor } from 'burp-brightscript';
import { RooibosProcessor, createProcessorConfig } from 'rooibos-cli';
import { ProgramBuilder } from 'brighterscript';

import { inspect } from 'util';
import { BsConfig } from 'brighterscript/dist/BsConfig';

const gulp = require('gulp');
const gulpClean = require('gulp-clean');

let burpFileProcessor: FileProcessor;

export function createDirectories() {
return gulp
.src('*.*', { read: false })
.pipe(gulp.dest('build'))
.pipe(gulp.dest('out'));
}

export async function compile(cb) {
let builder = new ProgramBuilder();
burpFileProcessor = createBurpProcessor();
builder.addFileResolver(projectFileResolver);

let configFiles: any[] = [
"manifest",
"source/**/*.*",
"components/**/*.*",
"images/**/*.*",
"font/**/*.*"
];

let sourceDir = 'src';
let config: BsConfig = {
stagingFolderPath: 'build',
createPackage: false,
"rootDir": sourceDir,
"autoImportComponentScript": true,
"files": configFiles,
"diagnosticFilters": [
"source/rooibosFunctionMap.brs",
"**/RALETrackerTask.*",
1107,
1001
],
"showDiagnosticsInConsole": true
}

console.log(`using config ${inspect(config)}`);
await builder.run(config);
cb();
}

function projectFileResolver(pathAbsolute: string): string | undefined | Thenable<string | undefined> {
let updated = burpFileProcessor.processFileWithPath(pathAbsolute, pathAbsolute.toLowerCase().endsWith('.brs'));
return updated;
}

/*******************************************************************
* testing
*******************************************************************/

export async function prepareTests(cb) {
let testFiles = [];
testFiles = [
'**/tests/**/*.bs',
'**/tests/**/*.brs',
'!**/rooibosDist.brs',
'!**/rooibosFunctionMap.brs',
'!**/TestsScene.brs'
];
let config = createProcessorConfig({
projectPath: 'build',
outputPath: "source/tests",
showFailuresOnly: true,
testsFilePattern: testFiles
});
let processor = new RooibosProcessor(config);
await processor.processFiles();
cb();
}

export async function prepareCodeCoverageTests(cb) {
let config = createProcessorConfig({
projectPath: "build",
outputPath: "source/tests",
showFailuresOnly: true,
testsFilePattern: [
"**/tests/**/*.brs",
"!**/rooibosDist.brs",
"!**/rooibosFunctionMap.brs",
"!**/TestsScene.brs"
],
sourceFilePattern: [
"**/*.brs",
"**/*.xml",
"!**/tests",
"!**/rLog",
"!**/rLogComponents",
"!**/rooibosDist.brs",
"!**/rooibosFunctionMap.brs",
"!**/TestsScene.brs",
"!**/ThreadUtils.brs"
],
isRecordingCodeCoverage: true
});
let processor = new RooibosProcessor(config);
processor.processFiles();

cb();
}

/*******************************************************************
* logging
*******************************************************************/

export function createBurpProcessor(): FileProcessor {
//NB - this will be replaced entirely with bsconfig settings, so the bsc compiler
//will do this for us -this is a temporary solution
let replacements = getBsLogReplacements();
console.log('Adding crash resilience to unit tests, by skipping assertions after a failure');
replacements.push({
regex: '(^( *\\t*)m\\.assert)',
replacement: ' if not m.currentResult.isFail then $1'
});

return new FileProcessor({ replacements: replacements });
}

function getBsLogReplacements(): any[] {
let replacements = [];
const isLogDisabled = false;
if (isLogDisabled) {
console.log('stripping logs');
replacements = [
{
regex: '(^\\s*(m\\.)*(log_method|log_info|log_error|log_verbose|log_debug|log_warn)\\(\\[)',
replacement: '\'$1'
},
{
regex: '(^\\s*(m\\.)*(registerLogger)\\((\\s*"))',
replacement: '\'$1'
},
{
regex: '(^\\s*(m\\.)*(logMethod|logInfo|logError|logVerbose|logDebug|logWarn|log_debug)\\()',
replacement: '\'$1'
}
];
} else {
console.log('Adding line numbers and package paths to log output');
replacements = [
{
regex: '(^\\s*(?:m\\.)*(log_method|log_info|log_error|log_verbose)\\s*\\(\\s*\\[\\s*)m\\.className',
replacement: '$1source_location'
},
{
regex: '(^\\s*(?:m\\.)*(log_debug)\\s*\\(\\s*[0-9]*\\s*,\\s*\\[)\\s*m\\.className',
replacement: '$1source_location'
},
{
regex: '(^\\s*(m\\.)*(logInfo|logError|logVerbose|logDebug|logWarn|logMethod)\\((\\s*))',
replacement: '$1source_location, '
}
];
}
return replacements;
}

export function clean() {
let dirs = ['build', 'out'];

return gulp
.src(dirs, {
allowEmpty: true
})
.pipe(gulpClean({ force: true }));
};

/* Default task */
exports.prePublishTests = series(clean, createDirectories, compile, prepareTests);
exports.prePublishTests = series(clean, createDirectories, compile, prepareTests);
Loading