-
Notifications
You must be signed in to change notification settings - Fork 0
/
browsertest.min.js.map
7 lines (7 loc) · 13.1 KB
/
browsertest.min.js.map
1
2
3
4
5
6
7
{
"version": 3,
"sources": ["browsertest.js"],
"sourcesContent": ["\"use strict\";\n\nexport {\n\tRun,\n}\nimport * as Unit from '../test_unit.js';\n\n// Test will call .trim() on string's golden and returned values. \n\n/**\n * -----------------------------------------------------------------------------\n *\n * Test defines a test to be run.\n *\n * - name: Name of the test to display to the user.\n * - func: Test function to execute.\n * - golden: Correct return value for the test.\n *\n * @typedef {object} Test\n * @property {string} name\n * @property {Function} func\n * @property {string} golden\n *\n * -----------------------------------------------------------------------------\n *\n * Tests defines an array of `Test` objects to be run.\n * @typedef {Array<Test>} Tests\n *\n * -----------------------------------------------------------------------------\n *\n * TestsToRun defines the tests that will be ran on the Browser Test JS page.\n * @typedef {Tests} TestsToRun\n *\n * -----------------------------------------------------------------------------\n *\n * Stylesheet is the object for displaying CSS/stylesheets on the test page.\n *\n * - href: The link to the stylesheet. Required.\n * - rel: The relationship between the linked source and current\n * document. Defaults to \"stylesheet\"\n * - integrity: The digest/checksum for the given source/stylesheet.\n * - crossorigin: Sets the crossorigin for requests to the resource.\n *\n * @typedef {object} Stylesheet\n * @property {string} href\n * @property {string} [rel]\n * @property {string} [integrity]\n * @property {string} [crossorigin]\n *\n * -----------------------------------------------------------------------------\n *\n * TestGUIOptions defines options for the Browser Test JS Testing page. All\n * options are optional, and will use the default if not proivded.\n *\n * Currently supported options:\n *\n * For 'header', 'footer', and any other Custom HTML elements:\n * These options must be written as HTML, but encapsulated in a string. If set,\n * the string will be used as the inner HTML and appended to the custom portion\n * of the page.\n * \n * 'header' and 'stylesheet' are mutually exclusive, with 'header' taking\n * precedence. If they are both set, `header` will be used. If just wanting\n * to use a custom stylesheet, `stylesheet` must be set, and `header` must not.\n * If wanting a custom header and stylesheet, the custom stylesheet must go in\n * the `header`, and header must be set.\n * \n * - header: Custom header.\n * - stylesheet: Custom stylesheet.\n * - footer: Custom footer.\n * - main_image: Custom main image.\n * - html_test_area: Custom HTML for testing and page customization.\n *\n * @typedef {object} TestGUIOptions\n * @property {Stylesheet} [header]\n * @property {Stylesheet} [stylesheet]\n * @property {String=Element} [footer]\n * @property {String=Image} [main_image]\n * @property {Stylesheet} [html_test_area]\n *\n * -----------------------------------------------------------------------------\n *\n * TestBrowserJS defines an object for projects/packages to interact with the\n * browsertestjs library.\n *\n * When Browser Test JS page is loaded, it will attempt to retrieve the\n * TestBrowserJS object from the `unit_test.js` file. It will use this object to\n * 1.) Run the tests 2.) Make modifications to the GUI.\n *\n * - TestsToRun: Holds the tests to be ran for the given application/package.\n * - TestOptions: Holds the options to be used for the GUI.\n *\n * @typedef {object} TestBrowserJS\n * @property {TestsToRun} TestsToRun\n * @property {TestGUIOptions} TestGUIOptions\n *\n * -----------------------------------------------------------------------------\n */\n\nlet totalTestsToRun = 0;\nlet totalTestsRan = 0;\nlet testPastCount = 0;\nlet testFailCount = 0;\n\n// Template for displaying test results in the GUI. Must be cloned.\nconst jsResultTemplate = document.getElementById('js_test_results');\n\n/**\n * Calls tests to be ran, after the DOM has been loaded.\n * See README for structuring your directory and `test_unit.js` file.\n **/\ndocument.addEventListener('DOMContentLoaded', () => {\n\t// If imported, don't run onload as determined by existence of #NoModuleFound.\n\tlet noMod = document.getElementById('NoModuleFound');\n\tif (noMod == null) {\n\t\treturn;\n\t}\n\n\tdocument.getElementById('NoModuleFound').hidden = true;\n\tdocument.getElementById('testsResultsMeta').hidden = false;\n\tlet tbjs = Unit.TestBrowserJS;\n\tif (tbjs === null || tbjs == undefined || typeof tbjs !== \"object\" || Object.keys(tbjs).length <= 0) {\n\t\tconsole.error(\"TestBrowserJS: The TestBrowserJS object is not properly defined, please see README.\", tbjs);\n\t} else {\n\t\tif (tbjs.TestGUIOptions === null || tbjs.TestGUIOptions === undefined || typeof tbjs.TestGUIOptions !== \"object\") {\n\t\t\ttbjs.TestGUIOptions = {};\n\t\t}\n\t\tsetGUI(tbjs);\n\n\t\tif (Array.isArray(tbjs.TestsToRun) && tbjs.TestsToRun.length > 0) {\n\t\t\tRun(tbjs.TestsToRun);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tdocument.getElementById('testsResultsMeta').innerHTML = \"\";\n\tdocument.getElementById('noTestsToRun').hidden = false;\n});\n\n/**\n * Runs all of the tests in the 'TestsToRun' array.\n * @param {Tests} tests\n * @returns {void}\n */\nasync function Run(tests) {\n\ttotalTestsToRun = Object.entries(tests).length;\n\tlet values = Object.values(tests);\n\tfor (let i = 0; i < totalTestsToRun; i++) {\n\t\tvar test = {};\n\t\ttest.name = values[i].name;\n\t\ttest.golden = values[i].golden;\n\t\ttry {\n\t\t\ttest.result = await values[i].func();\n\t\t} catch (err) {\n\t\t\tconsole.error(err);\n\t\t\ttest.result = err;\n\t\t}\n\t\tappendResult(test);\n\t}\n\tstats();\n};\n\n\n\n\n\n/**\n * stats displays statistics about the tests that are being run, out to the\n * screen. It will show the tests that ran, and which passed and failed.\n *\n * @returns {void} Displays the stats on the page.\n */\nasync function stats() {\n\tdocument.getElementById(\"totalTestsToRun\").innerText = totalTestsToRun;\n\tdocument.getElementById(\"totalTestsRan\").innerText = totalTestsRan;\n\tdocument.getElementById(\"testPastCount\").innerText = testPastCount;\n\tdocument.getElementById(\"testFailCount\").innerText = testFailCount;\n\n\tdocument.getElementById(\"testsRunning\").hidden = true;\n\tif (testFailCount == 0) {\n\t\tdocument.getElementById(\"testsPassed\").hidden = false;\n\t} else {\n\t\tdocument.getElementById(\"testsFailed\").hidden = false;\n\t}\n};\n\n/**\n * appendResults appends the results to the div on the page.\n *\n * @param {object} obj The object that holds the name of the test,\n * function, expected result, and actual results.\n * @returns {void}\n */\nfunction appendResult(obj) {\n\tlet clone = jsResultTemplate.content.cloneNode(true);\n\tlet test = \"\" + obj.name + \"\\: \";\n\n\tif (typeof obj.golden == \"string\") {\n\t\t// Trim outer strings making tests easier to write. \n\t\tvar failed = (obj.result.trim() != obj.golden.trim())\n\t} else {\n\t\tfailed = obj.result != obj.golden\n\t}\n\tif (failed) {\n\t\tconsole.error(\"\u274C Failed. Got: \" + obj.result + \" Expected: \" + obj.golden);\n\t\ttest += \"\u274C Failed\";\n\t\tclone.querySelector('div').classList.add(\"text-danger\")\n\t\tclone.querySelector('.result').textContent = \"Got: \" + obj.result;\n\t\tclone.querySelector('.expected').innerHTML = \"Expected: \" + obj.golden;\n\t\ttestFailCount++;\n\t} else {\n\t\t// Test Passed\n\t\tclone.querySelector('div').classList.add(\"text-success\")\n\t\ttest += \"\u2705 Passed\";\n\t\ttestPastCount++;\n\t}\n\ttotalTestsRan++;\n\n\tclone.querySelector('.test').textContent = test;\n\tdocument.getElementById(\"testsResultsList\").append(clone);\n};\n\n\n\n// Uses Bootstrap 5 CDN as default stylesheet/CSS.\nconst DefaultPageStylesheet = {\n\thref: \"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css\",\n\trel: \"stylesheet\",\n\tintegrity: \"sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx\",\n\tcrossOrigin: \"anonymous\"\n};\n\n/**\n * Sets the Browser Test JS GUI. Sets values if provided, otherwise sets defaults. \n *\n * @param {TestBrowserJS} tbjs Object. Options for TestBrowserJS.\n * @returns {void}\n **/\nfunction setGUI(tbjs) {\n\tlet keys = Object.keys(tbjs.TestGUIOptions);\n\tif (keys.length <= 0) {\n\t\tsetStyleSheet(DefaultPageStylesheet);\n\t\treturn;\n\t}\n\n\t// Perform checks for what options are provided and what is default.\n\n\t// Set custom header and stylesheet if provided\n\tif (keys.includes(\"header\")) {\n\t\tdocument.getElementById('CustomHeader').innerHTML = tbjs.TestGUIOptions.header;\n\t} else if (keys.includes(\"stylesheet\")) {\n\t\t// Set stylesheet if custom provided, and custom header is not.\n\t\tsetStyleSheet(tbjs.TestGUIOptions.stylesheet);\n\t} else {\n\t\t// If no custom header or stylesheet is given, use defaults.\n\t\tsetStyleSheet(DefaultPageStylesheet);\n\t}\n\n\t// Set custom footer if provided\n\tif (keys.includes(\"footer\")) {\n\t\tdocument.getElementById('CustomFooter').innerHTML = tbjs.TestGUIOptions.footer;\n\t}\n\t// Set custom main image if given.\n\tif (keys.includes(\"main_image\")) {\n\t\tdocument.getElementById('MainImage').src = tbjs.TestGUIOptions.main_image;\n\t}\n\t// Set custom custom HTML testing area in body if given.\n\tif (keys.includes(\"html_test_area\")) {\n\t\tdocument.getElementById('htmlTestArea').innerHTML = tbjs.TestGUIOptions.html_test_area;\n\t}\n}\n\n/**\n * Sets the stylesheet for the Browser Test JS page, with the given\n * Stylesheet object.\n *\n * @param {Stylesheet} ss Object. Stylesheet object.\n * @returns {void}\n **/\nfunction setStyleSheet(ss) {\n\tlet stylesheet = document.getElementById('bootstrapCSS');\n\tstylesheet.href = ss.href;\n\tlet keys = Object.keys(ss);\n\tif (keys.includes(\"crossOrigin\")) {\n\t\tstylesheet.crossOrigin = ss.crossOrigin;\n\t} else {\n\t\tstylesheet.crossOrigin = DefaultPageStylesheet.crossOrigin;\n\t}\n\tif (keys.includes(\"integrity\")) {\n\t\tstylesheet.integrity = ss.integrity;\n\t}\n\tif (keys.includes(\"rel\")) {\n\t\tstylesheet.rel = ss.rel;\n\t} else {\n\t\tstylesheet.rel = DefaultPageStylesheet.rel;\n\t}\n\n\t// console.log(stylesheet); // debugging\n}"],
"mappings": "AAKA,UAAYA,MAAU,kBA8FtB,IAAIC,EAAkB,EAClBC,EAAgB,EAChBC,EAAgB,EAChBC,EAAgB,EAGpB,MAAMC,EAAmB,SAAS,eAAe,iBAAiB,EAMlE,SAAS,iBAAiB,mBAAoB,IAAM,CAGnD,GADY,SAAS,eAAe,eAAe,GACtC,KACZ,OAGD,SAAS,eAAe,eAAe,EAAE,OAAS,GAClD,SAAS,eAAe,kBAAkB,EAAE,OAAS,GACrD,IAAIC,EAAON,EAAK,cAChB,GAAIM,IAAS,MAAQA,GAAQ,MAAa,OAAOA,GAA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O,KAAKE,CAAE,EACrBF,EAAK,SAAS,aAAa,EAC9BG,EAAW,YAAcD,EAAG,YAE5BC,EAAW,YAAcJ,EAAsB,YAE5CC,EAAK,SAAS,WAAW,IAC5BG,EAAW,UAAYD,EAAG,WAEvBF,EAAK,SAAS,KAAK,EACtBG,EAAW,IAAMD,EAAG,IAEpBC,EAAW,IAAMJ,EAAsB,GAIzC",
"names": ["Unit", "totalTestsToRun", "totalTestsRan", "testPastCount", "testFailCount", "jsResultTemplate", "tbjs", "setGUI", "Run", "tests", "values", "i", "test", "err", "appendResult", "stats", "obj", "clone", "failed", "DefaultPageStylesheet", "keys", "setStyleSheet", "ss", "stylesheet"]
}