Socket
Socket
Sign inDemoInstall

@skills17/mocha-web-helpers

Package Overview
Dependencies
78
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0

2

dist/main.js

@@ -1,1 +0,1 @@

(()=>{"use strict";var t={695:(t,e,s)=>{function r(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n=s(359);e.default=class{constructor(){r(this,"source",["./src/**"]),r(this,"tests",["./tests/**/*.@(spec|test).@(js|ts)"]),r(this,"localHistory",!1),r(this,"serve",{enabled:!1,port:3e3,bind:"127.0.0.1",mapping:{"/":"./src"}}),r(this,"points",{defaultPoints:1,strategy:n.Strategy.Add}),r(this,"groups",[])}loadGroups(t){return t.map(((t,e)=>{if(!t.match)throw new Error(`config.json validation error: group #${e} does not contain a 'match' property`);const s=void 0!==t.defaultPoints?t.defaultPoints:this.points.defaultPoints,r=void 0!==t.strategy?t.strategy:this.points.strategy;if(void 0!==t.maxPoints&&r!==n.Strategy.Deduct)throw new Error(`config.json validation error: property 'maxPoints' can only be set for strategy 'deduct'. Found in group #${e} (${t.match})`);const i=new n.Group(t.match,s,r,t.displayName,t.maxPoints);return t.tests&&Array.isArray(t.tests)&&t.tests.forEach(((s,r)=>{if(!s.match)throw new Error(`config.json validation error: test #${r} in group #${e} (${t.match}) does not contain a 'match' property`);i.addOverride(new n.Override(s.match,s.required,s.points))})),i}))}load(t){this.id=t.id,this.type=t.type,this.source=t.source??this.source,this.tests=t.tests??this.tests,this.localHistory=t.localHistory??this.localHistory,this.serve={...this.serve,...t.serve},this.points={...this.points,...t.points},this.groups=t.groups??this.groups}createTestRun(){const t=new n.TestRun;return this.loadGroups(this.groups).forEach((e=>t.addGroup(e))),t}getId(){return this.id}getType(){return this.type}getSource(){return this.source}getTests(){return this.tests}getServe(){return this.serve}getPoints(){return this.points}getGroups(){return this.groups}isLocalHistoryEnabled(){return this.localHistory}}},556:(t,e,s)=>{Object.defineProperty(e,"ZP",{enumerable:!0,get:function(){return r.default}});var r=n(s(695));n(s(806)),n(s(871)),n(s(872)),n(s(680));function n(t){return t&&t.__esModule?t:{default:t}}},806:()=>{},871:()=>{},872:()=>{},680:()=>{},210:(t,e,s)=>{function r(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n=a(s(715)),i=a(s(104));function a(t){return t&&t.__esModule?t:{default:t}}e.default=class{constructor(t,e,s,n,i){r(this,"extraTests",{}),r(this,"tests",{}),r(this,"overrides",[]),this.match=t,this.defaultPoints=e,this.strategy=s,this.displayName=n,this.maxPoints=i,this.pattern=new RegExp(`^${t}$`)}addNormalTest(t,e){if(this.tests[t])throw new Error(`A test with the same name already exists in the same group. Test name: ${t}`);const s=this.getOverrideForTest(t);this.tests[t]=new i.default(t,s?.getPoints()||this.defaultPoints,e,s?.isRequired()||!1),void 0!==this.extraTests[t]&&e&&!this.extraTests[t]&&this.tests[t].setManualCheck(!0)}addExtraTest(t,e){if(this.extraTests[t])throw new Error(`An extra test with the same name already exists in the same group. Test name: ${t}`);this.extraTests[t]=e,this.tests[t]&&this.tests[t].isSuccessful()&&!e&&this.tests[t].setManualCheck(!0)}getOverrideForTest(t){return this.overrides.find((e=>e.matches(t)))}matches(t){return this.pattern.test(t)}addTest(t,e,s){e?this.addExtraTest(t,s):this.addNormalTest(t,s)}addOverride(t){this.overrides.push(t)}getPoints(){let t=!1;const e=this.getTests().reduce(((e,s)=>(s.isRequired()&&!s.isSuccessful()&&(t=!0),this.strategy===n.default.Add?e+s.getPoints():s.isSuccessful()?e:e-s.getMaxPoints())),this.strategy===n.default.Deduct?this.getMaxPoints():0);return t?0:Math.max(e,0)}getMaxPoints(){return this.strategy===n.default.Deduct&&void 0!==this.maxPoints?this.maxPoints:this.getTests().reduce(((t,e)=>t+e.getMaxPoints()),0)}getMissingExtraTests(){return Object.keys(this.tests).filter((t=>void 0===this.extraTests[t])).map((t=>this.tests[t]))}getMissingNormalTests(){return Object.keys(this.extraTests).filter((t=>void 0===this.tests[t]))}hasTests(){return Object.keys(this.tests).length>0||Object.keys(this.extraTests).length>0}getDefaultPoints(){return this.defaultPoints}getStrategy(){return this.strategy}getDisplayName(){return this.displayName??this.match}getTests(){return Object.values(this.tests)}getPattern(){return this.match}requiresManualCheck(){return!!this.getTests().find((t=>t.requiresManualCheck()))}toJSON(){return{group:this.getDisplayName(),points:this.getPoints(),maxPoints:this.getMaxPoints(),strategy:this.getStrategy(),manualCheck:this.requiresManualCheck(),tests:this.getTests()}}}},529:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,e.default=class{constructor(t,e=!1,s){this.match=t,this.required=e,this.points=s,this.pattern=new RegExp(`^${t}$`)}matches(t){return this.pattern.test(t)}getPoints(){return this.points}isRequired(){return this.required}}},715:(t,e)=>{var s;Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,function(t){t.Add="add",t.Deduct="deduct"}(s||(s={}));var r=s;e.default=r},104:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,e.default=class{constructor(t,e,s,r){var n;(n="manualCheck")in this?Object.defineProperty(this,n,{value:false,enumerable:!0,configurable:!0,writable:!0}):this[n]=false,this.name=t,this.maxPoints=e,this.successful=s,this.required=r}getName(){return this.name}getPoints(){return this.successful?this.maxPoints:0}getMaxPoints(){return this.maxPoints}isSuccessful(){return this.successful}isRequired(){return this.required}setManualCheck(t){this.manualCheck=t}requiresManualCheck(){return this.manualCheck}toJSON(){return{name:this.getName(),points:this.getPoints(),maxPoints:this.getMaxPoints(),successful:this.isSuccessful(),required:this.isRequired(),manualCheck:this.requiresManualCheck()}}}},540:(t,e)=>{function s(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,e.default=class{constructor(){s(this,"groups",[]),s(this,"extraTestRecorded",!1),s(this,"ungroupedTests",[])}addGroup(t){this.groups.push(t)}recordTest(t,e,s,r){s&&(this.extraTestRecorded=!0);const n=this.groups.find((n=>!!n.matches(t)&&(n.addTest(e,s,r),!0)));return n||this.ungroupedTests.push(t),n||!1}getWarnings(){const t=[],e=this.getGroups().filter((t=>!t.hasTests()));this.extraTestRecorded&&e.length>0&&t.push(`The following groups do not have any test:\n${e.map((t=>` - ${t.getDisplayName()}`)).join("\n")}`);const s=this.getGroups().map((t=>t.getMissingExtraTests().map((e=>` - ${t.getDisplayName()} > ${e.getName()}`)))).filter((t=>t.length>0));this.extraTestRecorded&&s.length>0&&t.push(`The following tests do NOT have extra tests and so can NOT be checked for possible cheating:\n${s.map((t=>t.join("\n"))).join("\n")}`);const r=this.getGroups().map((t=>t.getMissingNormalTests().map((e=>` - ${t.getDisplayName()} > ${e}`)))).filter((t=>t.length>0));return r.length>0&&t.push(`The following extra tests do not belong to a main test and were ignored:\n${r.map((t=>t.join("\n"))).join("\n")}`),this.ungroupedTests.length>0&&t.push(`The following tests do not belong to a group and were ignored:\n${this.ungroupedTests.map((t=>` - ${t}`)).join("\n")}`),t}getGroups(){return this.groups}hasExtraTest(){return this.extraTestRecorded}getUngroupedTests(){return this.ungroupedTests}toJSON(){const t=this.getWarnings();return{testResults:this.getGroups().filter((t=>t.getTests().length>0)),warnings:t.length>0?t:void 0}}}},359:(t,e,s)=>{Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"Group",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"Override",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(e,"Strategy",{enumerable:!0,get:function(){return i.default}}),Object.defineProperty(e,"Test",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(e,"TestRun",{enumerable:!0,get:function(){return o.default}});var r=c(s(210)),n=c(s(529)),i=c(s(715)),a=c(s(104)),o=c(s(540));function c(t){return t&&t.__esModule?t:{default:t}}}},e={};function s(r){if(e[r])return e[r].exports;var n=e[r]={exports:{}};return t[r](n,n.exports,s),n.exports}(()=>{function t(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}const e=(e,s,r)=>class{constructor(s,n){this.runner=s,t(this,"playIcon","&#x2023;"),t(this,"escape",window.mocha.Mocha.utils.escape),t(this,"constants",window.mocha.Mocha.Runner.constants),t(this,"report",void 0),t(this,"htmlReporter",void 0),t(this,"htmlRunner",void 0),t(this,"htmlEvents",{}),t(this,"testRun",void 0),t(this,"stats",{}),t(this,"warnings",r),window.mocha.Mocha.reporters.Base.call(this,s,n),this.htmlRunner={on:(t,e)=>{this.htmlEvents[t]=e},stats:this.stats},this.htmlReporter=new window.mocha.Mocha.reporters.HTML(this.htmlRunner,n),this.report=document.getElementById("mocha-report"),window.before((()=>{this.testRun=e.createTestRun()})),window.after((()=>{})),s.on(this.constants.EVENT_TEST_PASS,this.onTestFinished.bind(this)),s.on(this.constants.EVENT_TEST_FAIL,this.onTestFinished.bind(this)),s.on(this.constants.EVENT_SUITE_END,this.onSuiteEnd.bind(this))}onTestFinished(t){const e=this.recordTest(t);if(!e)return;const s=this.getGroupElement(e);this.updateGroup(e,s,t),this.updateStats()}onSuiteEnd(t){t.root&&(this.updateStats(),this.displayWarnings(),e.isLocalHistoryEnabled()&&this.storeLocalHistory())}recordTest(t){const e=t.titlePath();try{return this.testRun?.recordTest(e.filter((t=>"extra"!==t&&"Extra"!==t)).join(" > "),t.title,e.includes("extra")||e.includes("Extra"),t.isPassed())}catch(t){return!1}}createFilterUrl(t,e){let{search:s}=window.location;return s&&(s=s.replace(/[?&]grep=[^&\s]*/g,"").replace(/^&/,"?")),`${window.location.pathname+(s?`${s}&`:"?")}grep=${encodeURIComponent(t)}&filter=${e}`}getGroupElement(t){const e=this.testRun?.getGroups().indexOf(t);let s=this.report?.querySelector(`.suite[data-group-id="${e}"]`);if(!s){const r=this.createFragment('<li class="suite" data-group-id="%s"><h1><a href="%s">%e</a><span class="points"></span></h1><ul></ul></li>',e,this.createFilterUrl(`^${t.getPattern()}`,"group"),t.getDisplayName());this.report?.appendChild(r),s=this.report?.querySelector(`.suite[data-group-id="${e}"]`)}return t.requiresManualCheck()&&!s.querySelector(".manual-check-warning")&&s.querySelector("h1")?.appendChild(this.createFragment('<span class="manual-check-warning">manual check required</span>')),s}createTestElement(t,e,s,r){let n;return e.isSuccessful()?(n=this.createFragment(`<li class="test pass %e" data-test-id="%s"><h2>%e<span class="duration">%ems</span><a href="%s" class="replay">${this.playIcon}</a></h2></li>`,s.speed,t,e.getName(),s.duration,this.createFilterUrl(`^${s.fullTitle()}$`,"single")),r.querySelector("ul")?.appendChild(n)):(n=this.createFragment(`<li class="test fail" data-test-id="%s"><h2>%e<a href="%s" class="replay">${this.playIcon}</a></h2></li>`,t,e.getName(),this.createFilterUrl(`^${s.fullTitle()}$`,"single")),r.querySelector("ul")?.appendChild(n),this.addTestError(n,s)),this.htmlReporter.addCodeToggle(n,s.body),n}updateGroup(t,e,s){t.getTests().forEach(((r,n)=>{let i=e.querySelector(`.test[data-test-id="${n}"]`);const a=e.querySelector("h1 .points");if(i||(i=this.createTestElement(n,r,s,e)),r.requiresManualCheck()&&!i.classList.contains("manual-check")){i.classList.add("manual-check");const t=i.querySelector("h2 a");t?.parentNode?.insertBefore(this.createFragment('<span class="manual-check-warning">please check manually for static return values and/or logical errors</span>'),t)}if(!window.location.search.includes("&filter=single")){const e=`<span class="scored">${t.getPoints()}</span> / <span class="total">${t.getMaxPoints()}</span> point${1!==t.getMaxPoints()?"s":""}`;let s="";s=t.getPoints()>=t.getMaxPoints()?"all-points":t.getPoints()>0?"partial-points":"no-points",a&&(a.innerHTML=e,a.className=`points ${s}`)}}))}addTestError(t,e){let s;const r=e.err.toString();if(e.err.stack){const t=e.err.stack.indexOf(e.err.message);s=-1===t?e.err.stack:e.err.stack.substr(e.err.message.length+t)}else e.err.sourceURL&&void 0!==e.err.line&&(s=`\n(${e.err.sourceURL}:${e.err.line})`);s=s||"",e.err.htmlMessage&&s?t.appendChild(this.createFragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',e.err.htmlMessage,s)):e.err.htmlMessage?t.appendChild(this.createFragment('<div class="html-error">%s</div>',e.err.htmlMessage)):t.appendChild(this.createFragment('<pre class="error">%e%e</pre>',r,s))}createFragment(t,...e){const s=document.createElement("div");let r=0;return s.innerHTML=t.replace(/%([se])/g,((t,s)=>{switch(s){case"s":return String(e[r++]);case"e":return this.escape(e[r++]);default:return""}})),s.firstChild}updateStats(){this.htmlRunner.total=this.runner.total,this.htmlEvents[this.constants.EVENT_SUITE_END].bind(this.htmlReporter)({root:!0}),document.querySelector("#mocha-stats .progress").dataset.progress=""+this.stats.tests/this.runner.total*100}displayWarnings(){const t=[...this.warnings,...this.testRun?.getWarnings()||[]];if(0===t?.length)return;this.report.prepend(this.createFragment('<li class="warnings"><h1>Warnings:</h1><ul></ul></li>'));const e=this.report.querySelector("li.warnings ul");t?.forEach((t=>{e?.appendChild(this.createFragment("<li><pre>%e</pre></li>",t))}))}storeLocalHistory(){this.testRun&&s.storeLocalHistory(this.testRun)}};var r=s(556);class n{constructor(t){var e,s;this.url=t,s=void 0,(e="config")in this?Object.defineProperty(this,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):this[e]=s}async loadConfig(){try{const t=new AbortController,e=setTimeout((()=>t.abort()),2e3),s=await fetch(`${this.url}/config.json`,{signal:t.signal});return clearTimeout(e),s.status>=200&&s.status<300?(this.config=await s.json(),!0):(s.status>=400&&s.status<500&&console.warn(`Task config API returned ${s.status}. The configured API '${this.url}' is maybe wrong.`),!1)}catch(t){return!1}}async storeLocalHistory(t){try{const e=await fetch(`${this.url}/history`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return(await e.json()).created}catch(t){return console.error(t),!1}}getConfig(){if(!this.config)throw new Error("Configuration is not yet loaded");const t=new r.ZP;return t.load(this.config),t}}function i(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class a{constructor(t,e,s,r){this.mochaAssets=e,this.testFiles=s,this.mochaOptions=r,i(this,"taskApi",void 0),i(this,"warnings",[]),this.taskApi=new n(t)}async injectMocha(){const t=document.createElement("div");t.id="mocha",document.body.prepend(t);const e=document.createElement("style");e.innerHTML="\n.points,\n.manual-check-warning {\n display: inline-block;\n margin-left: 14px;\n padding: 0 7px;\n border-radius: 2px;\n background: #f6ffed;\n border: 1px solid #b7eb8f;\n color: #389e0d;\n font-size: 12px;\n font-weight: 500;\n line-height: 15px;\n transform: translateY(-3px);\n}\n\n.points:empty {\n display: none;\n}\n\n.partial-points,\n.manual-check-warning {\n background: #fffbe6;\n border-color: #ffe58f;\n color: #d48806;\n}\n\n.no-points {\n background: #fff1f0;\n border-color: #ffa39e;\n color: #cf1322;\n}\n\n.manual-check-warning {\n font-weight: 700;\n}\n\n.test .manual-check-warning {\n transform: none;\n}\n\n#mocha .test.pass.manual-check::before {\n content: '?';\n color: #d48806;\n}\n\n#mocha li.warnings {\n padding: 15px;\n background: #fffbe6;\n border: 1px solid #ffe58f;\n color: #d48806;\n}\n\n#mocha li.warnings h1 {\n margin: 0;\n font-weight: 700;\n}\n\n#mocha li.warnings pre {\n margin-bottom: 0;\n white-space: pre-wrap;\n font-size: 16px;\n}\n\n.loader {\n position: absolute;\n top: 50%;\n left: 50%;\n width: 0.9em;\n height: 1.5em;\n margin: 0 1.6em;\n display: inline-block;\n transform: translate(-50%, -50%);\n animation: throbber-loader 2000ms 300ms infinite ease-out;\n background: #dde2e7;\n}\n\n.loader:before,\n.loader:after {\n content: '';\n position: absolute;\n width: 0.9em;\n height: 1.5em;\n top: 0;\n display: inline-block;\n background: #dde2e7;\n}\n\n.loader:before {\n left: -1.6em;\n animation: throbber-loader 2000ms 150ms infinite ease-out;\n}\n\n.loader:after {\n right: -1.6em;\n animation: throbber-loader 2000ms 450ms infinite ease-out;\n}\n\n@keyframes throbber-loader {\n 0% {\n background: #dde2e7;\n }\n 10% {\n background: #6b9dc8;\n }\n 40% {\n background: #dde2e7;\n }\n}\n",document.head.appendChild(e),this.mochaAssets.filter((t=>t.endsWith(".css"))).forEach((t=>{const e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("href",t),document.head.appendChild(e)}));const s=this.mochaAssets.filter((t=>t.endsWith(".js"))).map((t=>new Promise(((e,s)=>{const r=setTimeout((()=>s(new Error(`${t} did not load within 3 seconds`))),3e3),n=document.createElement("script");n.addEventListener("load",(()=>{clearTimeout(r),e()})),n.addEventListener("error",(t=>{clearTimeout(r),s(t)})),n.setAttribute("src",t),document.body.appendChild(n)}))));await Promise.all(s)}async injectTestFiles(){for(const t of this.testFiles)await new Promise(((e,s)=>{const r=setTimeout((()=>{console.error(`${t} did not load within 3 seconds`),this.warnings.push(`${t} did not load within 3 seconds`),e()}),3e3),n=document.createElement("script");n.addEventListener("load",(()=>{clearTimeout(r),e()})),n.addEventListener("error",(()=>{clearTimeout(r),console.error(`${t} failed to load`),this.warnings.push(`${t} failed to load`),e()})),n.setAttribute("src",t),document.body.appendChild(n)}))}configureExpect(){this.mochaAssets.find((t=>t.indexOf("chai")>=0))&&(window.expect=window.chai.expect)}async setup(){const t=document.createElement("div");t.classList.add("loader"),document.body.appendChild(t),await this.injectMocha(),this.configureExpect();const s={ui:"bdd",...this.mochaOptions};await this.taskApi.loadConfig()&&(s.reporter=e(this.taskApi.getConfig(),this.taskApi,this.warnings)),window.mocha.setup(s),await this.injectTestFiles(),t.remove(),window.mocha.checkLeaks(),window.mocha.run()}}window.skills17={setupMocha:({api:t="http://localhost:4500/js",mochaAssets:e=["node_modules/mocha/mocha.css","node_modules/chai/chai.js","node_modules/mocha/mocha.js"],files:s=[],...r})=>{(async()=>{const n=new a(t,e,s,r);await n.setup()})()}}})()})();
(()=>{"use strict";var t={695:(t,e,s)=>{function n(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var r=s(359);e.default=class{constructor(){n(this,"source",["./src/**"]),n(this,"tests",["./tests/**/*.spec.*","./tests/**/*.test.*"]),n(this,"localHistory",!1),n(this,"displayPoints",!0),n(this,"serve",{enabled:!1,port:3e3,bind:"127.0.0.1",mapping:{"/":"./src"}}),n(this,"points",{defaultPoints:1,strategy:r.Strategy.Add}),n(this,"groups",[]),n(this,"metadata",{})}loadGroups(t){return t.map(((t,e)=>{if(!t.match)throw new Error(`config.yaml validation error: group #${e} does not contain a 'match' property`);const s=void 0!==t.defaultPoints?t.defaultPoints:this.points.defaultPoints,n=void 0!==t.strategy?t.strategy:this.points.strategy;if(void 0!==t.maxPoints&&n!==r.Strategy.Deduct)throw new Error(`config.yaml validation error: property 'maxPoints' can only be set for strategy 'deduct'. Found in group #${e} (${t.match})`);const i=new r.Group(t.match,s,n,t.displayName,t.maxPoints);return t.tests&&Array.isArray(t.tests)&&t.tests.forEach(((s,n)=>{if(!s.match)throw new Error(`config.yaml validation error: test #${n} in group #${e} (${t.match}) does not contain a 'match' property`);i.addOverride(new r.Override(s.match,s.required,s.points))})),i}))}load(t){this.id=t.id,this.source=t.source??this.source,this.tests=t.tests??this.tests,this.localHistory=t.localHistory??this.localHistory,this.displayPoints=t.displayPoints??this.displayPoints,this.serve={...this.serve,...t.serve},this.points={...this.points,...t.points},this.groups=t.groups??this.groups,this.metadata=t.metadata??this.metadata}createTestRun(){const t=new r.TestRun;return this.loadGroups(this.groups).forEach((e=>t.addGroup(e))),t}getId(){return this.id}getSource(){return this.source}getTests(){return this.tests}getServe(){return this.serve}getPoints(){return this.points}getGroups(){return this.groups}getMetadata(){return this.metadata}isLocalHistoryEnabled(){return this.localHistory}arePointsDisplayed(){return this.displayPoints}}},556:(t,e,s)=>{Object.defineProperty(e,"ZP",{enumerable:!0,get:function(){return n.default}});var n=r(s(695));r(s(806)),r(s(871)),r(s(872)),r(s(680));function r(t){return t&&t.__esModule?t:{default:t}}},806:()=>{},871:()=>{},872:()=>{},680:()=>{},210:(t,e,s)=>{function n(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var r=a(s(715)),i=a(s(104));function a(t){return t&&t.__esModule?t:{default:t}}e.default=class{constructor(t,e,s,r,i){n(this,"extraTests",{}),n(this,"tests",{}),n(this,"overrides",[]),this.match=t,this.defaultPoints=e,this.strategy=s,this.displayName=r,this.maxPoints=i,this.pattern=new RegExp(`^${t}$`)}addNormalTest(t,e){if(this.tests[t])throw new Error(`A test with the same name already exists in the same group. Test name: ${t}`);const s=this.getOverrideForTest(t);this.tests[t]=new i.default(t,s?.getPoints()||this.defaultPoints,e,s?.isRequired()||!1),void 0!==this.extraTests[t]&&e&&!this.extraTests[t]&&this.tests[t].setManualCheck(!0)}addExtraTest(t,e){if(this.extraTests[t])throw new Error(`An extra test with the same name already exists in the same group. Test name: ${t}`);this.extraTests[t]=e,this.tests[t]&&this.tests[t].isSuccessful()&&!e&&this.tests[t].setManualCheck(!0)}getOverrideForTest(t){return this.overrides.find((e=>e.matches(t)))}roundPoints(t){return+t.toFixed(2)}matches(t){return this.pattern.test(t)}addTest(t,e,s){e?this.addExtraTest(t,s):this.addNormalTest(t,s)}addOverride(t){this.overrides.push(t)}getPoints(){let t=!1;const e=this.getTests().reduce(((e,s)=>(s.isRequired()&&!s.isSuccessful()&&(t=!0),this.strategy===r.default.Add?e+s.getPoints():s.isSuccessful()?e:e-s.getMaxPoints())),this.strategy===r.default.Deduct?this.getMaxPoints():0);return t?0:this.roundPoints(Math.max(e,0))}getMaxPoints(){return this.strategy===r.default.Deduct&&void 0!==this.maxPoints?this.maxPoints:this.roundPoints(this.getTests().reduce(((t,e)=>t+e.getMaxPoints()),0))}getMissingExtraTests(){return Object.keys(this.tests).filter((t=>void 0===this.extraTests[t])).map((t=>this.tests[t]))}getMissingNormalTests(){return Object.keys(this.extraTests).filter((t=>void 0===this.tests[t]))}hasTests(){return Object.keys(this.tests).length>0||Object.keys(this.extraTests).length>0}getDefaultPoints(){return this.defaultPoints}getStrategy(){return this.strategy}getDisplayName(){return this.displayName??this.match}getTests(){return Object.values(this.tests)}getPattern(){return this.match}requiresManualCheck(){return!!this.getTests().find((t=>t.requiresManualCheck()))}toJSON(){return{group:this.getDisplayName(),points:this.getPoints(),maxPoints:this.getMaxPoints(),strategy:this.getStrategy(),manualCheck:this.requiresManualCheck(),tests:this.getTests()}}}},529:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,e.default=class{constructor(t,e=!1,s){this.match=t,this.required=e,this.points=s,this.pattern=new RegExp(`^${t}$`)}matches(t){return this.pattern.test(t)}getPoints(){return this.points}isRequired(){return this.required}}},715:(t,e)=>{var s;Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,function(t){t.Add="add",t.Deduct="deduct"}(s||(s={}));var n=s;e.default=n},104:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,e.default=class{constructor(t,e,s,n){var r;(r="manualCheck")in this?Object.defineProperty(this,r,{value:false,enumerable:!0,configurable:!0,writable:!0}):this[r]=false,this.name=t,this.maxPoints=e,this.successful=s,this.required=n}getName(){return this.name}getPoints(){return this.successful?this.maxPoints:0}getMaxPoints(){return this.maxPoints}isSuccessful(){return this.successful}isRequired(){return this.required}setManualCheck(t){this.manualCheck=t}requiresManualCheck(){return this.manualCheck}toJSON(){return{name:this.getName(),points:this.getPoints(),maxPoints:this.getMaxPoints(),successful:this.isSuccessful(),required:this.isRequired(),manualCheck:this.requiresManualCheck()}}}},540:(t,e)=>{function s(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,e.default=class{constructor(){s(this,"groups",[]),s(this,"extraTestRecorded",!1),s(this,"ungroupedTests",[])}addGroup(t){this.groups.push(t)}recordTest(t,e,s,n){s&&(this.extraTestRecorded=!0);const r=this.groups.find((r=>!!r.matches(t)&&(r.addTest(e,s,n),!0)));return r||this.ungroupedTests.push(t),r||!1}getWarnings(){const t=[],e=this.getGroups().filter((t=>!t.hasTests()));this.extraTestRecorded&&e.length>0&&t.push(`The following groups do not have any test:\n${e.map((t=>` - ${t.getDisplayName()}`)).join("\n")}`);const s=this.getGroups().map((t=>t.getMissingExtraTests().map((e=>` - ${t.getDisplayName()} > ${e.getName()}`)))).filter((t=>t.length>0));this.extraTestRecorded&&s.length>0&&t.push(`The following tests do NOT have extra tests and so can NOT be checked for possible cheating:\n${s.map((t=>t.join("\n"))).join("\n")}`);const n=this.getGroups().map((t=>t.getMissingNormalTests().map((e=>` - ${t.getDisplayName()} > ${e}`)))).filter((t=>t.length>0));return n.length>0&&t.push(`The following extra tests do not belong to a main test and were ignored:\n${n.map((t=>t.join("\n"))).join("\n")}`),this.ungroupedTests.length>0&&t.push(`The following tests do not belong to a group and were ignored:\n${this.ungroupedTests.map((t=>` - ${t}`)).join("\n")}`),t}getGroups(){return this.groups}hasExtraTest(){return this.extraTestRecorded}getUngroupedTests(){return this.ungroupedTests}toJSON(){const t=this.getWarnings();return{testResults:this.getGroups().filter((t=>t.getTests().length>0)),warnings:t.length>0?t:void 0}}}},359:(t,e,s)=>{Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"Group",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(e,"Override",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"Strategy",{enumerable:!0,get:function(){return i.default}}),Object.defineProperty(e,"Test",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(e,"TestRun",{enumerable:!0,get:function(){return o.default}});var n=h(s(210)),r=h(s(529)),i=h(s(715)),a=h(s(104)),o=h(s(540));function h(t){return t&&t.__esModule?t:{default:t}}}},e={};function s(n){var r=e[n];if(void 0!==r)return r.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,s),i.exports}(()=>{function t(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}const e=(e,s,n)=>class{constructor(s,r){this.runner=s,t(this,"playIcon","&#x2023;"),t(this,"escape",window.mocha.Mocha.utils.escape),t(this,"constants",window.mocha.Mocha.Runner.constants),t(this,"report",void 0),t(this,"htmlReporter",void 0),t(this,"htmlRunner",void 0),t(this,"htmlEvents",{}),t(this,"testRun",void 0),t(this,"stats",{}),t(this,"warnings",n),window.mocha.Mocha.reporters.Base.call(this,s,r),this.htmlRunner={on:(t,e)=>{this.htmlEvents[t]=e},stats:this.stats},this.htmlReporter=new window.mocha.Mocha.reporters.HTML(this.htmlRunner,r),this.report=document.getElementById("mocha-report"),window.before((()=>{this.testRun=e.createTestRun()})),window.after((()=>{})),s.on(this.constants.EVENT_TEST_PASS,this.onTestFinished.bind(this)),s.on(this.constants.EVENT_TEST_FAIL,this.onTestFinished.bind(this)),s.on(this.constants.EVENT_SUITE_END,this.onSuiteEnd.bind(this))}onTestFinished(t){const e=this.recordTest(t);if(!e)return;const s=this.getGroupElement(e);this.updateGroup(e,s,t),this.updateStats()}onSuiteEnd(t){t.root&&(this.updateStats(),this.displayWarnings(),e.isLocalHistoryEnabled()&&this.storeLocalHistory())}recordTest(t){const e=t.titlePath();try{return this.testRun?.recordTest(e.filter((t=>"extra"!==t&&"Extra"!==t)).join(" > "),t.title,e.includes("extra")||e.includes("Extra"),t.isPassed())}catch(t){return!1}}createFilterUrl(t,e){let{search:s}=window.location;return s&&(s=s.replace(/[?&]grep=[^&\s]*/g,"").replace(/^&/,"?")),`${window.location.pathname+(s?`${s}&`:"?")}grep=${encodeURIComponent(t)}&filter=${e}`}getGroupElement(t){const e=this.testRun?.getGroups().indexOf(t);let s=this.report?.querySelector(`.suite[data-group-id="${e}"]`);if(!s){const n=this.createFragment('<li class="suite" data-group-id="%s"><h1><a href="%s">%e</a><span class="points"></span></h1><ul></ul></li>',e,this.createFilterUrl(`^${t.getPattern()}`,"group"),t.getDisplayName());this.report?.appendChild(n),s=this.report?.querySelector(`.suite[data-group-id="${e}"]`)}return t.requiresManualCheck()&&!s.querySelector(".manual-check-warning")&&s.querySelector("h1")?.appendChild(this.createFragment('<span class="manual-check-warning">manual check required</span>')),s}createTestElement(t,e,s,n){let r;return e.isSuccessful()?(r=this.createFragment(`<li class="test pass %e" data-test-id="%s"><h2>%e<span class="duration">%ems</span><a href="%s" class="replay">${this.playIcon}</a></h2></li>`,s.speed,t,e.getName(),s.duration,this.createFilterUrl(`^${s.fullTitle()}$`,"single")),n.querySelector("ul")?.appendChild(r)):(r=this.createFragment(`<li class="test fail" data-test-id="%s"><h2>%e<a href="%s" class="replay">${this.playIcon}</a></h2></li>`,t,e.getName(),this.createFilterUrl(`^${s.fullTitle()}$`,"single")),n.querySelector("ul")?.appendChild(r),this.addTestError(r,s)),this.htmlReporter.addCodeToggle(r,s.body),r}updateGroup(t,e,s){t.getTests().forEach(((n,r)=>{let i=e.querySelector(`.test[data-test-id="${r}"]`);const a=e.querySelector("h1 .points");if(i||(i=this.createTestElement(r,n,s,e)),n.requiresManualCheck()&&!i.classList.contains("manual-check")){i.classList.add("manual-check");const t=i.querySelector("h2 a");t?.parentNode?.insertBefore(this.createFragment('<span class="manual-check-warning">please check manually for static return values and/or logical errors</span>'),t)}if(!window.location.search.includes("&filter=single")){const e=`<span class="scored">${t.getPoints()}</span> / <span class="total">${t.getMaxPoints()}</span> point${1!==t.getMaxPoints()?"s":""}`;let s="";s=t.getPoints()>=t.getMaxPoints()?"all-points":t.getPoints()>0?"partial-points":"no-points",a&&(a.innerHTML=e,a.className=`points ${s}`)}}))}addTestError(t,e){let s;const n=e.err.toString();if(e.err.stack){const t=e.err.stack.indexOf(e.err.message);s=-1===t?e.err.stack:e.err.stack.substr(e.err.message.length+t)}else e.err.sourceURL&&void 0!==e.err.line&&(s=`\n(${e.err.sourceURL}:${e.err.line})`);s=s||"",e.err.htmlMessage&&s?t.appendChild(this.createFragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',e.err.htmlMessage,s)):e.err.htmlMessage?t.appendChild(this.createFragment('<div class="html-error">%s</div>',e.err.htmlMessage)):t.appendChild(this.createFragment('<pre class="error">%e%e</pre>',n,s))}createFragment(t,...e){const s=document.createElement("div");let n=0;return s.innerHTML=t.replace(/%([se])/g,((t,s)=>{switch(s){case"s":return String(e[n++]);case"e":return this.escape(e[n++]);default:return""}})),s.firstChild}updateStats(){this.htmlRunner.total=this.runner.total,this.htmlEvents[this.constants.EVENT_SUITE_END].bind(this.htmlReporter)({root:!0}),document.querySelector("#mocha-stats .progress").dataset.progress=""+this.stats.tests/this.runner.total*100}displayWarnings(){const t=[...this.warnings,...this.testRun?.getWarnings()||[]];if(0===t?.length)return;this.report.prepend(this.createFragment('<li class="warnings"><h1>Warnings:</h1><ul></ul></li>'));const e=this.report.querySelector("li.warnings ul");t?.forEach((t=>{e?.appendChild(this.createFragment("<li><pre>%e</pre></li>",t))}))}storeLocalHistory(){this.testRun&&s.storeLocalHistory(this.testRun)}};var n=s(556);class r{constructor(t){var e,s;this.url=t,s=void 0,(e="config")in this?Object.defineProperty(this,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):this[e]=s}async loadConfig(){try{const t=new AbortController,e=setTimeout((()=>t.abort()),2e3),s=await fetch(`${this.url}/config.json`,{signal:t.signal});return clearTimeout(e),s.status>=200&&s.status<300?(this.config=await s.json(),!0):(s.status>=400&&s.status<500&&console.warn(`Task config API returned ${s.status}. The configured API '${this.url}' is maybe wrong.`),!1)}catch(t){return!1}}async storeLocalHistory(t){try{const e=await fetch(`${this.url}/history`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return(await e.json()).created}catch(t){return console.error(t),!1}}getConfig(){if(!this.config)throw new Error("Configuration is not yet loaded");const t=new n.ZP;return t.load(this.config),t}}function i(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class a{constructor(t,e,s,n){this.mochaAssets=e,this.testFiles=s,this.mochaOptions=n,i(this,"taskApi",void 0),i(this,"warnings",[]),this.taskApi=new r(t)}async injectMocha(){const t=document.createElement("div");t.id="mocha",document.body.prepend(t);const e=document.createElement("style");e.innerHTML="\n.points,\n.manual-check-warning {\n display: inline-block;\n margin-left: 14px;\n padding: 0 7px;\n border-radius: 2px;\n background: #f6ffed;\n border: 1px solid #b7eb8f;\n color: #389e0d;\n font-size: 12px;\n font-weight: 500;\n line-height: 15px;\n transform: translateY(-3px);\n}\n\n.points:empty {\n display: none;\n}\n\n.partial-points,\n.manual-check-warning {\n background: #fffbe6;\n border-color: #ffe58f;\n color: #d48806;\n}\n\n.no-points {\n background: #fff1f0;\n border-color: #ffa39e;\n color: #cf1322;\n}\n\n.manual-check-warning {\n font-weight: 700;\n}\n\n.test .manual-check-warning {\n transform: none;\n}\n\n#mocha .test.pass.manual-check::before {\n content: '?';\n color: #d48806;\n}\n\n#mocha li.warnings {\n padding: 15px;\n background: #fffbe6;\n border: 1px solid #ffe58f;\n color: #d48806;\n}\n\n#mocha li.warnings h1 {\n margin: 0;\n font-weight: 700;\n}\n\n#mocha li.warnings pre {\n margin-bottom: 0;\n white-space: pre-wrap;\n font-size: 16px;\n}\n\n.loader {\n position: absolute;\n top: 50%;\n left: 50%;\n width: 0.9em;\n height: 1.5em;\n margin: 0 1.6em;\n display: inline-block;\n transform: translate(-50%, -50%);\n animation: throbber-loader 2000ms 300ms infinite ease-out;\n background: #dde2e7;\n}\n\n.loader:before,\n.loader:after {\n content: '';\n position: absolute;\n width: 0.9em;\n height: 1.5em;\n top: 0;\n display: inline-block;\n background: #dde2e7;\n}\n\n.loader:before {\n left: -1.6em;\n animation: throbber-loader 2000ms 150ms infinite ease-out;\n}\n\n.loader:after {\n right: -1.6em;\n animation: throbber-loader 2000ms 450ms infinite ease-out;\n}\n\n@keyframes throbber-loader {\n 0% {\n background: #dde2e7;\n }\n 10% {\n background: #6b9dc8;\n }\n 40% {\n background: #dde2e7;\n }\n}\n",document.head.appendChild(e),this.mochaAssets.filter((t=>t.endsWith(".css"))).forEach((t=>{const e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("href",t),document.head.appendChild(e)}));const s=this.mochaAssets.filter((t=>t.endsWith(".js"))).map((t=>new Promise(((e,s)=>{const n=setTimeout((()=>s(new Error(`${t} did not load within 3 seconds`))),3e3),r=document.createElement("script");r.addEventListener("load",(()=>{clearTimeout(n),e()})),r.addEventListener("error",(t=>{clearTimeout(n),s(t)})),r.setAttribute("src",t),document.body.appendChild(r)}))));await Promise.all(s)}async injectTestFiles(){for(const t of this.testFiles)await new Promise(((e,s)=>{const n=setTimeout((()=>{console.error(`${t} did not load within 3 seconds`),this.warnings.push(`${t} did not load within 3 seconds`),e()}),3e3),r=document.createElement("script");r.addEventListener("load",(()=>{clearTimeout(n),e()})),r.addEventListener("error",(()=>{clearTimeout(n),console.error(`${t} failed to load`),this.warnings.push(`${t} failed to load`),e()})),r.setAttribute("src",t),document.body.appendChild(r)}))}configureExpect(){this.mochaAssets.find((t=>t.indexOf("chai")>=0))&&(window.expect=window.chai.expect)}async setup(){const t=document.createElement("div");t.classList.add("loader"),document.body.appendChild(t),await this.injectMocha(),this.configureExpect();const s={ui:"bdd",...this.mochaOptions};await this.taskApi.loadConfig()&&(s.reporter=e(this.taskApi.getConfig(),this.taskApi,this.warnings)),window.mocha.setup(s),await this.injectTestFiles(),t.remove(),window.mocha.checkLeaks(),window.mocha.run()}}window.skills17={setupMocha:({api:t="http://localhost:4500/js",mochaAssets:e=["node_modules/mocha/mocha.css","node_modules/chai/chai.js","node_modules/mocha/mocha.js"],files:s=[],...n})=>{(async()=>{const r=new a(t,e,s,n);await r.setup()})()}}})()})();
{
"name": "@skills17/mocha-web-helpers",
"version": "1.0.0",
"version": "2.0.0",
"description": "Provides some mocha web helpers for usage in a skills competition environment.",

@@ -34,18 +34,18 @@ "main": "dist/main.js",

"@babel/preset-typescript": "^7.12.17",
"@skills17/static-task-server": "^2.0.0",
"@skills17/task-config": "^2.1.2",
"@skills17/task-config-api": "^1.0.1",
"@types/node": "^14.14.31",
"@skills17/static-task-server": "^3.0.0",
"@skills17/task-config": "^3.0.1",
"@skills17/task-config-api": "^2.0.0",
"@types/node": "^16.11.11",
"@types/rimraf": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"babel-loader": "^8.2.2",
"chai": "^4.3.0",
"cypress": "^6.5.0",
"eslint": "^7.20.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^7.2.0",
"cypress": "^9.1.0",
"eslint": "^8.3.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"mocha": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"mocha": "^8.4.0",
"prettier": "^2.2.1",

@@ -58,4 +58,4 @@ "rimraf": "^3.0.2",

"peerDependencies": {
"mocha": "^8.0.0"
"mocha": "^8.4.0"
}
}

@@ -113,3 +113,3 @@ # skills17/mocha-web-helpers

In JS, tests are grouped by a test name prefix defined in the `config.json` file.
In JS, tests are grouped by a test name prefix defined in the `config.yaml` file.

@@ -116,0 +116,0 @@ All `describe`s are concatenated with the actual test names before evaluation.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc