This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
learnBrowser.min.js
1 lines (1 loc) · 2.29 KB
/
learnBrowser.min.js
1
window.onload=function(){const a=document.getElementById('mocha');if(null===a)throw new Error('Check that a div#mocha element exists in the <body> in index.html.');if(mocha===a)throw new Error('Check that Mocha is added via a <script> tag in index.html.');if(void 0===window.describe)throw new Error('Check that Mocha is set up for BDD-style testing in index.html.');if(void 0===window.chai)throw new Error('Please use Chai as the matchers library for testing Learn.co JavaScript lessons.');const g=(t,u)=>{for(const v of t.suites)u=g(v,u);return u+=t.tests.length},h=g(mocha.suite,0),i={build:{test_suite:[{framework:'mocha',formatted_output:{tests:[],pending:[],failures:[],passes:[]}}]}},{formatted_output:j}=i.build.test_suite[0],k=()=>{const t=mocha.run().on('test end',u=>m(q(u))).on('end',()=>l(t))},l=t=>{if(___browserSync___===void 0)console.warn('In order to push test data to Learn\'s servers, you must start the test suite from your terminal with the \'learn\' or \'npm test\' command.');else if(0===t.total)console.warn('Make sure the LearnBrowser JS file is loaded *after* the test suite in index.html.');else if(t.total!==h)console.warn(`${t.total} out of ${h} tests ran.`);else{n(t);const u=o(i,___browserSync___.socketConfig);p(u)}},m=t=>{switch(j.tests.push(t),!0){case'failed'===t.state:j.failures.push(t);break;case'passed'===t.state:j.passes.push(t);break;case t.pending:j.pending.push(t);}},n=({stats:t})=>{i.examples=h,i.passing_count=t.passes,i.failure_count=t.failures,i.pending_count=t.pending,j.stats=t,i.build.test_suite[0].duration=t},o=(t,{username:u,github_user_id:v,learn_oauth_token:w,repo_name:x,ruby_platform:y,ide_container:z,learning_environment:A})=>Object.assign({},t,{username:u,github_user_id:v,learn_oauth_token:w,repo_name:x,ruby_platform:y,ide_container:z,learning_environment:A}),p=t=>fetch('http://ironbroker-v2.flatironschool.com/e/flatiron_mocha',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(t),mode:'no-cors'}).catch(()=>console.warn('Unable to contact Learn servers. Please check your Internet connection and try again.')),q=({title:t,parent:u,duration:v,_currentRetry:w,err:x})=>({title:t,fullTitle:r(t,u),duration:v,currentRetry:w,err:x}),r=(t,u)=>{for(;u&&'Suite'===u.constructor.name;)t=u.title.concat(' ',t),u=u.parent;return t.trim()};return()=>k()}();