How to use fetcherUrl method in wpt

Best JavaScript code snippet using wpt

client-test.js

Source:client-test.js Github

copy

Full Screen

1import assert from 'assert';2import typeBundle from '../fixtures/types'; // eslint-disable-line import/no-unresolved3import Client from '../src/client';4import Document from '../src/document';5import Query from '../src/query';6import Mutation from '../src/mutation';7import ClassRegistry from '../src/class-registry';8import GraphModel from '../src/graph-model';9import variable from '../src/variable';10suite('client-test', () => {11 test('it has a type bundle', () => {12 const client = new Client(typeBundle, {url: '/graphql'});13 assert.deepEqual(client.typeBundle, typeBundle);14 });15 test('it builds a client with url and fetcherOptions', () => {16 const client = new Client(typeBundle, {url: '/graphql', fetcherOptions: {mode: 'no-cors'}});17 assert.ok(client instanceof Client);18 });19 test('it builds a client with fetcher', () => {20 function fetcher(url) { return url; }21 const client = new Client(typeBundle, {fetcher});22 assert.ok(client instanceof Client);23 });24 test('it throws an error if both url and fetcher are set', () => {25 function fetcher(url) { return url; }26 function createClient() {27 return new Client(typeBundle, {url: '/graphql', fetcher});28 }29 assert.throws(createClient, Error);30 });31 test('it throws an error if neither url or fetcher are set', () => {32 function createClient() {33 return new Client(typeBundle);34 }35 assert.throws(createClient, Error);36 });37 test('it throws an error if fetcher and fetcherOptions are set', () => {38 function fetcher(url) { return url; }39 function createClient() {40 return new Client(typeBundle, {fetcher, fetcherOptions: {}});41 }42 assert.throws(createClient, Error);43 });44 test('it builds documents', () => {45 const client = new Client(typeBundle, {url: '/graphql'});46 const clientDocument = client.document();47 const expectedDocument = new Document(typeBundle);48 assert.deepEqual(clientDocument, expectedDocument);49 });50 test('it builds queries', () => {51 const client = new Client(typeBundle, {url: '/graphql'});52 const clientQuery = client.query('myQuery', (root) => {53 root.addField('shop', (shop) => {54 shop.addField('name');55 });56 });57 const expectedQuery = new Query(typeBundle, 'myQuery', (root) => {58 root.addField('shop', (shop) => {59 shop.addField('name');60 });61 });62 assert.deepEqual(clientQuery, expectedQuery);63 });64 test('it builds mutations', () => {65 const client = new Client(typeBundle, {url: '/graphql'});66 const input = variable('input', 'ApiCustomerAccessTokenCreateInput!');67 const clientMutation = client.mutation('myMutation', [input], (root) => {68 root.addField('apiCustomerAccessTokenCreate', {args: {input}}, (apiCustomerAccessTokenCreate) => {69 apiCustomerAccessTokenCreate.addField('apiCustomerAccessToken', (apiCustomerAccessToken) => {70 apiCustomerAccessToken.addField('accessToken');71 });72 });73 });74 const expectedMutation = new Mutation(typeBundle, 'myMutation', [input], (root) => {75 root.add('apiCustomerAccessTokenCreate', {args: {input}}, (apiCustomerAccessTokenCreate) => {76 apiCustomerAccessTokenCreate.add('apiCustomerAccessToken', (apiCustomerAccessToken) => {77 apiCustomerAccessToken.add('accessToken');78 });79 });80 });81 assert.deepEqual(clientMutation, expectedMutation);82 });83 test('it sends queries', () => {84 let fetcherGraphQLParams = null;85 let fetcherURL = null;86 function mockFetcher(url) {87 fetcherURL = url;88 return function fetcher(graphQLParams) {89 fetcherGraphQLParams = graphQLParams;90 return Promise.resolve({data: {shop: {name: 'Snowdevil'}}});91 };92 }93 const fetcher = mockFetcher('https://graphql.example.com');94 const mockClient = new Client(typeBundle, {fetcher});95 const query = mockClient.query((root) => {96 root.addField('shop', (shop) => {97 shop.addField('name');98 });99 });100 return mockClient.send(query).then((response) => {101 assert.equal(fetcherURL, 'https://graphql.example.com');102 assert.deepEqual(fetcherGraphQLParams, {query: query.toString()});103 assert.deepEqual(response.data, {shop: {name: 'Snowdevil'}});104 assert.equal(response.model.shop.name, 'Snowdevil');105 assert.ok(response.model instanceof GraphModel);106 });107 });108 test('it sends queries represented as functions', () => {109 let fetcherGraphQLParams = null;110 let fetcherURL = null;111 function mockFetcher(url) {112 fetcherURL = url;113 return function fetcher(graphQLParams) {114 fetcherGraphQLParams = graphQLParams;115 return Promise.resolve({data: {shop: {name: 'Snowdevil'}}});116 };117 }118 const fetcher = mockFetcher('https://graphql.example.com');119 const mockClient = new Client(typeBundle, {fetcher});120 function query(client) {121 const document = client.document();122 document.addQuery((root) => {123 root.addField('shop', (shop) => {124 shop.addField('name');125 });126 });127 return document;128 }129 return mockClient.send(query).then((response) => {130 assert.equal(fetcherURL, 'https://graphql.example.com');131 assert.deepEqual(fetcherGraphQLParams, {query: query(mockClient).toString()});132 assert.deepEqual(response.data, {shop: {name: 'Snowdevil'}});133 assert.equal(response.model.shop.name, 'Snowdevil');134 assert.ok(response.model instanceof GraphModel);135 });136 });137 test('it decodes responses with ClassRegistry', () => {138 class ShopModel extends GraphModel {}139 const classRegistry = new ClassRegistry();140 classRegistry.registerClassForType(ShopModel, 'Shop');141 const mockingClient = new Client(typeBundle, {fetcher: () => {142 return Promise.resolve({data: {shop: {name: 'Snowdevil'}}});143 }, registry: classRegistry});144 const query = mockingClient.query((root) => {145 root.addField('shop', (shop) => {146 shop.addField('name');147 });148 });149 return mockingClient.send(query).then((response) => {150 assert.ok(response.model instanceof GraphModel);151 assert.ok(response.model.shop instanceof ShopModel);152 });153 });154 test('it sends documents', () => {155 let fetcherGraphQLParams = null;156 let fetcherURL = null;157 function mockFetcher(url) {158 fetcherURL = url;159 return function fetcher(graphQLParams) {160 fetcherGraphQLParams = graphQLParams;161 return Promise.resolve({data: {shop: {name: 'Snowdevil'}}});162 };163 }164 const fetcher = mockFetcher('https://graphql.example.com');165 const mockClient = new Client(typeBundle, {fetcher});166 const document = mockClient.document();167 document.addQuery((root) => {168 root.addField('shop', (shop) => {169 shop.addField('name');170 });171 });172 return mockClient.send(document).then((response) => {173 assert.equal(fetcherURL, 'https://graphql.example.com');174 assert.deepEqual(fetcherGraphQLParams, {query: document.toString()});175 assert.deepEqual(response.data, {shop: {name: 'Snowdevil'}});176 assert.equal(response.model.shop.name, 'Snowdevil');177 assert.ok(response.model instanceof GraphModel);178 });179 });180 test('it sends mutations', () => {181 let fetcherGraphQLParams = null;182 let fetcherURL = null;183 function mockFetcher(url) {184 fetcherURL = url;185 return function fetcher(graphQLParams) {186 fetcherGraphQLParams = graphQLParams;187 return Promise.resolve({188 data: {189 apiCustomerAccessTokenCreate: {190 apiCustomerAccessToken: {191 id: 'gid://shopify/ApiCustomerAccessToken/1',192 accessToken: '7bfefea8142a7ec40f694dc8336a8ddb'193 }194 }195 }196 });197 };198 }199 const fetcher = mockFetcher('https://graphql.example.com');200 const mockClient = new Client(typeBundle, {fetcher});201 const input = variable('input', 'ApiCustomerAccessTokenCreateInput!');202 const mutation = mockClient.mutation([input], (root) => {203 root.addField('apiCustomerAccessTokenCreate', {args: {input}}, (apiCustomerAccessTokenCreate) => {204 apiCustomerAccessTokenCreate.addField('apiCustomerAccessToken', (apiCustomerAccessToken) => {205 apiCustomerAccessToken.addField('accessToken');206 });207 });208 });209 return mockClient.send(mutation, {input: {email: 'email@domain.com', password: 'test123'}}).then((response) => {210 assert.equal(fetcherURL, 'https://graphql.example.com');211 assert.deepEqual(fetcherGraphQLParams.query, mutation.toString());212 assert.deepEqual(response.data, {apiCustomerAccessTokenCreate: {apiCustomerAccessToken: {id: 'gid://shopify/ApiCustomerAccessToken/1', accessToken: '7bfefea8142a7ec40f694dc8336a8ddb'}}});213 assert.equal(response.model.apiCustomerAccessTokenCreate.apiCustomerAccessToken.accessToken, '7bfefea8142a7ec40f694dc8336a8ddb');214 assert.ok(response.model instanceof GraphModel);215 });216 });...

Full Screen

Full Screen

chosen_field_collection_test.js

Source:chosen_field_collection_test.js Github

copy

Full Screen

1/* global chai describe afterEach beforeEach before after it */2/* eslint-env module */3import velocity from "velocity";4import Promise from "bluebird";5import ChosenFieldCollectionView6from "btw/semantic_field_editor/views/chosen_field_collection";7import Field from "btw/semantic_field_editor/models/field";8import { SFFetcher } from "btw/semantic-field-fetcher";9import { BoneBreaker, isInViewText } from "testutils/backbone";10import { waitFor } from "testutils/util";11import { Server } from "testutils/server";12// eslint-disable-next-line import/no-extraneous-dependencies13import Bb from "backbone";14import Mn from "marionette";15// eslint-disable-next-line import/no-extraneous-dependencies16import _ from "lodash";17const { assert } = chai;18const ChosenFieldCollection = Bb.Collection.extend({19 Model: Field,20});21const fetcherUrl = "/en-us/semantic-fields/semanticfield/";22const fetcherUrlRe = /^\/en-us\/semantic-fields\/semanticfield\/(.*)$/;23class TestServer extends Server {24 constructor(options) {25 super(_.omit(options, ["fetcherUrl"]));26 this.fetcherUrl = options.fetcherUrl;27 }28 setChangeRecords(changeRecords) {29 this.changeRecords = changeRecords;30 }31 respond(request) {32 super.respond(request);33 // Already responded.34 if (request.status === 200) {35 return;36 }37 // No match.38 if (request.method === "GET" && this.fetcherUrl.test(request.url)) {39 const paths = new URL(request.url, "http://fake/").searchParams40 .get("paths").split(";");41 const response = paths.map(42 path => ({43 path,44 heading: "semantic field foo",45 heading_for_display: "semantic field foo",46 parent: undefined,47 changerecords: this.changeRecords,48 }));49 request.respond(200, { "Content-Type": "application/json" },50 JSON.stringify(response));51 }52 }53}54describe("ChosenFieldCollectionView", () => {55 let view = null;56 let server;57 let renderDiv;58 let breaker;59 // We want to be able to just modify ``keep`` in tests, so.60 // eslint-disable-next-line prefer-const61 let keep = false;62 const verboseServer = false;63 before(() => {64 breaker = new BoneBreaker(Bb, Mn);65 // Make all animations be instantaneous so that we don't spend66 // seconds waiting for them to happen.67 velocity.mock = true;68 server = new TestServer({69 fetcherUrl: fetcherUrlRe,70 verboseServer,71 });72 });73 after(() => {74 breaker.uninstall();75 server.restore();76 velocity.mock = false;77 });78 beforeEach(() => {79 renderDiv = document.createElement("div");80 document.body.appendChild(renderDiv);81 });82 afterEach(() => {83 breaker.neutralize();84 if (!keep) {85 if (view) {86 view.destroy();87 view = null;88 }89 if (renderDiv && renderDiv.parentNode) {90 renderDiv.parentNode.removeChild(renderDiv);91 }92 }93 });94 function makeView(options) {95 const newView = new ChosenFieldCollectionView(options);96 newView.setElement(renderDiv);97 newView.render();98 newView.triggerMethod("show");99 return newView;100 }101 function makeAndWaitForRender(paths, canDelete = true) {102 if (view !== null) {103 throw new Error("overwriting view!");104 }105 const fetcher = new SFFetcher(fetcherUrl, undefined);106 return fetcher.fetch(paths).then((resolved) => {107 // Deliberate leak to global space!108 view = makeView({109 collection: new ChosenFieldCollection(_.values(resolved)),110 fetcher,111 canDelete,112 });113 return Promise.map(paths, path => waitFor(() => isInViewText(view, path)))114 .return(view);115 });116 }117 it("shows the elements passed to it at initialization",118 () => makeAndWaitForRender(["01.01.06.01aj", "01.01.06.01.01aj"]));119 it("deletes a model from the collection on sf:delete from a child",120 () => makeAndWaitForRender(["01.01.06.01aj", "01.01.06.01.01aj"])121 .then(() => {122 assert.equal(view.collection.length, 2);123 const model = view.collection.at(0);124 const childView = view.getChildView("body");125 const modelView = childView.children.findByModel(model);126 modelView.triggerMethod("sf:delete", model);127 assert.equal(view.collection.length, 1);128 assert.isUndefined(view.collection.get(model));129 }));130 it("deletes from the collection the model whose delete button is pressed",131 () => makeAndWaitForRender(["01.01.06.01aj", "01.01.06.01.01aj"])132 .then(() => {133 assert.equal(view.collection.length, 2);134 const model = view.collection.at(0);135 const childView = view.getChildView("body");136 const modelView = childView.children.findByModel(model);137 modelView.ui.deleteButton.click();138 assert.equal(view.collection.length, 1);139 assert.isUndefined(view.collection.get(model));140 }));141 it("does not show a delete button if not requested",142 () => makeAndWaitForRender(["01.01.06.01aj", "01.01.06.01.01aj"], false)143 .then(() => {144 const model = view.collection.at(0);145 const childView = view.getChildView("body");146 const modelView = childView.children.findByModel(model);147 assert.isUndefined(modelView.ui.deleteButton[0]);148 }));149 it("reorders a model when it is dragged and dropped",150 () => makeAndWaitForRender(["01.01.06.01aj", "01.01.06.01.01aj"])151 .then(() => {152 const childView = view.getChildView("body");153 const originalOrder = childView.collection.models.slice();154 const sourceModelView = childView.children.findByIndex(0);155 let ev = new MouseEvent("mousedown", {156 which: 1,157 bubbles: true,158 });159 sourceModelView.el.dispatchEvent(ev);160 const destinationModelView = childView.children.findByIndex(1);161 const destinationRect = destinationModelView.el.getBoundingClientRect();162 const clientX = destinationRect.right - 10;163 const clientY = destinationRect.bottom - 10;164 ev = new MouseEvent("mousemove", {165 bubbles: true,166 clientX,167 clientY,168 });169 destinationModelView.el.dispatchEvent(ev);170 ev = new MouseEvent("mousemove", {171 bubbles: true,172 clientX: clientX + 1,173 clientY: clientY + 1,174 });175 destinationModelView.el.dispatchEvent(ev);176 ev = new MouseEvent("mouseup", {177 which: 1,178 bubbles: true,179 clientX,180 clientY,181 });182 sourceModelView.el.dispatchEvent(ev);183 // We've effectively reversed the elements.184 originalOrder.reverse();185 assert.sameMembers(childView.collection.models, originalOrder);186 }));...

Full Screen

Full Screen

CodeFetcher.ts

Source:CodeFetcher.ts Github

copy

Full Screen

1import axios from 'axios';2const PROTOCAL_PREFIX = "http://";3class CodeFetcher {4 private fetcherUrl : string;5 constructor(url : string, port : number) {6 this.fetcherUrl = PROTOCAL_PREFIX + url + `:${port}`;7 }8 async fetchCode(query : string, nresult : number) : Promise<Array<[string, number]>> {9 return axios({10 method: 'get',11 url: this.fetcherUrl,12 headers: {"query" : query, "nresult" : nresult},13 responseType: 'json',14 responseEncoding: 'utf-8'15 }16 ).then(17 (res) => {18 return res.data;19 }20 );21 }22}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2wpt.fetcherUrl(url, function(data) {3 console.log(data);4});5var fetcherUrl = function(url, callback) {6 var wpt = require('webpagetest');7 var test = wpt('API_KEY');8 test.runTest(url, {9 }, function(err, data) {10 if (err) {11 return console.error(err);12 }13 var testId = data.data.testId;14 test.getTestResults(testId, function(err, data) {15 callback(data);16 });17 });18};19exports.fetcherUrl = fetcherUrl;

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('wpt');2const wpt = new WebPageTest('www.webpagetest.org');3wpt.getTesters(function(err, data) {4 if (err) {5 console.log(err);6 }7 else {8 console.log(data);9 }10});11const wpt = require('wpt');12const wpt = new WebPageTest('www.webpagetest.org');13wpt.getLocations(function(err, data) {14 if (err) {15 console.log(err);16 }17 else {18 console.log(data);19 }20});21const wpt = require('wpt');22const wpt = new WebPageTest('www.webpagetest.org');23wpt.getBrowsers(function(err, data) {24 if (err) {25 console.log(err);26 }27 else {28 console.log(data);29 }30});31const wpt = require('wpt');32const wpt = new WebPageTest('www.webpagetest.org');33wpt.getTesters(function(err, data) {34 if (err) {35 console.log(err);36 }37 else {38 console.log(data);39 }40});41const wpt = require('wpt');42const wpt = new WebPageTest('www.webpagetest.org');43wpt.getTesters(function(err, data) {44 if (err) {45 console.log(err);46 }47 else {48 console.log(data);49 }50});51const wpt = require('wpt');52const wpt = new WebPageTest('www.webpagetest.org');53wpt.getTesters(function(err, data) {54 if (err) {55 console.log(err);56 }57 else {58 console.log(data);59 }60});61const wpt = require('wpt');62const wpt = new WebPageTest('www.webpagetest.org');63wpt.getTesters(function(err, data) {64 if (err) {65 console.log(err);66 }67 else {68 console.log(data);69 }70});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3});4var wpt = require('webpagetest');5var client = wpt('www.webpagetest.org');6});7var wpt = require('webpagetest');8var client = wpt('www.webpagetest.org');9});10var wpt = require('webpagetest');11var client = wpt('www.webpagetest.org');12});13var wpt = require('webpagetest');14var client = wpt('www.webpagetest.org');15});16var wpt = require('webpagetest');17var client = wpt('www.webpagetest.org');18});19var wpt = require('webpagetest');20var client = wpt('www.webpagetest.org');21});

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