How to use buildFile method in Jest

Best JavaScript code snippet using jest

ui.js

Source:ui.js Github

copy

Full Screen

12var UI = {34 //#region 公共56 // 当前页面。7 currentStep: 1,89 // 当前在编辑的打包方案文件。10 currentBuildFile: null,1112 // 是否使用 xfly 进行操作,而不是在客户端处理。13 usingXFly: true,1415 // 模块提示用的数据。16 _suggestData: null,1718 // 初始化全部逻辑。19 init: function () {2021 // 只显示第一个面板。22 Dom.query('.panel').hide();23 Dom.show(Dom.get('step' + UI.currentStep));24 UI.step(1);2526 ModuleBuilder.moduleBasePath = Demo.baseUrl + Demo.Configs.src;2728 },2930 // 切换到不同的页面。31 step: function (value) {3233 var me = this;3435 // 根据不同的步骤进行初始化。36 switch (value) {37 case 1:3839 // 如果使用 xfly, 先测试是否可以正常地连接到服务器。40 if (UI.usingXFly) {4142 // 等待服务器正常回调后,设置值为 true。43 UI.usingXFly = false;44 Ajax.jsonp(Demo.Configs.serverBaseUrl + Demo.Configs.apps + "/node/modulebuilder/server/api.njs?action=recentbuildfiles", function (data) {45 UI.usingXFly = true;46 me._showBuildFileListHtml('step1_buildfilelist', '已保存的打包方案', data);47 });48 }4950 break;5152 case 2:5354 // 显示打开历史。55 var data = window.localStorage && localStorage.moduleBuilderOpenList;5657 me._showBuildFileListHtml('step2_buildfilelist', '最近的打包方案', data && data.split(';'), true);5859 break;6061 case 3:62 UI._showBuildFile();6364 // 初始化 UI 界面。65 if (!UI._suggestData) {6667 var r = UI._suggestData = {};6869 for (var key in ModuleList.src) {7071 var type = ModuleList.src[key];7273 if (type === ".js") {74 key = key.substr(0, key.length - 3);75 } else if (type === ".css") {76 key = key.substr(0, key.length - 4);77 } else {78 continue;79 }8081 if (r[key]) {82 r[key] = ".js+.css";83 } else {84 r[key] = type;85 }86 }8788 var suggest = new Suggest(Dom.get('step3_module'));8990 suggest.getSuggestItems = function (text) {91 var r = [];9293 if (!text) {94 for (var key in UI._suggestData) {95 if (UI.currentBuildFile.includes.indexOf(key) < 0 && UI.currentBuildFile.excludes.indexOf(key)) {96 r.push(key);97 }98 }99 } else if (/\.$/.test(text)) {100 r.push(text.substr(0, text.length - 1), text + "js", text + "css");101 } else {102 for (var key in UI._suggestData) {103 if (UI.currentBuildFile.includes.indexOf(key) < 0 && UI.currentBuildFile.excludes.indexOf(key)) {104 if (key.indexOf(text) === 0) {105 r.push("<strong>" + text + "</strong>" + key.substr(text.length));106 } else if (key.indexOf("/" + text) >= 0) {107 r.push(key.replace("/" + text, "/<strong>" + text + "</strong>"));108 }109 }110 }111 }112113 return r;114 };115116117 Dom.keyNav(Dom.get('step3_module'), {118 enter: function () {119 if (suggest.isDropDownHidden()) {120 UI.addModule();121 }122 }123 });124125 }126127 break;128129 }130131 // 从左到右渐变。132 if (UI.currentStep < value) {133 Dom.show(Dom.get('step' + value));134 Dom.animate(Dom.get('container'), { marginLeft: '0--' + Dom.get('step' + UI.currentStep).offsetWidth }, -1, function () {135 Dom.get('container').style.marginLeft = 0;136 Dom.hide(Dom.get('step' + UI.currentStep));137 UI.currentStep = value;138 });139 } else if (UI.currentStep > value) {140 Dom.show(Dom.get('step' + value));141 Dom.animate(Dom.get('container'), { marginLeft: '-' + Dom.get('step' + UI.currentStep).offsetWidth + '-0' }, -1, function () {142 Dom.hide(Dom.get('step' + UI.currentStep));143 UI.currentStep = value;144 });145 }146 },147148 // 根据模块列表生成 HTML 模板。149 _showBuildFileListHtml: function (id, title, data, fromOpenList) {150151 id = Dom.get(id);152153 if (data && data.length) {154155 id.style.display = 'block';156157 var r = ['<div class="hint">' + title + ' ────────────────────────────────────────────</div>'];158159 for (var i = 0; i < data.length; i++) {160161 var path = data[i],162 name = path;163164 if (!fromOpenList) {165 path = Demo.baseUrl + path;166 name = Path.basename(name, ".js");167 }168169 path = path.replace(/\\/g, "/");170171172 r.push('<div class="line" onmouseover="this.className += \' line-hover\'" onmouseout="this.className = this.className.replace(\' line-hover\', \'\');"><nav class="demo demo-toolbar"><a href="javascript://打开此打包方案" onclick="UI.openBuildFile(\'' + path + '\',' + fromOpenList + ');return false;">打开</a> | <a class="demo-viewsource-toggle" href="javascript://删除此打包方案" onclick="UI.deleteBuildFile(\'' + path + '\',' + fromOpenList + '); return false;">删除</a> | <a href="javascript://复制此打包方案" onclick="UI.copyBuildFile(\'' + path + '\',' + fromOpenList + ');return false;">复制</a> | <a class="demo-viewsource-toggle" href="javascript://根据此打包方案重新生成" onclick="UI.buildBuildFile(\'' + path + '\',' + fromOpenList + '); return false;">生成</a></nav><a class="link" href="javascript://打开此打包方案" onclick="UI.openBuildFile(\'' + path + '\',' + fromOpenList + ');return false;">' + name + '</a></div>');173 }174175 id.innerHTML = r.join('');176 } else {177 id.style.display = 'none';178179 }180181 },182183 //#endregion184185 //#region 第一二步186187 // 创建新的打包方案。188 createNewBuildFile: function () {189190 // 如果之前已经新建过,则不再新建。191 if (UI.currentBuildFile && UI.currentBuildFile.isNew) {192 UI.step(3);193 return;194 }195196 // 创建新的打包方案。197 UI.currentBuildFile = new BuildFile();198 UI.currentBuildFile.isNew = true;199 UI.step(3);200 },201202 // 打开其他打包方案。203 openOtherBuildFile: function () {204 UI.step(2);205 },206207 // 打开指定的打包方案。208 openBuildFile: function (buildFilePath) {209 UI._loadBuildFile(buildFilePath, function (buildFile) {210 UI.currentBuildFile = buildFile;211 UI.step(3);212 });213 },214215 // 删除指定的打包方案。216 deleteBuildFile: function (buildFilePath, fromOpenList) {217218 if (fromOpenList) {219220221222 var data = window.localStorage && localStorage.moduleBuilderOpenList;223 if (data = data && data.split(';')) {224 var p = data.indexOf(buildFilePath);225 if (p >= 0) {226 data.splice(p, 1);227 }228229 localStorage.moduleBuilderOpenList = data.join(';');230 UI.step(2);231 }232 } else {233234 if (!confirm("确认删除打包方案文件 " + buildFilePath + " 吗?"))235 return;236237 UI._jsonpNode('deletebuildfile', {238 path: buildFilePath,239 }, function () {240 UI.step(1);241 });242 }243 },244245 _loadBuildFile: function (buildFilePath, callback) {246247 // 绝对路径,基于服务器打开。248 if (buildFilePath.indexOf(':') >= 0 && buildFilePath.indexOf(location.protocol + '//' + location.host + '/') !== 0) {249250 if (!UI.usingXFly) {251 UI._alertOpenXFlyError();252 } else {253 UI._jsonpNode('read', {254 path: buildFilePath255 }, function (content) {256257 var buildFile = new BuildFile();258 buildFile.load(content);259260 buildFile.path = buildFilePath;261 callback(buildFile);262263 });264 }265266 } else {267 ModuleBuilder.load(buildFilePath, callback);268 }269270 },271272 // 复制指定的打包方案。273 copyBuildFile: function (buildFilePath) {274 UI._loadBuildFile(buildFilePath, function (buildFile) {275 UI.currentBuildFile = buildFile;276277 buildFile.js = buildFile.css = buildFile.assets = buildFile.path = "";278279 UI.step(3);280 });281 },282283 // 编译指定的打包方案。284 buildBuildFile: function (buildFilePath) {285 UI._loadBuildFile(buildFilePath, function (buildFile) {286 UI.currentBuildFile = buildFile;287 UI._buildInternal();288 });289 },290291 _alertOpenXFlyError: function () {292 if (navigator.userAgent.indexOf("Windows") >= 0) {293 alert("错误: 需要先启动本地代理服务器才能读写本地文件。\r\n启动方法: 双击打开\"[库根目录]/apps/startserver.cmd\", 并不要关闭窗口。");294 } else {295 alert("错误: 需要先启动本地代理服务器才能读写本地文件。\r\n启动方法: 请先安装 nodejs, 然后启动\"[库根目录]/apps/startserver。\"");296 }297 },298299 _jsonpNode: function (action, data, callback) {300 Ajax.jsonp(Demo.Configs.serverBaseUrl + Demo.Configs.apps + "/node/modulebuilder/server/api.njs?action=" + action, data, callback, UI._alertOpenXFlyError);301 },302303 // 打开新输入的打包方案。304 openBuildFileOf: function () {305 UI._openOrBuildBuildFileOf(UI.openBuildFile);306 },307308 // 编译新输入的打包方案。309 buildBuildFileOf: function () {310 UI._openOrBuildBuildFileOf(UI.buildBuildFile);311 },312313 _openOrBuildBuildFileOf: function (callback) {314 UI._checkValue('step2_url', function (buildFilePath) {315316 if (/^\w+\//.test(buildFilePath)) {317 buildFilePath = "/" + buildFilePath;318 }319320 if (window.localStorage) {321 var data = (localStorage.moduleBuilderOpenList || "").split(';');322 if (data.indexOf(buildFilePath) < 0) {323 data.push(buildFilePath);324 localStorage.moduleBuilderOpenList = data.join(';');325 }326 }327328 callback(buildFilePath);329 });330 },331332 _checkValue: function (id, callback) {333 id = Dom.get(id);334 335 var value = id.value.trim();336337 if (value) {338 Dom.removeClass(id, 'x-textbox-error');339 callback(value);340 } else {341 Dom.addClass(Dom.get(id), 'x-textbox-error');342 }343 },344345 //#endregion346347 //#region 第三步348349 _showBuildFile: function () {350351 UI._showModuleList();352353 var buildFile = UI.currentBuildFile;354 buildFile.path = buildFile.path.replace(Demo.baseUrl, "");355356 Dom.get('step3_compress').checked = buildFile.compress;357 Dom.get('step3_addAssert').checked = buildFile.addAssert;358359 Dom.get('step3_buildfile').value = buildFile.path;360 Dom.get('step3_js').value = buildFile.js;361 Dom.get('step3_css').value = buildFile.css;362 Dom.get('step3_assets').value = buildFile.assets;363 Dom.get('step3_dependencySyntax').value = buildFile.dependencySyntax;364 Dom.get('step3_uniqueBuildFiles').value = buildFile.uniqueBuildFiles;365 Dom.get('step3_parseMacro').checked = buildFile.parseMacro;366 Dom.get('step3_defines').value = buildFile.defines;367 Dom.get('step3_prependComments').value = buildFile.prependComments;368 Dom.get('step3_prependModuleComments').value = buildFile.prependModuleComments;369370 },371372 _showModuleList: function () {373 var buildFile = UI.currentBuildFile;374 var html = '';375376 add("includes", "", "");377 add("excludes", "<del>", "</del>");378379 Dom.get('step3_modulelist').innerHTML = html;380 Dom.get('step_clearModules').style.display = html ? '' : 'none';381382 function add(includeOrExclude, prefix, postfix) {383384 for (var i = 0, all = buildFile[includeOrExclude]; i < all.length; i++) {385 html += '<div class="line" onmouseover="this.className += \' line-hover\'" onmouseout="this.className = this.className.replace(\' line-hover\', \'\');"><nav class="demo demo-toolbar"><a onclick="UI.viewSource(this, \'' + all[i] + '\');return false;" href="javascript://查看当前模块对应的源文件">源文件</a> | <a onclick="UI.viewRequires(this, \'' + all[i] + '\');return false;" href="javascript://查看当前模块依赖的模块">查看依赖</a>';386387 if (i > 0)388 html += ' | <a href="javascript://上移生成的位置" onclick="UI.moveModule(\'' + includeOrExclude + '\', ' + i + ', false); return false;">上移</a>';389390 if (i < all.length - 1)391 html += ' | <a href="javascript://下移生成的位置" onclick="UI.moveModule(\'' + includeOrExclude + '\', ' + i + ', true);">下移</a>';392393394 html += ' | <a onclick="UI.deleteModule(\'' + includeOrExclude + '\', ' + i + '); return false;" href="javascript://删除此行">删除</a></nav>';395 html += '<a class="link link-url" href="' + UI._getModuleExampleUrl(all[i]) + '" target="_blank">' + prefix + all[i] + postfix + '</a></div>';396 }397398 }399400 },401402 _updateBuildFile: function () {403 var buildFile = UI.currentBuildFile;404405 buildFile.compress = Dom.get('step3_compress').checked;406 buildFile.addAssert = Dom.get('step3_addAssert').checked;407408 buildFile.path = Dom.get('step3_buildfile').value;409 buildFile.js = Dom.get('step3_js').value;410 buildFile.css = Dom.get('step3_css').value;411 buildFile.assets = Dom.get('step3_assets').value;412 buildFile.dependencySyntax = Dom.get('step3_dependencySyntax').value;413 buildFile.uniqueBuildFiles = Dom.get('step3_uniqueBuildFiles').value;414 buildFile.parseMacro = Dom.get('step3_parseMacro').checked;415 buildFile.defines = Dom.get('step3_defines').value;416 buildFile.prependComments = Dom.get('step3_prependComments').value;417 buildFile.prependModuleComments = Dom.get('step3_prependModuleComments').value;418 },419420 _getModuleExampleUrl: function (module) {421 return Demo.baseUrl + Demo.Configs.examples + "/" + module.replace(/\.\w+$/, "") + ".html";422 },423424 addModule: function (showErrorMessage) {425 UI._checkValue('step3_module', function (value) {426 if (UI.currentBuildFile.includes.indexOf(value) >= 0) {427 if (confirm('模块 ' + value + ' 已在列表中,是否重复添加?') === false) {428 return;429 }430 }431432 if (UI.currentBuildFile.excludes.indexOf(value) >= 0) {433 if (confirm('模块 ' + value + ' 已被排除,是否取消排除并添加?') === false) {434 return;435 }436437 UI.currentBuildFile.excludes.remove(value);438 }439440 UI.currentBuildFile.includes.push(value);441 UI._showModuleList();442443 Dom.get('step3_module').value = '';444 });445 },446447 removeModule: function (showErrorMessage) {448 UI._checkValue('step3_module', function (value) {449450 if (UI.currentBuildFile.includes.indexOf(value) >= 0) {451 if (confirm('模块 ' + value + ' 已在列表中,是否排除?') === false) {452 return;453 }454 }455456 if (UI.currentBuildFile.excludes.indexOf(value) >= 0) {457 alert('模块 ' + value + ' 已被排除');458 return;459 }460461 UI.currentBuildFile.excludes.push(value);462 UI._showModuleList();463464 Dom.get('step3_module').value = '';465466 });467 },468469 clearModules: function () {470 if (confirm('确定清空列表吗?')) {471 UI.currentBuildFile.includes.length = UI.currentBuildFile.excludes.length = 0;472 UI._showModuleList();473 }474 },475476 moveModule: function (includeOrExclude, id, down) {477 var oldId = down ? (id + 1) : (id - 1);478 if (oldId < 0 || oldId >= UI.currentBuildFile[includeOrExclude].length) {479 return;480 }481 var old = UI.currentBuildFile[includeOrExclude][oldId];482 UI.currentBuildFile[includeOrExclude][oldId] = UI.currentBuildFile[includeOrExclude][id];483 UI.currentBuildFile[includeOrExclude][id] = old;484485 UI._showModuleList();486 },487488 deleteModule: function (includeOrExclude, id) {489 UI.currentBuildFile[includeOrExclude].splice(id, 1);490491 UI._showModuleList();492 },493494 viewSource: function (node, module) {495 var div = node.parentNode.parentNode;496497 if (div.nextSibling && Dom.hasClass(div.nextSibling, 'source')) {498 Dom.toggle(div.nextSibling);499 return;500 }501502 if (div.nextSibling && div.nextSibling.tagName === 'UL' && div.nextSibling.nextSibling && Dom.hasClass(div.nextSibling.nextSibling, 'source')) {503 Dom.toggle(div.nextSibling.nextSibling);504 return;505 }506507 UI._getSource(module, function (data) {508 div = Dom.after(div, '<ul class="source x-bubble"></ul>');509 var html = '';510 for (var path in data) {511 html += '<li><a href="' + Demo.baseUrl + Demo.Configs.src + '/' + path + '" class="x-hint" target="_blank">' + Demo.Utils.encodeHTML(data[path]) + '</a></li>';512 }513 div.innerHTML = html || '<li>(无源码)</li>';514 });515 },516517 viewRequires: function (node, module) {518 var div = node.parentNode.parentNode;519520 if (div.nextSibling && Dom.hasClass(div.nextSibling, 'refs')) {521 Dom.toggle(div.nextSibling);522 return;523 }524525 if (div.nextSibling && div.nextSibling.tagName === 'UL' && div.nextSibling.nextSibling && Dom.hasClass(div.nextSibling.nextSibling, 'refs')) {526 Dom.toggle(div.nextSibling.nextSibling);527 return;528 }529530 UI._getRequires(module, function (data) {531 div = Dom.after(div, '<ul class="refs"></ul>');532 var html = '';533 for (var path in data) {534 html += '<li><div class="line" onmouseover="this.className += \' line-hover\'" onmouseout="this.className = this.className.replace(\' line-hover\', \'\');"><span class="demo demo-toolbar"><a class="demo" href="javascript://查看关联的源文件" onclick="UI.viewSource(this, \'' + path + '\');return false;">源文件</a> | <a class="demo" href="javascript://查看当前模块依赖的项" onclick="UI.viewRequires(this, \'' + path + '\');return false;">查看依赖</a></span><a class="link" href="' + UI._getModuleExampleUrl(path) + '">' + path + '</a></div></li>';535 }536 div.innerHTML = html || '<li>(无依赖)</li>';537 });538539 },540541 toggleMore: function () {542 var more = Dom.get('step3_advance');543544 if (Dom.isHidden(more)) {545 Dom.show(more);546 Dom.get('step3_toggleMore').innerHTML = '<span class="toggle-arrow">▾</span> 折叠更多选项';547 } else {548 Dom.hide(more);549 Dom.get('step3_toggleMore').innerHTML = '<span class="toggle-arrow">▸</span> 展开更多选项';550 }551 },552553 // 获取某个的模块源码。554 _getSource: function (modulePath, callback) {555 UI._updateBuildFile();556557 var file = UI.currentBuildFile;558559 var r = {};560 var type = ModuleBuilder.getModuleType(modulePath);561 if (type) {562 checkFile(modulePath, function () {563 callback(r);564 });565 } else {566 checkFile(modulePath + ".js", function () {567 checkFile(modulePath + ".css", function () {568 callback(r);569 });570 });571 }572573 function checkFile(modulePath, callback) {574 var fullPath = ModuleBuilder.getFullPath(modulePath, file.path, file.moduleBasePath);575 ModuleBuilder.loadContent(fullPath, function (error, content) {576 if (!error) {577 r[modulePath] = fullPath;578 }579580 callback();581 });582 }583584 },585586 // 获取某个的模块引用项。587 _getRequires: function (modulePath, callback) {588 UI._updateBuildFile();589590 var file = UI.currentBuildFile;591 var r = {};592 var type = ModuleBuilder.getModuleType(modulePath);593 if (type) {594 checkFile(modulePath, function () {595 callback(r);596 });597 } else {598 checkFile(modulePath + ".js", function () {599 checkFile(modulePath + ".css", function () {600 callback(r);601 });602 });603 }604605 function checkFile(modulePath, callback) {606 var fullPath = ModuleBuilder.getFullPath(modulePath, file.path, file.moduleBasePath);607 ModuleBuilder.loadContent(fullPath, function (error, content) {608 if (!error) {609 var type = ModuleBuilder.getModuleType(modulePath);610 var rq;611612 if (type == ".js") {613 rq = ModuleBuilder.resolveJsRequires(content, file).includes;614 } else if (type == ".css") {615 rq = ModuleBuilder.resolveCssRequires(content, modulePath, fullPath, {}, file).imports;616 }617618619 if (rq) {620 rq.each(function (item) {621 r[item] = modulePath;622 });623 }624625 }626627 callback();628 });629 }630631 },632633 //#endregion634635 //#region 第四步636637 build: function () {638639 // 帮助用户点击添加。640 if (Dom.get('step3_module').value) {641 UI.addModule();642 }643644 if (!UI.currentBuildFile.includes.length) {645 alert("请先添加需要打包的模块");646 return;647 }648649 UI._updateBuildFile();650 UI._buildInternal();651652 },653654 preview: function () {655656 // 帮助用户点击添加。657 if (Dom.get('step3_module').value) {658 UI.addModule();659 }660661 if (!UI.currentBuildFile.includes.length) {662 alert("请先添加需要打包的模块");663 return;664 }665666 UI._updateBuildFile();667668 UI.step(4);669670 var form = Dom.get('step4_result');671 Dom.hide(Dom.get('step4_done'));672 Dom.hide(Dom.get('step4_form'));673 Dom.show(form);674675 ModuleBuilder.build({676677 file: UI.currentBuildFile,678679 log: function (info) {680 // console.info(info);681 Dom.get('step4_tip').innerHTML = Demo.Utils.encodeHTML(info);682 },683684 error: function (error) {685 Dom.get('step4_error').innerHTML += Demo.Utils.encodeHTML(error);686 },687688 complete: function (result) {689690 result.log("正在合并代码...");691692 Dom.show(Dom.get('step4_done'));693 694 var r = [];695 696 for(var key in result.css) {697 r.push('<link rel="stylesheet" type="text/css" href="' + Demo.baseUrl + Demo.Configs.src + '/' + result.css[key].path + '">');698 }699 700 for(var key in result.js) {701 r.push('<script type="text/javascript" src="' + Demo.baseUrl + Demo.Configs.src + '/' + result.js[key].path + '"></script>');702 }703704 UI._showResultForm('step4_js', '');705 UI._showResultForm('step4_css', '');706 UI._showResultForm('step4_assets', '');707 UI._showResultForm('step4_html', r.join('\r\n')); 708709 result.log("分析依赖完成!"); 710 711 }712713 });714715716 },717 718 save: function (){719 720 UI._updateBuildFile();721 UI.step(4);722723 if (!UI.usingXFly) {724 UI._alertOpenXFlyError();725 } else {726 UI._postNode('save');727 }728 729 },730 731 _postNode: function (action, data){732 733 var form = Dom.get('step4_form');734 Dom.hide(Dom.get('step4_result'));735 Dom.show(form);736737 form.innerHTML = '<iframe src="about:blank" frameborder="0" style="width:100%" height="200px"></iframe>';738739 form = form.firstChild;740741 var doc = form.contentDocument;742743 doc.open();744 doc.write('<form id="form" method="post" action="' + Demo.Configs.serverBaseUrl + Demo.Configs.apps + '/node/modulebuilder/server/api.njs?action=' + action + '" style="visibility:hidden;"><textarea id="data" name="data"></textarea></form>');745 doc.close();746747 doc.getElementById('data').value = JSON.stringify(UI.currentBuildFile);748 doc.getElementById('form').submit();749 750 },751752 // 开始打包。753 _buildInternal: function () {754 755 UI.step(4);756757 var needXFly = UI.currentBuildFile.js || UI.currentBuildFile.css || UI.currentBuildFile.assets || UI.currentBuildFile.path;758759 if (needXFly && !UI.usingXFly) {760 UI._alertOpenXFlyError();761 needXFly = false;762 }763764 // 基于服务器生成。765 if (needXFly) {766 UI._postNode('build');767 } else {768769 var form = Dom.get('step4_result');770 Dom.hide(Dom.get('step4_done'));771 Dom.hide(Dom.get('step4_form'));772 Dom.show(form);773774 ModuleBuilder.build({775776 file: UI.currentBuildFile,777778 log: function (info) {779 // console.info(info);780 Dom.get('step4_tip').innerHTML = Demo.Utils.encodeHTML(info);781 },782783 error: function (error) {784 Dom.get('step4_error').innerHTML += Demo.Utils.encodeHTML(error);785 },786787 complete: function (result) {788789 result.log("正在合并代码...");790 UI._showResultForm('step4_html', '');791792 setTimeout(function () {793794 Dom.show(Dom.get('step4_done'));795796 var jsStream = new StringStream();797 var cssStream = new StringStream();798799 ModuleBuilder.writeJs(result, jsStream);800801 setTimeout(function () {802 jsStream.end();803 UI._showResultForm('step4_js', jsStream.toString());804805 ModuleBuilder.writeCss(result, cssStream);806 cssStream.end();807 UI._showResultForm('step4_css', cssStream.toString());808809 setTimeout(function () {810 var assets = [];811812 for (var images in result.assets) {813 assets.push(result.assets[images].relative);814 }815816 UI._showResultForm('step4_assets', assets.join('\r\n'));817818 result.log("打包成功 !");819820 }, 0);821822 }, 0);823824 }, 0);825826 }827828 });829830 }831832 },833834 _showResultForm: function (id, value) {835 Dom.get(id).value = value;836 Dom.get(id).style.display = Dom.prev(Dom.get(id)).style.display = value ? '' : 'none';837 }838839 //#endregion840841};842 ...

Full Screen

Full Screen

register-file-types-test.mjs

Source:register-file-types-test.mjs Github

copy

Full Screen

...26 });27 it('should use cache', () => {28 registerFallback(F);29 const i0 = getEntityId();30 const f0 = buildFile('/etc/config');31 const f1 = buildFile('/etc/config');32 expect(f1.id).toBe(f0.id);33 expect(f0.i_parent.initial.id).toBe(f1.i_parent.initial.id);34 const i1 = getEntityId() - 1;35 expect(i1 - i0).toBe(2);36 });37 it('should register and find it back', async () => {38 registerFileRegExp(glob2regExp('test.a'), A);39 expect(buildFile('test.a')).toEqual(jasmine.any(A));40 });41 it('should register an array and find it back', async () => {42 registerFileRegExp([43 glob2regExp('test.a'),44 glob2regExp('test.b')45 ], A);46 expect(buildFile('test.a')).toEqual(jasmine.any(A));47 expect(buildFile('test.b')).toEqual(jasmine.any(A));48 expect(buildFile('TEST.A')).toEqual(jasmine.any(A));49 });50 // it('should handle fallback and find it back', async () => {51 // registerFileRegExp(glob2regExp('test.a'), A);52 // registerFileRegExp(FallBackRegExp, B);53 // expect(buildFile('test.a')).toEqual(jasmine.any(A));54 // expect(buildFile('test.b')).toEqual(jasmine.any(B));55 // });56 it('should handle globs', async () => {57 registerFileRegExp(glob2regExp('a.*'), A);58 registerFileRegExp(glob2regExp('b.*'), B);59 expect(buildFile('a.test')).toEqual(jasmine.any(A));60 expect(buildFile('b.test')).toEqual(jasmine.any(B));61 });62 it('should handle . as a litteral', async () => {63 registerFileRegExp(glob2regExp('a.test'), A);64 registerFileRegExp(glob2regExp('a_test'), B);65 expect(buildFile('a.test')).toEqual(jasmine.any(A));66 expect(buildFile('a_test')).toEqual(jasmine.any(B));67 });68 it('should handle globs by size', async () => {69 registerFileRegExp(glob2regExp('test.*'), A);70 registerFileRegExp(glob2regExp('test.truc.*'), B);71 expect(buildFile('test.truc.bac')).toEqual(jasmine.any(B));72 expect(buildFile('test.somethingelse')).toEqual(jasmine.any(A));73 });...

Full Screen

Full Screen

build.js

Source:build.js Github

copy

Full Screen

1234var buildFilePath = process.argv[2];56if (buildFilePath) {7 var ModuleBuilder = require('../assets/modulebuilder.js');8 var Demo = require('../../../demo/demo.js');9 ModuleBuilder.moduleBasePath = Demo.basePath + Demo.Configs.src;10 ModuleBuilder.load(buildFilePath, function (buildFile) {11 if (buildFile.js) {12 buildFile.js = ModuleBuilder.parseRelativePath(buildFilePath, buildFile.js);13 }14 if (buildFile.css) {15 buildFile.css = ModuleBuilder.parseRelativePath(buildFilePath, buildFile.css);16 }17 if (buildFile.assets) {18 buildFile.assets = ModuleBuilder.parseRelativePath(buildFilePath, buildFile.assets);19 }2021 ModuleBuilder.build({22 file: buildFile,23 complete: function (result) {24 var IO = require('utilskit/io');25 try {26 27 if (result.file.js && !isEmpty(result.js)) {28 var stream = IO.openWrite(result.file.js, {29 flags: 'w',30 encoding: Demo.Configs.encoding31 });32 ModuleBuilder.writeJs(result, stream);33 stream.end();34 result.log("生成 js 文件: " + result.file.js + "");35 }36 if (result.file.css && !isEmpty(result.css)) {37 var stream = IO.openWrite(result.file.css, {38 flags: 'w',39 encoding: Demo.Configs.encoding40 });41 ModuleBuilder.writeCss(result, stream);42 stream.end();43 result.log("生成 css 文件: " + result.file.css + "");44 }45 if (result.file.assets && !isEmpty(result.assets)) {46 result.log("正在复制资源...");47 for (var key in result.assets) {48 IO.copyFile(result.assets[key].from, result.assets[key].to);49 }50 result.log("生成图片文件夹: " + result.file.assets + "");51 }52 result.log("生成完成!");53 } catch (e) {54 result.error(e.message);55 }56 }5758 });5960 });6162} else {63 console.log("用法: build path/to/buildfile.js");64}65function isEmpty(obj) {66 for (var key in obj) {67 return false;68 }69 return true; ...

Full Screen

Full Screen

coder.js

Source:coder.js Github

copy

Full Screen

1// This must be ran from VS Code's root.2const gulp = require("gulp");3const path = require("path");4const _ = require("underscore");5const buildfile = require("./src/buildfile");6const common = require("./build/lib/optimize");7const util = require("./build/lib/util");8const vscodeEntryPoints = _.flatten([9 buildfile.entrypoint("vs/workbench/workbench.web.api"),10 buildfile.entrypoint("vs/server/entry"),11 buildfile.base,12 buildfile.workbenchWeb,13 buildfile.workerExtensionHost,14 buildfile.workerNotebook,15 buildfile.keyboardMaps,16 // See ./src/vs/workbench/buildfile.desktop.js17 buildfile.entrypoint("vs/platform/files/node/watcher/unix/watcherApp"),18 buildfile.entrypoint("vs/platform/files/node/watcher/nsfw/watcherApp"),19 buildfile.entrypoint('vs/platform/terminal/node/ptyHostMain'),20 buildfile.entrypoint("vs/workbench/services/extensions/node/extensionHostProcess"),21]);22// See ./build/gulpfile.vscode.js23const vscodeResources = [24 "out-build/vs/server/fork.js",25 "!out-build/vs/server/doc/**",26 "out-build/vs/workbench/services/extensions/worker/extensionHostWorkerMain.js",27 "out-build/bootstrap.js",28 "out-build/bootstrap-fork.js",29 "out-build/bootstrap-amd.js",30 'out-build/bootstrap-node.js',31 'out-build/vs/**/*.{svg,png,html,ttf,jpg}',32 "!out-build/vs/code/browser/workbench/*.html",33 '!out-build/vs/code/electron-browser/**',34 "out-build/vs/base/common/performance.js",35 "out-build/vs/base/node/languagePacks.js",36 'out-build/vs/base/browser/ui/codicons/codicon/**',37 'out-build/vs/base/node/userDataPath.js',38 "out-build/vs/workbench/browser/media/*-theme.css",39 "out-build/vs/workbench/contrib/debug/**/*.json",40 "out-build/vs/workbench/contrib/externalTerminal/**/*.scpt",41 "out-build/vs/workbench/contrib/webview/browser/pre/*.js",42 "out-build/vs/**/markdown.css",43 "out-build/vs/workbench/contrib/tasks/**/*.json",44 "out-build/vs/platform/files/**/*.md",45 "!**/test/**"46];47gulp.task("optimize", gulp.series(48 util.rimraf("out-vscode"),49 common.optimizeTask({50 src: "out-build",51 entryPoints: vscodeEntryPoints,52 resources: vscodeResources,53 loaderConfig: common.loaderConfig(),54 out: "out-vscode",55 inlineAmdImages: true,56 bundleInfo: undefined57 }),58));59gulp.task("minify", gulp.series(60 util.rimraf("out-vscode-min"),61 common.minifyTask("out-vscode")...

Full Screen

Full Screen

gulp-github1s.js

Source:gulp-github1s.js Github

copy

Full Screen

1// This must be ran from VS Code's root.2const gulp = require('gulp');3const _ = require('underscore');4const buildfile = require('./src/buildfile');5const common = require('./build/lib/optimize');6const util = require('./build/lib/util');7const vscodeEntryPoints = _.flatten([8 buildfile.entrypoint('vs/workbench/workbench.web.api'),9 buildfile.base,10 buildfile.workbenchWeb,11 buildfile.workerExtensionHost,12 buildfile.workerNotebook,13 buildfile.keyboardMaps,14 buildfile.entrypoint('vs/platform/files/node/watcher/unix/watcherApp'),15 buildfile.entrypoint('vs/platform/files/node/watcher/nsfw/watcherApp'),16 buildfile.entrypoint(17 'vs/workbench/services/extensions/node/extensionHostProcess'18 ),19]);20const vscodeResources = [21 '!out-build/vs/server/doc/**',22 'out-build/vs/workbench/services/extensions/worker/extensionHostWorkerMain.js',23 'out-build/bootstrap.js',24 'out-build/bootstrap-fork.js',25 'out-build/bootstrap-amd.js',26 'out-build/bootstrap-node.js',27 'out-build/paths.js',28 'out-build/vs/**/*.{svg,png,html,ttf}',29 '!out-build/vs/code/browser/workbench/*.html',30 '!out-build/vs/code/electron-browser/**',31 'out-build/vs/base/common/performance.js',32 'out-build/vs/base/node/languagePacks.js',33 'out-build/vs/base/browser/ui/codicons/codicon/**',34 'out-build/vs/workbench/browser/media/*-theme.css',35 'out-build/vs/workbench/contrib/debug/**/*.json',36 'out-build/vs/workbench/contrib/externalTerminal/**/*.scpt',37 'out-build/vs/workbench/contrib/webview/browser/pre/*.js',38 'out-build/vs/**/markdown.css',39 'out-build/vs/workbench/contrib/tasks/**/*.json',40 'out-build/vs/platform/files/**/*.md',41 '!**/test/**',42];43gulp.task(44 'optimize',45 gulp.series(46 util.rimraf('out-vscode'),47 common.optimizeTask({48 src: 'out-build',49 entryPoints: vscodeEntryPoints,50 resources: vscodeResources,51 loaderConfig: common.loaderConfig(),52 out: 'out-vscode',53 inlineAmdImages: true,54 bundleInfo: undefined,55 })56 )57);58gulp.task(59 'minify',60 gulp.series(util.rimraf('out-vscode-min'), common.minifyTask('out-vscode'))...

Full Screen

Full Screen

gulp-githubsurf.js

Source:gulp-githubsurf.js Github

copy

Full Screen

1// This must be ran from VS Code's root.2const gulp = require("gulp");3const _ = require("underscore");4const buildfile = require("./src/buildfile");5const common = require("./build/lib/optimize");6const util = require("./build/lib/util");7const vscodeEntryPoints = _.flatten([8 buildfile.entrypoint("vs/workbench/workbench.web.api"),9 buildfile.base,10 buildfile.workbenchWeb,11 buildfile.workerExtensionHost,12 buildfile.workerNotebook,13 buildfile.keyboardMaps,14 buildfile.entrypoint("vs/platform/files/node/watcher/unix/watcherApp"),15 buildfile.entrypoint("vs/platform/files/node/watcher/nsfw/watcherApp"),16 buildfile.entrypoint("vs/workbench/services/extensions/node/extensionHostProcess"),17]);18const vscodeResources = [19 "!out-build/vs/server/doc/**",20 "out-build/vs/workbench/services/extensions/worker/extensionHostWorkerMain.js",21 "out-build/bootstrap.js",22 "out-build/bootstrap-fork.js",23 "out-build/bootstrap-amd.js",24 'out-build/bootstrap-node.js',25 "out-build/paths.js",26 'out-build/vs/**/*.{svg,png,html,ttf}',27 "!out-build/vs/code/browser/workbench/*.html",28 '!out-build/vs/code/electron-browser/**',29 "out-build/vs/base/common/performance.js",30 "out-build/vs/base/node/languagePacks.js",31 'out-build/vs/base/browser/ui/codicons/codicon/**',32 "out-build/vs/workbench/browser/media/*-theme.css",33 "out-build/vs/workbench/contrib/debug/**/*.json",34 "out-build/vs/workbench/contrib/externalTerminal/**/*.scpt",35 "out-build/vs/workbench/contrib/webview/browser/pre/*.js",36 "out-build/vs/**/markdown.css",37 "out-build/vs/workbench/contrib/tasks/**/*.json",38 "out-build/vs/platform/files/**/*.md",39 "!**/test/**"40];41gulp.task("optimize", gulp.series(42 util.rimraf("out-vscode"),43 common.optimizeTask({44 src: "out-build",45 entryPoints: vscodeEntryPoints,46 resources: vscodeResources,47 loaderConfig: common.loaderConfig(),48 out: "out-vscode",49 inlineAmdImages: true,50 bundleInfo: undefined51 }),52));53gulp.task("minify", gulp.series(54 util.rimraf("out-vscode-min"),55 common.minifyTask("out-vscode")...

Full Screen

Full Screen

gulp-gogs1s.js

Source:gulp-gogs1s.js Github

copy

Full Screen

1// This must be ran from VS Code's root.2const gulp = require("gulp");3const _ = require("underscore");4const buildfile = require("./src/buildfile");5const common = require("./build/lib/optimize");6const util = require("./build/lib/util");7const vscodeEntryPoints = _.flatten([8 buildfile.entrypoint("vs/workbench/workbench.web.api"),9 buildfile.base,10 buildfile.workbenchWeb,11 buildfile.workerExtensionHost,12 buildfile.workerNotebook,13 buildfile.keyboardMaps,14 buildfile.entrypoint("vs/platform/files/node/watcher/unix/watcherApp"),15 buildfile.entrypoint("vs/platform/files/node/watcher/nsfw/watcherApp"),16 buildfile.entrypoint("vs/workbench/services/extensions/node/extensionHostProcess"),17]);18const vscodeResources = [19 "!out-build/vs/server/doc/**",20 "out-build/vs/workbench/services/extensions/worker/extensionHostWorkerMain.js",21 "out-build/bootstrap.js",22 "out-build/bootstrap-fork.js",23 "out-build/bootstrap-amd.js",24 'out-build/bootstrap-node.js',25 "out-build/paths.js",26 'out-build/vs/**/*.{svg,png,html,ttf}',27 "!out-build/vs/code/browser/workbench/*.html",28 '!out-build/vs/code/electron-browser/**',29 "out-build/vs/base/common/performance.js",30 "out-build/vs/base/node/languagePacks.js",31 'out-build/vs/base/browser/ui/codicons/codicon/**',32 "out-build/vs/workbench/browser/media/*-theme.css",33 "out-build/vs/workbench/contrib/debug/**/*.json",34 "out-build/vs/workbench/contrib/externalTerminal/**/*.scpt",35 "out-build/vs/workbench/contrib/webview/browser/pre/*.js",36 "out-build/vs/**/markdown.css",37 "out-build/vs/workbench/contrib/tasks/**/*.json",38 "out-build/vs/platform/files/**/*.md",39 "!**/test/**"40];41gulp.task("optimize", gulp.series(42 util.rimraf("out-vscode"),43 common.optimizeTask({44 src: "out-build",45 entryPoints: vscodeEntryPoints,46 resources: vscodeResources,47 loaderConfig: common.loaderConfig(),48 out: "out-vscode",49 inlineAmdImages: true,50 bundleInfo: undefined51 }),52));53gulp.task("minify", gulp.series(54 util.rimraf("out-vscode-min"),55 common.minifyTask("out-vscode")...

Full Screen

Full Screen

cli.js

Source:cli.js Github

copy

Full Screen

1#!/usr/bin/env node2/**3 * @app build4 * @app:npm @archivist/build5 * @app:git https://github.com/Archivist-Nerd/node-build6 * @app:Licence MIT7 * @app:Copyright Copyright (c) 2020 Archivist-Nerd8 *9 * @app:Example:10 * build [buildFile]11 *12 * @app:Example:13 * build ./src/.build14 */15'use strict';1617const pkg = require('./package.json') // package.json Contents18 , bargs = require("@archivistnerd/bargs") // Command Line Arguments19 , app = require('../.') // actual app code20 ;21process.on('uncaughtException', err => console.error('uncaughtException', err))22process.on('unhandledRejection', err => console.error('unhandledRejection', err))23bargs24 .scriptName( `${ pkg.name } \t ${ 'v'+pkg.version } \t ${ pkg.description }` )25 .usage(`build [buildfile]`)2627 .command('$ [buildfile]', 'use buildfile',28 (argv) => {29 if ( argv.buildFile == undefined ) return bargs.displayHelp()30 if (!app.build( argv.buildFile )) console.log(` error: file "${argv.buildFile}" does not exist`)31 }32 ,[33 { name: 'buildFile', type: 'string', describe: 'build filename' },34 ])3536 .help() ...

Full Screen

Full Screen

Jest Testing Tutorial

LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.

Chapters

  1. What is Jest Framework
  2. Advantages of Jest - Jest has 3,898,000 GitHub repositories, as mentioned on its official website. Learn what makes Jest special and why Jest has gained popularity among the testing and developer community.
  3. Jest Installation - All the prerequisites and set up steps needed to help you start Jest automation testing.
  4. Using Jest with NodeJS Project - Learn how to leverage Jest framework to automate testing using a NodeJS Project.
  5. Writing First Test for Jest Framework - Get started with code-based tutorial to help you write and execute your first Jest framework testing script.
  6. Jest Vocabulary - Learn the industry renowned and official jargons of the Jest framework by digging deep into the Jest vocabulary.
  7. Unit Testing with Jest - Step-by-step tutorial to help you execute unit testing with Jest framework.
  8. Jest Basics - Learn about the most pivotal and basic features which makes Jest special.
  9. Jest Parameterized Tests - Avoid code duplication and fasten automation testing with Jest using parameterized tests. Parameterization allows you to trigger the same test scenario over different test configurations by incorporating parameters.
  10. Jest Matchers - Enforce assertions better with the help of matchers. Matchers help you compare the actual output with the expected one. Here is an example to see if the object is acquired from the correct class or not. -

|<p>it('check_object_of_Car', () => {</p><p> expect(newCar()).toBeInstanceOf(Car);</p><p> });</p>| | :- |

  1. Jest Hooks: Setup and Teardown - Learn how to set up conditions which needs to be followed by the test execution and incorporate a tear down function to free resources after the execution is complete.
  2. Jest Code Coverage - Unsure there is no code left unchecked in your application. Jest gives a specific flag called --coverage to help you generate code coverage.
  3. HTML Report Generation - Learn how to create a comprehensive HTML report based on your Jest test execution.
  4. Testing React app using Jest Framework - Learn how to test your react web-application with Jest framework in this detailed Jest tutorial.
  5. Test using LambdaTest cloud Selenium Grid - Run your Jest testing script over LambdaTest cloud-based platform and leverage parallel testing to help trim down your test execution time.
  6. Snapshot Testing for React Front Ends - Capture screenshots of your react based web-application and compare them automatically for visual anomalies with the help of Jest tutorial.
  7. Bonus: Import ES modules with Jest - ES modules are also known as ECMAScript modules. Learn how to best use them by importing in your Jest testing scripts.
  8. Jest vs Mocha vs Jasmine - Learn the key differences between the most popular JavaScript-based testing frameworks i.e. Jest, Mocha, and Jasmine.
  9. Jest FAQs(Frequently Asked Questions) - Explore the most commonly asked questions around Jest framework, with their answers.

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful