rooibos-roku
Version:
simple, flexible, fun brightscript test framework for roku scenegraph apps - roku brighterscript plugin
128 lines • 4.82 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestSuite = exports.TestBlock = void 0;
const path = require("path");
const roku_types_1 = require("brighterscript/dist/roku-types");
const Diagnostics_1 = require("../utils/Diagnostics");
const Utils_1 = require("./Utils");
const nativeNodeNames = Object.keys(roku_types_1.nodes);
/**
* base of test suites and blocks..
*/
class TestBlock {
constructor(annotation) {
this.annotation = annotation;
this.isValid = false;
this.isIncluded = false;
this.hasFailures = false;
this.hasSoloTests = false;
this.hasAsyncTests = false;
this.hasIgnoredTests = false;
}
get file() {
return this.annotation.file;
}
get pkgPath() {
return this.file.pkgPath;
}
get filePath() {
return this.file.pathAbsolute;
}
get name() {
return this.annotation.name;
}
get isSolo() {
return this.annotation.isSolo;
}
get isAsync() {
return this.annotation.isAsync;
}
get asyncTimeout() {
return this.annotation.asyncTimeout;
}
get isIgnored() {
return this.annotation.isIgnore;
}
set isIgnored(value) {
this.annotation.isIgnore = value;
}
}
exports.TestBlock = TestBlock;
class TestSuite extends TestBlock {
constructor(annotation, classStatement) {
var _a;
super(annotation);
this.testGroups = new Map();
this.hasSoloGroups = false;
this.isNodeTest = false;
this.registeredTestCount = 0;
this.classStatement = classStatement;
this.isNodeTest = annotation.nodeName && annotation.nodeName.trim() !== '';
this.nodeName = (_a = annotation.nodeName) === null || _a === void 0 ? void 0 : _a.trim();
if (!this.name) {
this.annotation.name = classStatement.name.text;
}
this.generatedNodeName = (this.name || 'ERROR').replace(/[^a-zA-Z0-9]/g, '_');
let pathBase = path.join('components', 'rooibos', 'generated');
this.xmlPkgPath = path.join(pathBase, this.generatedNodeName + '.xml');
this.bsPkgPath = path.join(pathBase, this.generatedNodeName + '.bs');
}
addGroup(group) {
var _a;
this.testGroups.set(group.name, group);
this.hasIgnoredTests || (this.hasIgnoredTests = group.hasIgnoredTests);
this.hasSoloTests || (this.hasSoloTests = group.hasSoloTests);
this.hasSoloGroups || (this.hasSoloGroups = group.isSolo);
(_a = this.annotation).isAsync || (_a.isAsync = group.hasAsyncTests);
this.isValid = true;
}
addDataFunctions(editor) {
if (this.isIncluded) {
(0, Utils_1.addOverriddenMethod)(this.file, this.annotation.annotation, this.classStatement, 'getTestSuiteData', `return ${this.asText()}`, editor);
}
}
getTestGroups() {
return [...this.testGroups.values()];
}
validate() {
if (this.isNodeTest) {
if (!this.nodeName) {
(0, Diagnostics_1.diagnosticNodeTestRequiresNode)(this.file, this.annotation.annotation);
}
else if (!this.file.program.getComponent(this.nodeName) && !nativeNodeNames.includes(this.nodeName.toLowerCase())) {
(0, Diagnostics_1.diagnosticNodeTestIllegalNode)(this.file, this.annotation.annotation, this.nodeName);
}
}
}
asText() {
let testGroups = this.isIncluded ? [...this.testGroups.values()].filter((testGroup) => testGroup.isIncluded)
.map((testGroup) => testGroup.asText()) : '';
return `{
name: ${(0, Utils_1.sanitizeBsJsonString)(this.name)}
isSolo: ${this.isSolo}
noCatch: ${this.annotation.noCatch}
isIgnored: ${this.isIgnored}
isAsync: ${this.isAsync}
pkgPath: "${this.pkgPath}"
filePath: "${this.filePath}"
lineNumber: ${this.classStatement.range.start.line + 1}
valid: ${this.isValid}
hasFailures: ${this.hasFailures}
hasSoloTests: ${this.hasSoloTests}
hasIgnoredTests: ${this.hasIgnoredTests}
hasSoloGroups: ${this.hasSoloGroups}
setupFunctionName: "${this.setupFunctionName || ''}"
tearDownFunctionName: "${this.tearDownFunctionName || ''}"
beforeEachFunctionName: "${this.beforeEachFunctionName || ''}"
afterEachFunctionName: "${this.afterEachFunctionName || ''}"
isNodeTest: ${this.isNodeTest || false}
isAsync: ${this.isAsync || false}
asyncTimeout: ${this.asyncTimeout || 60000}
nodeName: "${this.nodeName || ''}"
generatedNodeName: "${this.generatedNodeName || ''}"
testGroups: [${testGroups}]
}`;
}
}
exports.TestSuite = TestSuite;
//# sourceMappingURL=TestSuite.js.map