How to use loadPromise method in wpt

Best JavaScript code snippet using wpt

TileLoaderTest.ts

Source:TileLoaderTest.ts Github

copy

Full Screen

1/*2 * Copyright (C) 2019-2021 HERE Europe B.V.3 * Licensed under Apache 2.0, see full license in LICENSE4 * SPDX-License-Identifier: Apache-2.05 */6// Mocha discourages using arrow functions, see https://mochajs.org/#arrow-functions7import { DecodedTile, Geometry, ITileDecoder, TileInfo } from "@here/harp-datasource-protocol";8import {9 Projection,10 TileKey,11 TilingScheme,12 webMercatorProjection,13 webMercatorTilingScheme14} from "@here/harp-geoutils";15import { DataSource, MapView, Statistics, Tile, TileLoaderState } from "@here/harp-mapview";16import { LoggerManager } from "@here/harp-utils";17import * as chai from "chai";18import * as chaiAsPromised from "chai-as-promised";19import * as sinon from "sinon";20import { DataProvider } from "../lib/DataProvider";21import { TileLoader } from "../lib/TileLoader";22chai.use(chaiAsPromised);23// Needed for using expect(...).true for example24const { expect } = chai;25class MockDataSource extends DataSource {26 /** @override */27 getTilingScheme(): TilingScheme {28 return webMercatorTilingScheme;29 }30 /** @override */31 getTile(tileKey: TileKey): Tile | undefined {32 return undefined;33 }34}35class MockDataProvider extends DataProvider {36 async connect() {37 // empty implementation38 }39 ready(): boolean {40 return true;41 }42 async getTile(): Promise<ArrayBufferLike | {}> {43 return await Promise.resolve(new ArrayBuffer(5));44 }45 /** @override */ dispose() {46 // Nothing to be done here.47 }48}49const fakeGeometry = {};50const fakeEmptyGeometry = {51 foo: "bar",52 geometries: [fakeGeometry as Geometry],53 techniques: []54};55class MockTileDecoder implements ITileDecoder {56 async connect() {57 // connect is not used58 }59 dispose() {60 // dispose is not used61 }62 async decodeTile(): Promise<DecodedTile> {63 return await Promise.resolve(fakeEmptyGeometry);64 }65 async getTileInfo(66 _data: ArrayBufferLike,67 _tileKey: TileKey,68 _projection: Projection69 ): Promise<TileInfo | undefined> {70 return await Promise.resolve(undefined);71 }72 configure() {73 // no configuration needed for mock74 }75}76function createMockMapView() {77 return ({78 projection: webMercatorProjection,79 getDataSourceByName() {},80 statistics: new Statistics()81 } as any) as MapView;82}83describe("TileLoader", function () {84 let tileKey: TileKey;85 let mapView: MapView;86 let dataSource: DataSource;87 let dataProvider: MockDataProvider;88 let loggerWasEnabled = true;89 before(function () {90 tileKey = TileKey.fromRowColumnLevel(0, 0, 0);91 mapView = createMockMapView();92 dataSource = new MockDataSource();93 dataSource.attach(mapView);94 const logger = LoggerManager.instance.getLogger("BaseTileLoader");95 if (logger) {96 loggerWasEnabled = logger.enabled;97 logger.enabled = false;98 }99 });100 beforeEach(function () {101 dataProvider = new MockDataProvider();102 });103 after(function () {104 LoggerManager.instance.enable("BaseTileLoader", loggerWasEnabled);105 });106 describe("loadAndDecode()", function () {107 it("should load tiles", function () {108 const tileLoader = new TileLoader(109 dataSource,110 tileKey,111 dataProvider,112 new MockTileDecoder()113 );114 const loadPromise = tileLoader.loadAndDecode();115 expect(loadPromise).to.not.be.undefined;116 return expect(loadPromise).to.eventually.be.fulfilled;117 });118 it("should not reload already requested tile", function () {119 const tileLoader = new TileLoader(120 dataSource,121 tileKey,122 dataProvider,123 new MockTileDecoder()124 );125 const loadPromise = tileLoader.loadAndDecode();126 expect(loadPromise).to.not.be.undefined;127 const secondLoadPromise = tileLoader.loadAndDecode();128 expect(secondLoadPromise).to.not.be.undefined;129 expect(secondLoadPromise).to.equal(loadPromise);130 return expect(loadPromise).to.eventually.be.fulfilled;131 });132 it("should handle empty payloads", function () {133 const tileDecoder = new MockTileDecoder();134 const decodeTileSpy = sinon.spy(tileDecoder, "decodeTile");135 const tileLoader = new TileLoader(dataSource, tileKey, dataProvider, tileDecoder);136 const getTileStub = sinon.stub(dataProvider, "getTile").resolves(new ArrayBuffer(0));137 let loadPromise = tileLoader.loadAndDecode();138 expect(loadPromise).to.not.be.undefined;139 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {140 expect(tileLoader.state).to.equal(TileLoaderState.Ready);141 expect(decodeTileSpy.notCalled).to.be.true;142 getTileStub.resolves({});143 loadPromise = tileLoader.loadAndDecode();144 expect(loadPromise).to.not.be.undefined;145 expect(tileLoader.decodedTile!.geometries.length).eq(0);146 expect(tileLoader.decodedTile?.techniques.length).eq(0);147 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {148 expect(decodeTileSpy.notCalled).to.be.true;149 });150 });151 });152 describe("loadAndDecode()", function () {153 let tileLoader: TileLoader;154 this.beforeEach(() => {155 tileLoader = new TileLoader(156 dataSource,157 tileKey,158 dataProvider,159 new MockTileDecoder()160 );161 LoggerManager.instance.update("TileLoader", { enabled: false });162 });163 this.afterEach(() => {164 LoggerManager.instance.update("TileLoader", { enabled: false });165 });166 it("should recover from losing internet connection", function () {167 // This test writes an error to the console, so we disable it.168 LoggerManager.instance.update("TileLoader", { enabled: false });169 const getTileStub = sinon170 .stub(dataProvider, "getTile")171 .rejects(new Error("No connection."));172 const loadPromise = tileLoader.loadAndDecode();173 expect(loadPromise).to.not.be.undefined;174 // Chai.PromisedAssertion doesn't have .finally unfortunately.175 return expect(loadPromise).to.eventually.be.rejected.then(() => {176 expect(tileLoader.state).to.equal(TileLoaderState.Failed);177 getTileStub.restore();178 const loadPromise = tileLoader.loadAndDecode();179 expect(loadPromise).to.not.be.undefined;180 return expect(loadPromise).to.eventually.be.fulfilled;181 });182 });183 });184 });185 describe("cancel()", function () {186 it("should cancel running requests", function () {187 const tileLoader = new TileLoader(188 dataSource,189 tileKey,190 dataProvider,191 new MockTileDecoder()192 );193 const loadPromise = tileLoader.loadAndDecode();194 expect(loadPromise).to.not.be.undefined;195 tileLoader.cancel();196 expect(tileLoader.state).to.equal(TileLoaderState.Canceled);197 return expect(loadPromise).to.eventually.be.rejected;198 });199 it("should cancel during decoding", function () {200 const tileLoader = new TileLoader(201 dataSource,202 tileKey,203 dataProvider,204 new MockTileDecoder()205 );206 const loadPromise = tileLoader.loadAndDecode();207 expect(loadPromise).to.not.be.undefined;208 // mock loaded data state209 (tileLoader as any).payload = new ArrayBuffer(5);210 tileLoader.state = TileLoaderState.Loaded;211 (tileLoader as any).startDecodeTile();212 tileLoader.cancel();213 expect(tileLoader.state).to.equal(TileLoaderState.Canceled);214 return expect(loadPromise).to.eventually.be.rejected;215 });216 });217 describe("tile load", function () {218 // Note, this test can't be in TileTest.ts because the TileLoader is not part of the219 // @here/harp-mapview package, and trying to add package which contains the TileLoader220 // as a dependency causes a loop which isn't allowed.221 it("tile load sets dependencies from decoded tile", async function () {222 const dependencies: number[] = [0, 1];223 const decodedTile: DecodedTile = {224 techniques: [],225 geometries: [],226 dependencies227 };228 const tileLoader = sinon.createStubInstance(TileLoader);229 tileLoader.decodedTile = decodedTile;230 tileLoader.loadAndDecode.returns(Promise.resolve(TileLoaderState.Ready));231 const tile = new Tile(dataSource, tileKey);232 tile.tileLoader = tileLoader;233 await tile.load();234 expect(tile.dependencies).to.be.deep.eq(235 dependencies.map(morton => TileKey.fromMortonCode(morton))236 );237 });238 });...

Full Screen

Full Screen

WebTileLoaderTest.ts

Source:WebTileLoaderTest.ts Github

copy

Full Screen

1/*2 * Copyright (C) 2020-2021 HERE Europe B.V.3 * Licensed under Apache 2.0, see full license in LICENSE4 * SPDX-License-Identifier: Apache-2.05 */6// Mocha discourages using arrow functions, see https://mochajs.org/#arrow-functions7import { TileKey, webMercatorProjection } from "@here/harp-geoutils";8import { CopyrightInfo, MapView, Tile, TileLoaderState } from "@here/harp-mapview";9import { LoggerManager } from "@here/harp-utils";10import * as chai from "chai";11import * as chaiAsPromised from "chai-as-promised";12import * as sinon from "sinon";13import * as THREE from "three";14import { WebTileDataProvider, WebTileDataSource } from "../lib/WebTileDataSource";15import { WebTileLoader } from "../lib/WebTileLoader";16chai.use(chaiAsPromised);17const { expect } = chai;18describe("WebTileLoader", function () {19 const tileKey: TileKey = TileKey.fromRowColumnLevel(0, 0, 0);20 const mapView = ({21 projection: webMercatorProjection22 } as any) as MapView;23 const texture = new THREE.Texture();24 const copyRightInfo: CopyrightInfo[] = [];25 const renderOrder: number = 42;26 const opacity: number = 1;27 const getTextureStub = sinon.stub();28 const dataProvider: WebTileDataProvider = { getTexture: getTextureStub } as any;29 let dataSource: WebTileDataSource;30 let tile: Tile;31 let loggerWasEnabled = true;32 before(function () {33 const logger = LoggerManager.instance.getLogger("BaseTileLoader");34 if (logger) {35 loggerWasEnabled = logger.enabled;36 logger.enabled = false;37 }38 });39 beforeEach(function () {40 dataSource = new WebTileDataSource({41 dataProvider,42 renderingOptions: {43 opacity,44 renderOrder45 }46 });47 dataSource.attach(mapView);48 tile = new Tile(dataSource, tileKey);49 getTextureStub.resolves([texture, copyRightInfo]);50 });51 after(function () {52 LoggerManager.instance.enable("BaseTileLoader", loggerWasEnabled);53 });54 describe("loadAndDecode()", function () {55 it("should load textured mesh and copyright info", function () {56 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);57 const loadPromise = tileLoader.loadAndDecode();58 expect(loadPromise).to.not.be.undefined;59 expect(tileLoader.isFinished).to.be.false;60 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {61 expect(tileLoader.isFinished).to.be.true;62 expect(tile.shouldDisposeTexture(texture)).to.be.true;63 expect(tile.objects).has.lengthOf(1);64 expect(tile.objects[0]).instanceOf(THREE.Mesh);65 const mesh = tile.objects[0] as THREE.Mesh;66 expect(mesh.renderOrder).equal(renderOrder);67 expect(mesh.material).has.property("map").equal(texture);68 expect(mesh.material).has.property("opacity").equal(opacity);69 expect(tile.copyrightInfo).to.equal(copyRightInfo);70 });71 });72 it("should not enforce blending if data source is fully opaque", function () {73 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);74 const loadPromise = tileLoader.loadAndDecode();75 expect(loadPromise).to.not.be.undefined;76 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {77 expect(tileLoader.isFinished).to.be.true;78 expect(tile.objects).has.lengthOf(1);79 expect(tile.objects[0]).instanceOf(THREE.Mesh);80 const mesh = tile.objects[0] as THREE.Mesh;81 expect(mesh.material).has.property("blending").that.equals(THREE.NormalBlending);82 });83 });84 it("should enable custom blending if data source is transparent", function () {85 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);86 dataSource.opacity = 0.5;87 const loadPromise = tileLoader.loadAndDecode();88 expect(loadPromise).to.not.be.undefined;89 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {90 expect(tileLoader.isFinished).to.be.true;91 expect(tile.objects).has.lengthOf(1);92 expect(tile.objects[0]).instanceOf(THREE.Mesh);93 const mesh = tile.objects[0] as THREE.Mesh;94 expect(mesh.material).has.property("blending").that.equals(THREE.CustomBlending);95 });96 });97 it("should not reload already requested tile", function () {98 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);99 const loadPromise = tileLoader.loadAndDecode();100 expect(loadPromise).to.not.be.undefined;101 const secondLoadPromise = tileLoader.loadAndDecode();102 expect(secondLoadPromise).to.not.be.undefined;103 expect(secondLoadPromise).to.equal(loadPromise);104 return expect(loadPromise).to.eventually.be.fulfilled;105 });106 it("should forceHasGeometry on tile on empty payload", function () {107 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);108 getTextureStub.resolves(undefined);109 const loadPromise = tileLoader.loadAndDecode();110 expect(loadPromise).to.not.be.undefined;111 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {112 expect(tileLoader.isFinished).to.be.true;113 expect(tileLoader.state).to.equal(TileLoaderState.Ready);114 expect(loadPromise).to.not.be.undefined;115 expect(tile.hasGeometry).to.be.true;116 expect(tile.objects).to.be.empty;117 });118 });119 it("should forceHasGeometry on tile on empty texture", function () {120 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);121 getTextureStub.resolves([undefined, []]);122 const loadPromise = tileLoader.loadAndDecode();123 expect(loadPromise).to.not.be.undefined;124 return expect(loadPromise).to.eventually.be.fulfilled.then(() => {125 expect(tileLoader.isFinished).to.be.true;126 expect(tileLoader.state).to.equal(TileLoaderState.Ready);127 expect(loadPromise).to.not.be.undefined;128 expect(tile.hasGeometry).to.be.true;129 expect(tile.objects).to.be.empty;130 });131 });132 it("should finish loading on retry", function () {133 getTextureStub.rejects(new Error("No connection."));134 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);135 const loadPromise = tileLoader.loadAndDecode();136 expect(loadPromise).to.not.be.undefined;137 return expect(loadPromise).to.eventually.be.rejected.then(() => {138 expect(tileLoader.isFinished).to.be.true;139 expect(tileLoader.state).to.equal(TileLoaderState.Failed);140 getTextureStub.resolves([{}, []]);141 const loadPromise = tileLoader.loadAndDecode();142 expect(loadPromise).to.not.be.undefined;143 return expect(loadPromise).to.eventually.be.fulfilled;144 });145 });146 });147 describe("cancel()", function () {148 it("should cancel running requests", function () {149 const tileLoader = new WebTileLoader(dataSource, tile, dataProvider);150 const loadPromise = tileLoader.loadAndDecode();151 expect(loadPromise).to.not.be.undefined;152 tileLoader.cancel();153 expect(tileLoader.state).to.equal(TileLoaderState.Canceled);154 return expect(loadPromise).to.eventually.be.rejected;155 });156 });...

Full Screen

Full Screen

rakuten.js

Source:rakuten.js Github

copy

Full Screen

1const functions = require('firebase-functions');2const puppeteer = require('puppeteer');3const admin = require('firebase-admin');4const config = require('./data.json');5let page, browser;6async function getBrowserPage () {7 const isDebug = process.env.NODE_ENV !== 'production'8 const launchOptions = {9 headless: isDebug ? false : true,10 args: ['--no-sandbox']11 }12 browser = await puppeteer.launch(launchOptions)13 return browser.newPage()14}15exports.pointRakuten = functions.runWith({16 memory: '1GB',17 timeoutSeconds: 260,18})19.region('asia-northeast1')20.pubsub.schedule('every day 12:00')21.timeZone('Asia/Tokyo')22.onRun(async (context) => {23 await runRakuten(context);24});25exports.runRakuten=runRakuten;26async function runRakuten(context){27 if (!page) {28 page = await getBrowserPage();29 }30 // rakuten keiba31 await page.goto('https://bet.keiba.rakuten.co.jp/bank/deposit/');32 await page.type('#loginInner_u', config.rakuten.id);33 await page.type('#loginInner_p', config.rakuten.pw);34 loadPromise = page.waitForNavigation();35 await page.click('[value="ログイン"]');36 await loadPromise;37 await page.type('#depositingInputPrice', "1000");38 loadPromise = page.waitForNavigation();39 await page.click('#depositingInputButton');40 await loadPromise;41 await page.type('[name="pin"]', config.rakutenkeiba.pw);42 loadPromise = page.waitForNavigation();43 await page.click('#depositingConfirmButton');44 await loadPromise;45 // e-shinbun bet46 await page.goto('https://www.e-shinbun.net/account/?ref=ebet&path=http%3A%2F%2Fbet.e-shinbun.net%2F');47 loadPromise = page.waitForNavigation();48 await page.click("[type=image]");49 await loadPromise;50 loadPromise = page.waitForNavigation();51 await page.click("[alt=続ける]");52 await loadPromise;53 loadPromise = page.waitForNavigation();54 await page.click("[alt=入金]");55 await loadPromise;56 await page.type('#StatementAmount', "100");57 loadPromise = page.waitForNavigation();58 await page.click(".std_btn");59 await loadPromise;60 await page.type('#UserPassword', config.eshinbun.pw);61 loadPromise = page.waitForNavigation();62 await page.click('[onclick="hasTransacted();"]');63 await loadPromise;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var webPageTest = new wpt('API_KEY');3var options = {4 videoParams: {5 }6};7 if (err) {8 console.log(err);9 } else {10 console.log(data);11 webPageTest.getTestResults(data.data.testId, function (err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17 });18 }19});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = new wpt('API_KEY');3var options = {4};5test.runTest(options, function(err, data) {6 if (err) return console.error(err);7 test.waitForTestToFinish(data.data.testId, function(err, data) {8 if (err) return console.error(err);9 test.getTestResults(data.data.testId, function(err, data) {10 if (err) return console.error(err);11 console.log(data.data);12 });13 });14});15var wpt = require('webpagetest');16var test = new wpt('API_KEY');17var options = {18};19test.runTest(options, function(err, data) {20 if (err) return console.error(err);21 test.waitForTestToFinish(data.data.testId)22 .then(function(data) {23 return test.getTestResults(data.data.testId);24 })25 .then(function(data) {26 console.log(data.data);27 })28 .catch(function(err) {29 console.error(err);30 });31});32var wpt = require('webpagetest');33var test = new wpt('API_KEY');34var options = {35};36test.runTest(options)37 .then(function(data) {38 return test.waitForTestToFinish(data.data.testId);39 })40 .then(function(data) {41 return test.getTestResults(data.data.testId);42 })43 .then(function(data) {44 console.log(data.data);45 })46 .catch(function(err) {47 console.error(err);48 });49});50var wpt = require('webpagetest');51var test = new wpt('API_KEY');52var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1 .then((result) => {2 console.log(result);3 })4 .catch((error) => {5 console.log(error);6 });

Full Screen

Using AI Code Generation

copy

Full Screen

1 console.log("Page loaded");2});3 console.log("Page loaded");4}).catch(function(err) {5 console.log(err);6});7 console.log("Page loaded");8}).catch(function(err) {9 console.log(err);10}).finally(function() {11 console.log("Done");12});13 console.log("Page loaded");14}).catch(function(err) {15 console.log(err);16}).finally(function() {17 console.log("Done");18}).then(function() {19 console.log("Done");20});21 console.log("Page loaded");22}).catch(function(err) {23 console.log(err);24}).finally(function() {25 console.log("Done");26}).then(function() {27 console.log("Done");28}).catch(function(err) {29 console.log(err);30});31 console.log("Page loaded");32}).catch(function(err) {33 console.log(err);34}).finally(function() {35 console.log("Done");36}).then(function() {37 console.log("Done");38}).catch(function(err) {39 console.log(err);40}).finally(function() {41 console.log("Done");42});43 console.log("Page loaded");44}).catch(function(err) {45 console.log(err);46}).finally(function() {47 console.log("Done");48}).then(function() {49 console.log("Done");50}).catch(function(err) {51 console.log(err);52}).finally(function() {53 console.log("Done");54}).then(function() {55 console.log("Done");56});

Full Screen

Using AI Code Generation

copy

Full Screen

1 });2});3 });4});5 });6});7 });8});9 });10});11 });

Full Screen

Using AI Code Generation

copy

Full Screen

1function loadPromise(url){2 return new Promise(function(resolve, reject){3 window.addEventListener('load', function(){4 resolve();5 });6 });7}8loadPromise(url).then(function(){9 console.log('page loaded');10});11function loadPromise(url){12 return new Promise(function(resolve, reject){13 window.addEventListener('load', function(){14 resolve();15 });16 });17}18loadPromise(url).then(function(){19 console.log('page loaded');20});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2const fs = require('fs');3wptools.loadPromise('Albert Einstein').then(page => {4 const json = page.data;5 fs.writeFileSync('output.json', JSON.stringify(json, null, 2));6});7{8 "extract": "Albert Einstein (14 March 1879 – 18 April 1955) was a German-born theoretical physicist who developed the theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics). Einstein's work is also known for its influence on the philosophy of science. Einstein is best known in popular culture for his mass–energy equivalence formula E = mc2 (which has been dubbed \"the world's most famous equation\"). He received the 1921 Nobel Prize in Physics \"for his services to theoretical physics, and especially for his discovery of the law of the photoelectric effect\", a pivotal step in the development of quantum theory.",9 {10 }11 "pageterms": {12 },13 "thumbnail": {14 },15 "originalimage": {16 },17 {

Full Screen

Using AI Code Generation

copy

Full Screen

1 console.log(response);2});3 console.log(response);4});5 console.log(response);6});7 console.log(response);8});9 console.log(response);10});11 console.log(response);12});13 console.log(response);14});15 console.log(response);16});17 console.log(response);18});19 console.log(response);20});21 console.log(response);22});23 console.log(response);24});25loadPromise("

Full Screen

Using AI Code Generation

copy

Full Screen

1 .then(function(page) {2 var status = page.getStatus();3 var metrics = page.getMetrics();4 var screenshot = page.getScreenshot();5 })6 .catch(function(error) {7 var message = error.getMessage();8 });

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