UNPKG

rooibos-roku

Version:

simple, flexible, fun brightscript test framework for roku scenegraph apps - roku brighterscript plugin

69 lines 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestCase = void 0; const Utils_1 = require("./Utils"); class TestCase { constructor(annotation, name, funcName, isSolo, isIgnored, lineNumber, params = null, paramTestIndex = 0, paramLineNumber = 0, expectedNumberOfParams = 0) { this.annotation = annotation; this.isSolo = isSolo; this.isAsync = annotation.isAsync; this.asyncTimeout = annotation.asyncTimeout; this.slow = annotation.slow; this.funcName = funcName; this.isIgnored = isIgnored; this.name = name; this.lineNumber = lineNumber; this.paramLineNumber = paramLineNumber; this.assertIndex = 0; this.rawParams = params; this.expectedNumberOfParams = expectedNumberOfParams; this.paramTestIndex = paramTestIndex; this.isParamTest = this.expectedNumberOfParams > 0; } asText() { let rawParamsText = this.fixBadJson(this.rawParams).replace(/null/g, 'invalid'); return ` { isSolo: ${this.isSolo} noCatch: ${this.annotation.noCatch} funcName: "${this.funcName || ''}" isIgnored: ${this.isIgnored} isAsync: ${this.isAsync} asyncTimeout: ${this.asyncTimeout || 2000} slow: ${this.slow} isParamTest: ${this.isParamTest} name: ${(0, Utils_1.sanitizeBsJsonString)(this.name)} lineNumber: ${this.lineNumber + 1} paramLineNumber: ${this.isParamTest ? this.paramLineNumber + 1 : 0} assertIndex: ${this.assertIndex} rawParams: ${rawParamsText} paramTestIndex: ${this.paramTestIndex} expectedNumberOfParams: ${this.expectedNumberOfParams} isParamsValid: ${(this.rawParams || []).length === this.expectedNumberOfParams} }`; } fixBadJson(o) { // In case of an array we'll stringify all objects. if (Array.isArray(o)) { return `[${o .map(obj => `${this.fixBadJson(obj)}`) .join(',') // eslint-disable-next-line @typescript-eslint/indent }]`; } // not an object, stringify using native function if (typeof o !== 'object' || o === null) { return JSON.stringify(o); } return `{${Object .keys(o) .map(key => { return `"${key.replace(/"/g, '')}":${this.fixBadJson(o[key])}`; }) .join(',') // eslint-disable-next-line @typescript-eslint/indent }}`; } } exports.TestCase = TestCase; //# sourceMappingURL=TestCase.js.map