How to use clonedRequest method in wpt

Best JavaScript code snippet using wpt

requests.js

Source:requests.js Github

copy

Full Screen

1/* This Source Code Form is subject to the terms of the Mozilla Public2 * License, v. 2.0. If a copy of the MPL was not distributed with this3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */4"use strict";5const I = require("devtools/client/shared/vendor/immutable");6const { getUrlDetails } = require("../utils/request-utils");7const {8 ADD_REQUEST,9 CLEAR_REQUESTS,10 CLONE_SELECTED_REQUEST,11 OPEN_NETWORK_DETAILS,12 REMOVE_SELECTED_CUSTOM_REQUEST,13 SELECT_REQUEST,14 SEND_CUSTOM_REQUEST,15 UPDATE_REQUEST,16} = require("../constants");17const Request = I.Record({18 id: null,19 // Set to true in case of a request that's being edited as part of "edit and resend"20 isCustom: false,21 // Request properties - at the beginning, they are unknown and are gradually filled in22 startedMillis: undefined,23 method: undefined,24 url: undefined,25 urlDetails: undefined,26 remotePort: undefined,27 remoteAddress: undefined,28 isXHR: undefined,29 cause: undefined,30 fromCache: undefined,31 fromServiceWorker: undefined,32 status: undefined,33 statusText: undefined,34 httpVersion: undefined,35 securityState: undefined,36 securityInfo: undefined,37 mimeType: "text/plain",38 contentSize: undefined,39 transferredSize: undefined,40 totalTime: undefined,41 eventTimings: undefined,42 headersSize: undefined,43 // Text value is used for storing custom request query44 // which only appears when user edit the custom requst form45 customQueryValue: undefined,46 requestHeaders: undefined,47 requestHeadersFromUploadStream: undefined,48 requestCookies: undefined,49 requestPostData: undefined,50 responseHeaders: undefined,51 responseCookies: undefined,52 responseContent: undefined,53 responseContentDataUri: undefined,54 formDataSections: undefined,55});56const Requests = I.Record({57 // The collection of requests (keyed by id)58 requests: I.Map(),59 // Selection state60 selectedId: null,61 preselectedId: null,62 // Auxiliary fields to hold requests stats63 firstStartedMillis: +Infinity,64 lastEndedMillis: -Infinity,65});66const UPDATE_PROPS = [67 "method",68 "url",69 "remotePort",70 "remoteAddress",71 "status",72 "statusText",73 "httpVersion",74 "securityState",75 "securityInfo",76 "mimeType",77 "contentSize",78 "transferredSize",79 "totalTime",80 "eventTimings",81 "headersSize",82 "customQueryValue",83 "requestHeaders",84 "requestHeadersFromUploadStream",85 "requestCookies",86 "requestPostData",87 "responseHeaders",88 "responseCookies",89 "responseContent",90 "responseContentDataUri",91 "formDataSections",92];93/**94 * Remove the currently selected custom request.95 */96function closeCustomRequest(state) {97 let { requests, selectedId } = state;98 if (!selectedId) {99 return state;100 }101 let removedRequest = requests.get(selectedId);102 // Only custom requests can be removed103 if (!removedRequest || !removedRequest.isCustom) {104 return state;105 }106 return state.withMutations(st => {107 st.requests = st.requests.delete(selectedId);108 st.selectedId = null;109 });110}111function requestsReducer(state = new Requests(), action) {112 switch (action.type) {113 case ADD_REQUEST: {114 return state.withMutations(st => {115 let newRequest = new Request(Object.assign(116 { id: action.id },117 action.data,118 { urlDetails: getUrlDetails(action.data.url) }119 ));120 st.requests = st.requests.set(newRequest.id, newRequest);121 // Update the started/ended timestamps122 let { startedMillis } = action.data;123 if (startedMillis < st.firstStartedMillis) {124 st.firstStartedMillis = startedMillis;125 }126 if (startedMillis > st.lastEndedMillis) {127 st.lastEndedMillis = startedMillis;128 }129 // Select the request if it was preselected and there is no other selection130 if (st.preselectedId && st.preselectedId === action.id) {131 st.selectedId = st.selectedId || st.preselectedId;132 st.preselectedId = null;133 }134 });135 }136 case UPDATE_REQUEST: {137 let { requests, lastEndedMillis } = state;138 let updatedRequest = requests.get(action.id);139 if (!updatedRequest) {140 return state;141 }142 updatedRequest = updatedRequest.withMutations(request => {143 for (let [key, value] of Object.entries(action.data)) {144 if (!UPDATE_PROPS.includes(key)) {145 continue;146 }147 request[key] = value;148 switch (key) {149 case "url":150 // Compute the additional URL details151 request.urlDetails = getUrlDetails(value);152 break;153 case "totalTime":154 request.endedMillis = request.startedMillis + value;155 lastEndedMillis = Math.max(lastEndedMillis, request.endedMillis);156 break;157 case "requestPostData":158 request.requestHeadersFromUploadStream = {159 headers: [],160 headersSize: 0,161 };162 break;163 }164 }165 });166 return state.withMutations(st => {167 st.requests = requests.set(updatedRequest.id, updatedRequest);168 st.lastEndedMillis = lastEndedMillis;169 });170 }171 case CLEAR_REQUESTS: {172 return new Requests();173 }174 case SELECT_REQUEST: {175 return state.set("selectedId", action.id);176 }177 case CLONE_SELECTED_REQUEST: {178 let { requests, selectedId } = state;179 if (!selectedId) {180 return state;181 }182 let clonedRequest = requests.get(selectedId);183 if (!clonedRequest) {184 return state;185 }186 let newRequest = new Request({187 id: clonedRequest.id + "-clone",188 method: clonedRequest.method,189 url: clonedRequest.url,190 urlDetails: clonedRequest.urlDetails,191 requestHeaders: clonedRequest.requestHeaders,192 requestPostData: clonedRequest.requestPostData,193 isCustom: true194 });195 return state.withMutations(st => {196 st.requests = requests.set(newRequest.id, newRequest);197 st.selectedId = newRequest.id;198 });199 }200 case REMOVE_SELECTED_CUSTOM_REQUEST: {201 return closeCustomRequest(state);202 }203 case SEND_CUSTOM_REQUEST: {204 // When a new request with a given id is added in future, select it immediately.205 // where we know in advance the ID of the request, at a time when it206 // wasn't sent yet.207 return closeCustomRequest(state.set("preselectedId", action.id));208 }209 case OPEN_NETWORK_DETAILS: {210 if (!action.open) {211 return state.set("selectedId", null);212 }213 if (!state.selectedId && !state.requests.isEmpty()) {214 return state.set("selectedId", state.requests.first().id);215 }216 return state;217 }218 default:219 return state;220 }221}222module.exports = {223 Requests,224 requestsReducer,...

Full Screen

Full Screen

search_request.js

Source:search_request.js Github

copy

Full Screen

1/*2 * Licensed to Elasticsearch B.V. under one or more contributor3 * license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright5 * ownership. Elasticsearch B.V. licenses this file to you under6 * the Apache License, Version 2.0 (the "License"); you may7 * not use this file except in compliance with the License.8 * You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */1920import ngMock from 'ng_mock';21import sinon from 'sinon';22import expect from 'expect.js';2324import { SearchRequestProvider } from '../search_request';25import { searchRequestQueue } from '../../../../search_request_queue';2627describe('ui/courier/fetch search request', () => {28 beforeEach(ngMock.module('kibana'));2930 afterEach(() => {31 searchRequestQueue.removeAll();32 });3334 it('throws exception when created without errorHandler', ngMock.inject((Private) => {35 const SearchReq = Private(SearchRequestProvider);3637 let caughtError = false;38 try {39 new SearchReq({ source: {} });40 } catch(error) {41 caughtError = true;42 }43 expect(caughtError).to.be(true);44 }));4546 describe('start', () => {47 it('calls this.source.requestIsStarting(request)', ngMock.inject((Private) => {48 const SearchReq = Private(SearchRequestProvider);4950 const spy = sinon.spy(() => Promise.resolve());51 const source = { requestIsStarting: spy };5253 const req = new SearchReq({ source, errorHandler: () => {} });54 expect(req.start()).to.have.property('then').a('function');55 sinon.assert.calledOnce(spy);56 sinon.assert.calledWithExactly(spy, req);57 }));58 });5960 describe('clone', () => {61 it('returns a search request with identical constructor arguments', ngMock.inject((Private) => {62 const SearchRequest = Private(SearchRequestProvider);6364 const source = {};65 const errorHandler = () => {};66 const defer = {};6768 const originalRequest = new SearchRequest({ source, errorHandler, defer });69 const clonedRequest = originalRequest.clone();7071 expect(clonedRequest).not.to.be(originalRequest);72 expect(clonedRequest.source).to.be(source);73 expect(clonedRequest.errorHandler).to.be(errorHandler);74 expect(clonedRequest.defer).to.be(defer);75 }));7677 }); ...

Full Screen

Full Screen

first.interceptor.ts

Source:first.interceptor.ts Github

copy

Full Screen

1import { Injectable } from '@angular/core';2import {3 HttpRequest,4 HttpHandler,5 HttpEvent,6 HttpInterceptor,7 HttpHeaders8} from '@angular/common/http';9import { Observable, tap } from 'rxjs';10@Injectable()11export class FirstInterceptor implements HttpInterceptor {12 token = "xxxxxxxx";13 intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {14 let clonedRequest = request.clone({15 setHeaders: {Authorization: `Bearer ${this.token}`, Accept: 'json'}16 });17 if(!clonedRequest.headers.has("Content-Type")) {18 clonedRequest = clonedRequest.clone(19 {headers: clonedRequest.headers.set('Content-Type', 'application/json')}20 );21 };22 return next.handle(clonedRequest).pipe(23 tap( (event: HttpEvent<unknown>) => {24 })25 );26 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('webpagetest');10var api = new wpt('www.webpagetest.org');11api.testStatus('140627_0X_1e7c1e1f0da7b2c2d1f2f4c4c2b0f0e1', function(err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18var wpt = require('webpagetest');19var api = new wpt('www.webpagetest.org');20api.getTestResults('140627_0X_1e7c1e1f0da7b2c2d1f2f4c4c2b0f0e1', function(err, data) {21 if (err) {22 console.log(err);23 } else {24 console.log(data);25 }26});27var wpt = require('webpagetest');28var api = new wpt('www.webpagetest.org');29api.getTestResults('140627_0X_1e7c1e1f0da7b2c2d1f2f4c4c2b0f0e1', true, function(err, data) {30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36var wpt = require('webpagetest');37var api = new wpt('www.webpagetest.org');38api.getTestResults('140627_

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt');2var request = require('request');3var url = require('url');4var options = {5 headers: {6 }7};8var newOptions = {9 headers: {10 }11};12var options2 = {13 headers: {14 }15};16var options3 = {17 headers: {18 }19};20var options4 = {21 headers: {22 }23};24var options5 = {25 headers: {26 }27};28var options6 = {29 headers: {30 }31};32var options7 = {33 headers: {34 }35};36var options8 = {37 headers: {38 }39};40var options9 = {41 headers: {42 }43};44var options10 = {45 headers: {46 }47};48var options11 = {49 headers: {50 }51};52var options12 = {53 headers: {54 }55};56var options13 = {57 headers: {58 }59};60var options14 = {61 headers: {62 }63};64var options15 = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org','A.9a8c8d89f1a2c2b2c3d3e3f3f4f4f4f4');3 if (err) return console.error(err);4 api.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data.data.median.firstView.SpeedIndex);7 });8});9### WebPageTest(apiKey, server, options)10### wpt.runTest(url, options, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const wptClient = wpt('www.webpagetest.org', 'A.0c7e7f9d9a2f2dfb0c6b1f1b2c7c8d9f');3}, (err, data) => {4 if (err) {5 console.error(err);6 } else {7 console.log(data);8 }9});10### `runTest(url, options, callback)`

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', 'A.2d5e5a5d0f6b0e7c9b6d9d7c9b6d9c7b');5 if (err) return console.error(err);6 wpt.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10});

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