Best JavaScript code snippet using wpt
reports.js
Source:reports.js
...34 $("#confirm_submission").modal({backdrop: 'static'});35 $("form.report-form").submit(function(event){36 event.preventDefault();37 var year = $("#report_year").val();38 checkReportExists(year, true);39 });40 $("#cancel").click(function(e){41 e.preventDefault();42 $("#confirm_submission").modal("hide");43 $("#do_submit").show();44 $("#confirmation_warning").hide();45 });46 $("#do_submit").click(function(e){47 e.preventDefault();48 $(this).unbind('click');49 $("form.report-form").unbind("submit");50 $("form.report-form").submit();51 });52}53function fillInModalDetails(){54 $("#confirm_year").html($("#report_year option:selected").text());55 $("#confirm_basis").html($("#report_basis option:selected").text());56 var objRE = new RegExp(/([^\/\\]+)$/);57 var strName = '';58 $("#confirm_exports").empty();59 if($("#report_has_exports_false").is(':checked')){60 if($("#report_no_trade_exports").is(':checked')){61 $("#confirm_exports").append("<li>No trade occurred</li>");62 }else {63 $("#confirm_exports").append("<li>No export files were added.</li>");64 }65 }else if($("#report_has_exports_true").is(':checked')){66 $("#uploaded_exports").find('.upload_file').each(function(){67 if($(this).nextAll('input[type=hidden]').val()!=="1" && $(this).val() !== ""){68 strName = objRE.exec($(this).val());69 $("#confirm_exports").append("<li>"+strName[1]+"</li>");70 }71 });72 if($("#confirm_exports").children('li').length === 0){73 $("#confirm_exports").append("<li>No export files were added. <span class='warning'>Please add a file or select 'No' if you do not have any files to upload.</span></li>");74 $("#do_submit").hide();75 $("#confirmation_warning").show();76 }77 }else {78 $("#confirm_exports").append("<li><span class='warning'>Please select one option ('Yes' or 'No').</span></li>");79 $("#do_submit").hide();80 $("#confirmation_warning").show();81 }82 $("#confirm_imports").empty();83 if($("#report_has_imports_false").is(':checked')){84 if($("#report_no_trade_imports").is(':checked')){85 $("#confirm_imports").append("<li>No trade occurred</li>");86 } else {87 $("#confirm_imports").append("<li>No import files were added.</li>");88 }89 }else if($("#report_has_imports_true").is(':checked')){90 $("#uploaded_imports").find('.upload_file').each(function(){91 if($(this).nextAll('input[type=hidden]').val()!=="1" && $(this).val() !== ""){92 strName = objRE.exec($(this).val());93 $("#confirm_imports").append("<li>"+strName[1]+"</li>");94 }95 });96 if($("#confirm_imports").children('li').length === 0){97 $("#confirm_imports").append("<li>No import files were added. <span class='warning'>Please add a file or select 'No' if you do not have any files to upload.</span></li>");98 $("#do_submit").hide();99 $("#confirmation_warning").show();100 }101 } else {102 $("#confirm_imports").append("<li><span class='warning'>Please select one option ('Yes' or 'No').</span></li>");103 $("#do_submit").hide();104 $("#confirmation_warning").show();105 }106 $("#confirm_additional_information").empty();107 if($("#report_has_additional_information_false").is(':checked')){108 $("#confirm_additional_information").append("<li>No additional information was added.</li>");109 }else{110 $("#uploaded_additional_information").find('.upload_file').each(function(){111 if($(this).nextAll('input[type=hidden]').val()!=="1" && $(this).val() !== ""){112 strName = objRE.exec($(this).val());113 $("#confirm_additional_information").append("<li>"+strName[1]+"</li>");114 }115 });116 if($("#confirm_additional_information").children('li').length === 0){117 $("#confirm_additional_information").append("<li>No additional information was added.</li>");118 }119 }120}121function hasFilesOrNot(){122 $("input[type=radio]").change(function(){123 if(this.value == "true"){124 //hide no trade if present125 $(this).parents('.clearfix').nextAll('.no_trade').hide('slow');126 //remove tick from no trade checkbox127 $(this).parents('.clearfix').nextAll('.no_trade').find('input').attr('checked', false);128 //show files controls129 $(this).parents('.clearfix').nextAll('.files_control').show('slow');130 //change the documents that were marked to be removed by the user interaction with Yes or No question.131 $(this).parents('.clearfix').nextAll('.files_control').find('.to_be_removed').each(function(){132 $(this).val("0").removeClass("to_be_removed");133 });134 } else{135 $(this).parents('.clearfix').nextAll('.no_trade').show('slow');136 $(this).parents('.clearfix').nextAll('.files_control').hide('slow');137 //Mark all the documents of this type to be destroyed, unless they are already marked for destruction.138 $(this).parents('.clearfix').nextAll('.files_control').find("input[type=hidden]").each(function(){139 if($(this).val() != "1"){140 $(this).addClass("to_be_removed");141 $(this).val("1");142 }143 });144 }145 });146}147function existingReport(){148 $("#existing_report").modal({backdrop: 'static'});149 $("#existing_report_cancel").click(function(e){150 e.preventDefault();151 $("#existing_report").modal('hide');152 });153 $("#report_year").change(function(){154 var year = $(this).val();155 checkReportExists(year, false);156 });157}158function checkReportExists(year, submission){159 var result;160 $.ajax({161 url: '/users/'+CURRENT_USER+'/has_report',162 data: {year: year},163 dataType: 'json',164 success: function(report_id){165 if(report_id !== -1 && report_id !== CURRENT_REPORT){166 $("#existing_report_year").text(year);167 $("#edit_existing").attr("href", '/reports/'+report_id+'/edit');168 $("#existing_report").modal('show');169 } else if(submission){170 fillInModalDetails();171 $("#confirm_submission").modal("show");172 }...
utils.js
Source:utils.js
1require('dotenv').config()2const getenv = require('getenv');3const { readdir, access, writeFile, readFile, unlink, rmdir } = require('fs').promises;4const CY_TESTS_DIR = getenv.string('CY_TESTS_DIR');5const CY_REPORTS_DIR = getenv.string('CY_REPORTS_DIR');6const CY_OUTPUT = getenv.string('CY_OUTPUT');7const CY_DOWNLOADS_DIR = getenv.string('CY_DOWNLOADS_DIR');8const fileExists = async (path) => {9 try {10 await access(path);11 return true;12 } catch {13 return false;14 }15};16const getTests = async () => {17 const dirContent = await readdir(CY_TESTS_DIR);18 return dirContent.filter(entry => entry.includes('.test.js'));19};20const writeJson = async (object) => {21 const content = JSON.stringify(object, null, '\t');22 await writeFile(CY_OUTPUT, content);23};24const upsertTestStatus = async (testname, status) => {25 const content = await readFile(CY_OUTPUT);26 const testsObj = JSON.parse(content);27 testsObj[testname] = status;28 await writeJson(testsObj);29};30const checkReportExists = async (test) => {31 const path = `${CY_REPORTS_DIR}/${test}.json`;32 const reportExists = await fileExists(path);33 return reportExists;34};35const checkTestPassed = async (test) => {36 const path = `${CY_REPORTS_DIR}/${test}.json`;37 const reportExists = await fileExists(path);38 if (!reportExists) return false;39 const content = await readFile(path);40 const { fixtures } = JSON.parse(content);41 return !fixtures.some(fixture => fixture.tests.some(test => test.errs.length > 0));42};43const getReports = async () => {44 const dirContent = await readdir(CY_REPORTS_DIR);45 return dirContent.filter(entry => entry.includes('.json'));46};47const cleanErrorReports = async () => {48 const reports = await getReports();49 for (let i = 0; i < reports.length; i++) {50 const testName = reports[i].replace('.json', '');51 const hasTestPassed = await checkTestPassed(testName);52 if (!hasTestPassed) {53 await unlink(`${CY_REPORTS_DIR}/${reports[i]}`);54 }55 }56};57const cleanDownloadsFolder = async () => {58 await rmdir(CY_DOWNLOADS_DIR, { recursive: true });59};60module.exports = {61 fileExists,62 getTests,63 writeJson,64 upsertTestStatus,65 checkReportExists,66 checkTestPassed,67 cleanErrorReports,68 cleanDownloadsFolder...
runner.js
Source:runner.js
...37 const startedAt = Date.now();38 return new Promise((resolve) => {39 const intervalId = setInterval(async () => {40 if (Date.now() - startedAt > TIMEOUT) return resolve(false);41 const doesReportExist = await checkReportExists(test);42 if (doesReportExist) {43 const hasTestPassed = await checkTestPassed(test);44 if (hasTestPassed) clearInterval(intervalId);45 return resolve(hasTestPassed);46 }47 }, 1000);48 });49};50module.exports.run = async (test) => {51 await testcafe(test);52 const hasTestPassed = await waitForReport(test, { TIMEOUT: 10000 });53 return hasTestPassed;...
Using AI Code Generation
1var wpt = require('./wpt.js');2 if(err){3 console.log(err);4 } else {5 console.log(exists);6 }7});8var wpt = require('./wpt.js');9wpt.getLocations(function(err, locations){10 if(err){11 console.log(err);12 } else {13 console.log(locations);14 }15});16var wpt = require('./wpt.js');17wpt.getTesters(function(err, testers){18 if(err){
Using AI Code Generation
1var wptReport = require('wptReport');2 if(err) {3 console.log(err);4 } else {5 console.log(reportExists);6 }7});8## checkReportExists(url, callback)9 if(err) {10 console.log(err);11 } else {12 console.log(reportExists);13 }14});15## getReport(url, callback)16 if(err) {17 console.log(err);18 } else {19 console.log(report);20 }21});22## getReportList(callback)23wptReport.getReportList(function(err, reportList) {24 if(err) {25 console.log(err);26 } else {27 console.log(reportList);28 }29});30## getReportListByDate(date, callback)31wptReport.getReportListByDate('2015-04-01', function(err, reportList) {32 if(err) {33 console.log(err);34 } else {35 console.log(reportList);36 }37});38## getReportListByDateRange(startDate, endDate, callback)39wptReport.getReportListByDateRange('2015-04-01', '2015-04-10', function(err, reportList) {40 if(err) {41 console.log(err);42 } else {43 console.log(reportList);44 }45});46## getReportListByURL(url, callback)47 if(err) {48 console.log(err);49 } else {50 console.log(reportList);51 }52});53## getReportListByDateAndURL(date, url, callback)54wptReport.getReportListByDateAndURL('2015-04
Using AI Code Generation
1var checkReportExists = require('./wpt-api').checkReportExists;2 if (err) {3 console.log('Error checking if report exists', err);4 } else {5 console.log('Report exists?', reportExists);6 }7});8var getTestResults = require('./wpt-api').getTestResults;9 if (err) {10 console.log('Error getting report', err);11 } else {12 console.log('Report', report);13 }14});15var getTestResults = require('./wpt-api').getTestResults;16}, function(err, report) {17 if (err) {18 console.log('Error getting report', err);19 } else {20 console.log('Report', report);21 }22});23var getTestResults = require('./wpt-api').getTestResults;24}, function(err, report) {25 if (err) {26 console.log('Error getting report', err);27 } else {28 console.log('Report', report);29 }30});31var getTestResults = require('./wpt-api').getTestResults;
Using AI Code Generation
1var wpt = require('wpt-api');2var wpt = new wpt('A.5f5a8a7b1f9c0d7e5b5a8a7b1f9c0d7e');3 console.log(data);4});5var wpt = require('wpt-api');6var wpt = new wpt('A.5f5a8a7b1f9c0d7e5b5a8a7b1f9c0d7e');7 console.log(data);8});9var wpt = require('wpt-api');10var wpt = new wpt('A.5f5a8a7b1f9c0d7e5b5a8a7b1f9c0d7e');11 console.log(data);12});13### Get Test Results (with Page Speed)14var wpt = require('wpt-api');15var wpt = new wpt('A.5f5a8a7b1f9c0d7e5b5a8a7b1f9c0d7e');16 console.log(data);17});18### Get Test Results (with HAR)19var wpt = require('wpt-api');20var wpt = new wpt('A.5f5a8a7b1f9c0d7e5b5a8a7b1f9c0d7e');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!