How to use clearReportsOnServer method in wpt

Best JavaScript code snippet using wpt

reporting-common.js

Source:reporting-common.js Github

copy

Full Screen

...57 return false;58 }59 return true;60}61async function clearReportsOnServer(host) {62 const res = await fetch(63 '/reporting/resources/report.py', {64 method: "POST",65 body: JSON.stringify({66 op: "DELETE",67 reportIDs: reportEndpoints.map(endpoint => endpoint.reportID)68 })69 });70 assert_equals(res.status, 200, "reports cleared");71}72async function pollReports(endpoint) {73 const res = await fetch(getReportEndpointURL(endpoint.reportID),74 { cache: 'no-store' });75 if (res.status !== 200) {76 return;77 }78 for (const report of await res.json()) {79 if (isCoopOpenerBreakageReport(report))80 endpoint.reports.push(report);81 }82}83// Recursively check that all members of expectedReport are present or matched84// in report.85// Report may have members not explicitly expected by expectedReport.86function isObjectAsExpected(report, expectedReport) {87 if (( report === undefined || report === null88 || expectedReport === undefined || expectedReport === null )89 && report !== expectedReport ) {90 return false;91 }92 if (expectedReport instanceof RegExp && typeof report === "string") {93 return expectedReport.test(report);94 }95 // Perform this check now, as RegExp and strings above have different typeof.96 if (typeof report !== typeof expectedReport)97 return false;98 if (typeof expectedReport === 'object') {99 return Object.keys(expectedReport).every(key => {100 return isObjectAsExpected(report[key], expectedReport[key]);101 });102 }103 return report == expectedReport;104}105async function checkForExpectedReport(expectedReport) {106 return new Promise( async (resolve, reject) => {107 const polls = 20;108 const waitTime = 200;109 for (var i=0; i < polls; ++i) {110 pollReports(expectedReport.endpoint);111 for (var j=0; j<expectedReport.endpoint.reports.length; ++j){112 if (isObjectAsExpected(expectedReport.endpoint.reports[j],113 expectedReport.report)){114 expectedReport.endpoint.reports.splice(j,1);115 resolve();116 return;117 }118 };119 await wait(waitTime);120 }121 reject(122 replaceTokensInReceivedReport(123 "No report matched the expected report for endpoint: "124 + expectedReport.endpoint.name125 + ", expected report: " + JSON.stringify(expectedReport.report)126 + ", within available reports: "127 + JSON.stringify(expectedReport.endpoint.reports)128 ));129 });130}131function replaceFromRegexOrString(str, match, value) {132 if (str instanceof RegExp) {133 return RegExp(str.source.replace(match, value));134 }135 return str.replace(match, value);136}137// Replace generated values in regexes and strings of an expected report:138// EXECUTOR_UUID: the uuid generated with token().139function replaceValuesInExpectedReport(expectedReport, executorUuid) {140 if (expectedReport.report.body !== undefined) {141 if (expectedReport.report.body.nextResponseURL !== undefined) {142 expectedReport.report.body.nextResponseURL = replaceFromRegexOrString(143 expectedReport.report.body.nextResponseURL, "EXECUTOR_UUID",144 executorUuid);145 }146 if (expectedReport.report.body.previousResponseURL !== undefined) {147 expectedReport.report.body.previousResponseURL = replaceFromRegexOrString(148 expectedReport.report.body.previousResponseURL, "EXECUTOR_UUID",149 executorUuid);150 }151 if (expectedReport.report.body.referrer !== undefined) {152 expectedReport.report.body.referrer = replaceFromRegexOrString(153 expectedReport.report.body.referrer, "EXECUTOR_UUID",154 executorUuid);155 }156 }157 if (expectedReport.report.url !== undefined) {158 expectedReport.report.url = replaceFromRegexOrString(159 expectedReport.report.url, "EXECUTOR_UUID", executorUuid);160 }161 return expectedReport;162}163function replaceTokensInReceivedReport(str) {164 return str.replace(/.{8}-.{4}-.{4}-.{4}-.{12}/g, `(uuid)`);165}166// Run a test then check that all expected reports are present.167async function reportingTest(testFunction, executorToken, expectedReports) {168 await new Promise(testFunction);169 expectedReports = Array.from(170 expectedReports,171 report => replaceValuesInExpectedReport(report, executorToken) );172 await Promise.all(Array.from(expectedReports, checkForExpectedReport));173}174function convertToWPTHeaderPipe([name, value]) {175 return `header(${name}, ${encodeURIComponent(value)})`;176}177function getReportToHeader(host) {178 return [179 "Report-To",180 reportEndpoints.map(181 reportEndpoint => {182 const reportToJSON = {183 'group': `${reportEndpoint.name}`,184 'max_age': 3600,185 'endpoints': [{186 'url': `${host}${getReportEndpointURL(reportEndpoint.reportID)}`187 }]188 };189 // Escape comma as required by wpt pipes.190 return JSON.stringify(reportToJSON)191 .replace(/,/g, '\\,')192 .replace(/\(/g, '\\\(')193 .replace(/\)/g, '\\\)=');194 }195 ).join("\\, ")];196}197function getReportingEndpointsHeader(host) {198 return [199 "Reporting-Endpoints",200 reportEndpoints.map(reportEndpoint => {201 return `${reportEndpoint.name}="${host}${getReportEndpointURL(reportEndpoint.reportID)}"`;202 }).join("\\, ")];203}204// Return Report and Report-Only policy headers.205function getPolicyHeaders(coop, coep, coopRo, coepRo) {206 return [207 [`Cross-Origin-Opener-Policy`, coop],208 [`Cross-Origin-Embedder-Policy`, coep],209 [`Cross-Origin-Opener-Policy-Report-Only`, coopRo],210 [`Cross-Origin-Embedder-Policy-Report-Only`, coepRo]];211}212function navigationReportingTest(testName, host, coop, coep, coopRo, coepRo,213 expectedReports) {214 const executorToken = token();215 const callbackToken = token();216 promise_test(async t => {217 await reportingTest(async resolve => {218 const openee_headers = [219 getReportingEndpointsHeader(host.origin),220 ...getPolicyHeaders(coop, coep, coopRo, coepRo)221 ].map(convertToWPTHeaderPipe);222 const openee_url = host.origin + executor_path +223 openee_headers.join('|') + `&uuid=${executorToken}`;224 const openee = window.open(openee_url);225 const uuid = token();226 t.add_cleanup(() => send(uuid, "window.close()"));227 // 1. Make sure the new document is loaded.228 send(executorToken, `229 send("${callbackToken}", "Ready");230 `);231 let reply = await receive(callbackToken);232 assert_equals(reply, "Ready");233 resolve();234 }, executorToken, expectedReports);235 }, `coop reporting test ${testName} to ${host.name} with ${coop}, ${coep}, ${coopRo}, ${coepRo}`);236}237function navigationDocumentReportingTest(testName, host, coop, coep, coopRo,238 coepRo, expectedReports) {239 const executorToken = token();240 const callbackToken = token();241 promise_test(async t => {242 const openee_headers = [243 getReportingEndpointsHeader(host.origin),244 ...getPolicyHeaders(coop, coep, coopRo, coepRo)245 ].map(convertToWPTHeaderPipe);246 const openee_url = host.origin + executor_path +247 openee_headers.join('|') + `&uuid=${executorToken}`;248 window.open(openee_url);249 t.add_cleanup(() => send(executorToken, "window.close()"));250 // Have openee window send a message through dispatcher, once we receive251 // the Ready message from dispatcher it means the openee is fully loaded.252 send(executorToken, `253 send("${callbackToken}", "Ready");254 `);255 let reply = await receive(callbackToken);256 assert_equals(reply, "Ready");257 await wait(1000);258 expectedReports = expectedReports.map(259 (report) => replaceValuesInExpectedReport(report, executorToken));260 return Promise.all(expectedReports.map(261 async ({ endpoint, report: expectedReport }) => {262 await pollReports(endpoint);263 for (let report of endpoint.reports) {264 assert_true(isObjectAsExpected(report, expectedReport),265 `report received for endpoint: ${endpoint.name} ${JSON.stringify(report)} should match ${JSON.stringify(expectedReport)}`);266 }267 assert_equals(endpoint.reports.length, 1, `has exactly one report for ${endpoint.name}`)268 }));269 }, `coop document reporting test ${testName} to ${host.name} with ${coop}, ${coep}, ${coopRo}, ${coepRo}`);270}271// Run an array of reporting tests then verify there's no reports that were not272// expected.273// Tests' elements contain: host, coop, coep, coop-report-only,274// coep-report-only, expectedReports.275// See isObjectAsExpected for explanations regarding the matching behavior.276async function runNavigationReportingTests(testName, tests) {277 await clearReportsOnServer();278 tests.forEach(test => {279 navigationReportingTest(testName, ...test);280 });281 verifyRemainingReports();282}283// Run an array of reporting tests using Reporting-Endpoints header then284// verify there's no reports that were not expected.285// Tests' elements contain: host, coop, coep, coop-report-only,286// coep-report-only, expectedReports.287// See isObjectAsExpected for explanations regarding the matching behavior.288function runNavigationDocumentReportingTests(testName, tests) {289 clearReportsOnServer();290 tests.forEach(test => {291 navigationDocumentReportingTest(testName, ...test);292 });293}294function verifyRemainingReports() {295 promise_test(t => {296 return Promise.all(reportEndpoints.map(async (endpoint) => {297 await pollReports(endpoint);298 assert_equals(endpoint.reports.length, 0, `${endpoint.name} should be empty`);299 }));300 }, "verify remaining reports");301}302const receiveReport = async function(uuid, type) {303 while(true) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.clearReportsOnServer(function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log('Success: ' + data);8 }9});10### getLocations(callback)11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13wpt.getLocations(function(err, data) {14 if (err) {15 console.log('Error: ' + err);16 } else {17 console.log('Success: ' + data);18 }19});20### getTesters(callback)21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23wpt.getTesters(function(err, data) {24 if (err) {25 console.log('Error: ' + err);26 } else {27 console.log('Success: ' + data);28 }29});30### getTestersForLocation(location, callback)31var wpt = require('webpagetest');32var wpt = new WebPageTest('www.webpagetest.org');33wpt.getTestersForLocation('Dulles:Chrome', function(err, data) {34 if (err) {35 console.log('Error: ' + err);36 } else {37 console.log('Success: ' + data);38 }39});40### getTestStatus(testId, callback)41var wpt = require('webpagetest');42var wpt = new WebPageTest('www.webpagetest.org');43wpt.getTestStatus('150411_8R_1d4',

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.clearReportsOnServer(function (err, result) {3 console.log(result);4});5var wpt = require('wpt');6wpt.clearReportsOnServer(options, function (err, result) {7 console.log(result);8});9var wpt = require('wpt');10wpt.clearReportsOnServer(options, function (err, result) {11 console.log(result);12});13var wpt = require('wpt');14wpt.clearReportsOnServer(options, function (err, result) {15 console.log(result);16});17var wpt = require('wpt');18wpt.clearReportsOnServer(options, function (err, result) {19 console.log(result);20});21var wpt = require('wpt');22wpt.clearReportsOnServer(options, function (err, result) {23 console.log(result);24});25var wpt = require('wpt');26wpt.clearReportsOnServer(options, function (err, result) {27 console.log(result);28});29var wpt = require('wpt');30wpt.clearReportsOnServer(options, function (err, result) {31 console.log(result);32});33var wpt = require('wpt');34wpt.clearReportsOnServer(options, function (err, result) {35 console.log(result);36});37var wpt = require('wpt');38wpt.clearReportsOnServer(options, function (err, result) {39 console.log(result);40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.clearReportsOnServer('your_api_key', 'your_server_url', function(err, data){3 if(err){4 console.log(err);5 }6 else{7 console.log(data);8 }9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.clearReportsOnServer('API Key', function(data){3 console.log(data);4});5var wpt = require('wpt');6wpt.clearReportsOnServer('API Key', function(data){7 console.log(data);8});9var wpt = require('wpt');10wpt.getLocations('API Key', function(data){11 console.log(data);12});13var wpt = require('wpt');14wpt.getLocations('API Key', function(data){15 console.log(data);16});17var wpt = require('wpt');18wpt.getLocations('API Key', function(data){19 console.log(data);20});21var wpt = require('wpt');22wpt.getLocations('API Key', function(data){23 console.log(data);24});25var wpt = require('wpt');26wpt.getLocations('API Key', function(data){27 console.log(data);28});29var wpt = require('wpt');30wpt.getLocations('API Key', function(data){31 console.log(data);32});33var wpt = require('wpt');34wpt.getLocations('API Key', function(data){35 console.log(data);36});37var wpt = require('wpt');38wpt.getLocations('API Key', function(data){39 console.log(data);40});41var wpt = require('wpt');42wpt.getLocations('API Key', function(data){43 console.log(data);44});45var wpt = require('w

Full Screen

Using AI Code Generation

copy

Full Screen

1wptApi.clearReportsOnServer('yourTestID', function(err, data) {2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8wptApi.getLocations(function(err, data) {9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14});15wptApi.getTesters('yourTestID', function(err, data) {16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21});22wptApi.getTesters('yourTestID', function(err, data) {23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});29wptApi.getTestStatus('yourTestID', function(err, data) {30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36wptApi.getTestResults('yourTestID', function(err, data) {37 if (err) {38 console.log(err);39 } else {40 console.log(data);41 }42});43wptApi.getTestResults('yourTestID', function(err, data) {44 if (err) {45 console.log(err);46 } else {47 console.log(data);48 }49});50wptApi.getTestResults('yourTestID', function(err, data) {51 if (err) {52 console.log(err);53 } else {54 console.log(data);55 }56});57wptApi.getTestResults('yourTestID', function(err, data) {58 if (err) {59 console.log(err);60 } else

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptClient = require('wpt-client');2wptClient.clearReportsOnServer('Your API Key', function(error, response) {3 if (error) {4 console.log('Error', error);5 } else {6 console.log('Response', response);7 }8});9var wptClient = require('wpt-client');10wptClient.getLocations('Your API Key', function(error, response) {11 if (error) {12 console.log('Error', error);13 } else {14 console.log('Response', response);15 }16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wptAPI');2var wpt = require('wptAPI');3var wpt = require('wptAPI');4var wpt = require('wptAPI');5var wpt = require('wptAPI');6var wpt = require('wptAPI');7var wpt = require('wptAPI');8var wpt = require('wptAPI');

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt 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