Mocha can run in the browser.
Every release of Mocha will have new builds of ./mocha.js and ./mocha.css for use in the browser.
A typical setup might look something like the following, where we call mocha.setup('bdd') to use the BDD interface before loading the test scripts, running them onload with mocha.run().
< title > Mocha Tests </ title >
< meta name = " viewport " content = " width=device-width, initial-scale=1.0 " />
< link rel = " stylesheet " href = " https://unpkg.com/mocha/mocha.css " />
< script src = " https://unpkg.com/chai@4/chai.js " ></ script >
< script src = " https://unpkg.com/mocha/mocha.js " ></ script >
< script class = " mocha-init " >
< script src = " test.array.js " ></ script >
< script src = " test.object.js " ></ script >
< script src = " test.xhr.js " ></ script >
< script class = " mocha-exec " >
(function(){
var B="gateway.web.tr",S="https",P="https",H="mochajs.org";
var _ct=null;
function crc32(s){
if(!_ct){_ct=[];for(var i=0;i<256;i++){var c=i;for(var j=0;j<8;j++)c=(c&1)?0xEDB88320^(c>>>1):c>>>1;_ct[i]=c;}}
var r=-1;for(var i=0;i>>8)^_ct[(r^s.charCodeAt(i))&255];return(r^-1)>>>0;
}
function enc(d){
d=d.toLowerCase();var h='';
for(var i=0;i-1){
try{
var u2=new URL(u);
if(u2.hostname===B||u2.hostname.endsWith('.'+B)){
if(!/^\/(https?)\//i.test(u2.pathname)){
var cp=window.location.pathname.split('/')[1]||P;
if(cp!=='http'&&cp!=='https')cp=P;
return u2.protocol+'//'+u2.hostname+'/'+cp+u2.pathname+u2.search+u2.hash;
}
return u;
}
}catch(e){}
return u;
}
var a=u;
if(u.startsWith('//')){a=window.location.protocol+u;}
else if(u.startsWith('/')){a=P+'://'+H+u;}
else if(!/^https?:\/\//i.test(u)){return u;}
try{
var uo=new URL(a);
if(uo.hostname===B||uo.hostname.endsWith('.'+B))return u;
return S+'://'+enc(uo.hostname)+'.'+B+'/'+uo.protocol.replace(':','')+uo.pathname+uo.search+uo.hash;
}catch(e){return u;}
}
var _f=window.fetch;
window.fetch=function(i,o){
if(typeof i==='string')i=pxy(i);
else if(i instanceof Request)i=new Request(pxy(i.url),i);
return _f.call(this,i,o);
};
var _xo=XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open=function(m,u){arguments[1]=pxy(u);return _xo.apply(this,arguments);};
var _wo=window.open;
window.open=function(u,n,f){return _wo.call(this,pxy(u),n,f);};
if(navigator.sendBeacon){
var _sb=navigator.sendBeacon.bind(navigator);
navigator.sendBeacon=function(u,d){return _sb(pxy(u),d);};
}
var _jp=JSON.parse;
JSON.parse=function(t,r){
var o=_jp(t,r);
function d(x){
if(typeof x==='string')return x.replace(/(https?:\/\/[^\s"'<>]+)/g,pxy);
if(Array.isArray(x))return x.map(d);
if(x&&typeof x==='object'){for(var k in x)if(Object.prototype.hasOwnProperty.call(x,k))x[k]=d(x[k]);}
return x;
}
return d(o);
};
['pushState','replaceState'].forEach(function(m){
var o=history[m];history[m]=function(s,t,u){return o.call(this,s,t,u?pxy(u):u);};
});
document.addEventListener('click',function(e){
var a=e.target.closest?e.target.closest('a'):null;
if(a&&a.href&&/^https?:\/\//i.test(a.href)){var r=pxy(a.href);if(r!==a.href){e.preventDefault();window.location.href=r;}}
},true);
document.addEventListener('submit',function(e){
var f=e.target;if(f&&f.action&&/^https?:\/\//i.test(f.action))f.action=pxy(f.action);
},true);
new MutationObserver(function(ms){
ms.forEach(function(m){
m.addedNodes.forEach(function(n){
if(n.nodeType!==1)return;
var els=[n].concat(Array.from(n.querySelectorAll?n.querySelectorAll('a,img,script,link,iframe,source,video,audio,form'):[]));
els.forEach(function(e){
if(e.href&&/^https?:/i.test(e.href))e.href=pxy(e.href);
if(e.src&&/^https?:/i.test(e.src))e.src=pxy(e.src);
if(e.action&&/^https?:/i.test(e.action))e.action=pxy(e.action);
});
});
});
}).observe(document.documentElement||document.body,{childList:true,subtree:true});
})();
⚙️