-
Notifications
You must be signed in to change notification settings - Fork 5
/
examplejs.min.js
1 lines (1 loc) · 2.48 KB
/
examplejs.min.js
1
!function(n){function e(n,e){return n.replace(/#\{(.*?)\}/g,function(n,t){return e&&t in e?e[t]:""})}function t(n,t){if(!n)return n;t=t||{};var i,s="";if(String(n).replace(/\s*\*?\s*@example\s*(.*)\n\s*((```(?:javascript|js|html|css)\s*\n([^]*?)\s*```[\s]*)+)/gi,function(n,r,o){var a={js:[],css:[],html:[]};r=r||"none",o.replace(/```(javascript|js|html|css)\s*\n([^]*?)\s*```/g,function(n,e,t){e=e.toLowerCase(),"javascript"===e&&(e="js"),t.trim()&&a[e].push(t)}),a.css.length>0&&a.html.unshift("<style>"+a.css.join("\n")+"</style>"),a.html.length>0&&(i=!0,s+=e('\n it(#{it}, function (done) {\n jsdom.env(#{html}, {\n features: {\n FetchExternalResources : ["script", "link"],\n ProcessExternalResources: ["script"]\n }\n },\n function (err, window) {\n global.window = window;\n #{global}.forEach(\n function (key) {\n global[key] = window[key];\n }\n );\n assert.equal(err, null);\n done();\n }\n );\n });\n ',{html:JSON.stringify(a.html.join("\n")),it:JSON.stringify("jsdom@"+r),global:JSON.stringify((t.globals||"document,navigator").split(",").map(function(n){return n.trim()}))}));var l=a.js.join("\n"),u=l.indexOf("// * done")>=0,c=l.indexOf("// * throw")>=0;if(l=l.replace(/^(\s*\/\/ > .*\n??)+/gm,function(n){var e=n.match(/^(\s*)\/\/ > /)[1],t=n.replace(/^\s*\/\/ > /gm,"");return e+'assert.equal(examplejs_printLines.join("\\n"), '+JSON.stringify(t)+"); examplejs_printLines = [];"}).replace(/console\.log/g,"examplejs_print"),u&&(l=l.replace("// * done","done();")),c){var d=l.match(/^(\s*)/)[1];l="\n"+d+"(function() {\n"+l+"\n"+d+"}).should.throw();"}s+=e("\n it(#{it}, function (#{done}) {\n examplejs_printLines = [];\n#{code}\n });\n ",{code:l,done:u?"done":"",it:JSON.stringify(r)})}),!s)return"";var r=[];return t.header&&r.push(t.header),r.push(e("\ndescribe(#{desc}, function () {\n var assert = require('should');\n var util = require('util');\n var examplejs_printLines;\n function examplejs_print() {\n examplejs_printLines.push(util.format.apply(util, arguments));\n }\n #{jsdom}\n #{timeout}\n#{exampleCode}\n});\n ",{desc:JSON.stringify(t.desc||"none"),jsdom:i?"var jsdom = require('jsdom');":"",timeout:t.timeout?"this.timeout("+t.timeout+");":"",exampleCode:s})),r.join("\n")}var i=i||{};i.build=t,"function"==typeof define?define.amd&&define(function(){return i}):"undefined"!=typeof module&&module.exports?module.exports=i:window[n]=i}("examplejs");