Best JavaScript code snippet using wpt
Preview.test.js
Source:Preview.test.js
1// @flow2import React from 'react';3import {observable} from 'mobx';4import {mount, shallow} from 'enzyme';5import ResourceStore from 'sulu-admin-bundle/stores/ResourceStore';6import ResourceFormStore from 'sulu-admin-bundle/containers/Form/stores/ResourceFormStore';7import Router from 'sulu-admin-bundle/services/Router';8import ResourceRequester from 'sulu-admin-bundle/services/ResourceRequester';9import PreviewStore from '../stores/PreviewStore';10import Preview from '../Preview';11window.open = jest.fn().mockReturnValue({addEventListener: jest.fn()});12window.ResizeObserver = jest.fn(function() {13 this.observe = jest.fn();14});15jest.mock('debounce', () => jest.fn((value) => value));16jest.mock('../stores/PreviewStore', () => jest.fn(function() {17 this.start = jest.fn().mockReturnValue(Promise.resolve());18 this.update = jest.fn().mockReturnValue(Promise.resolve());19 this.updateContext = jest.fn().mockReturnValue(Promise.resolve());20 this.stop = jest.fn().mockReturnValue(Promise.resolve());21 this.setWebspace = jest.fn();22 this.setTargetGroup = jest.fn();23 this.renderRoute = '/render';24}));25jest.mock('sulu-admin-bundle/services/Requester', () => ({26 get: jest.fn().mockImplementation((route: string) => new Promise((resolve) => {27 if (route === '/start') {28 resolve({token: '123-123-123'});29 }30 })),31 post: jest.fn().mockReturnValue(Promise.resolve()),32}));33jest.mock('sulu-admin-bundle/containers/Form/stores/ResourceFormStore', () => jest.fn());34jest.mock('sulu-admin-bundle/services/ResourceRequester', () => ({35 getList: jest.fn(),36}));37jest.mock('sulu-admin-bundle/stores/ResourceStore', () => jest.fn());38jest.mock('sulu-page-bundle/stores/webspaceStore', () => ({39 grantedWebspaces: [{key: 'sulu_io'}, {key: 'example'}],40}));41jest.mock('sulu-admin-bundle/services/Router/Router', () => jest.fn(function(history) {42 this.history = history;43 this.attributes = {locale: 'de'};44 this.route = {options: {}};45}));46jest.mock('sulu-admin-bundle/utils', () => ({47 translate: jest.fn((key) => key),48}));49beforeEach(() => {50 jest.resetModules();51 Preview.mode = 'on_request';52 Preview.audienceTargeting = false;53});54test('Render correct preview', () => {55 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});56 const formStore = new ResourceFormStore(resourceStore, 'pages');57 const router = new Router({});58 const preview = mount(<Preview formStore={formStore} router={router} />);59 const startPromise = Promise.resolve();60 const previewStore = preview.instance().previewStore;61 previewStore.start.mockReturnValue(startPromise);62 previewStore.starting = false;63 preview.instance().handleStartClick();64 return startPromise.then(() => {65 preview.update();66 expect(preview.render()).toMatchSnapshot();67 });68});69test('Render correct preview with target groups', () => {70 const targetGroupsPromise = Promise.resolve({_embedded: {target_groups: []}});71 ResourceRequester.getList.mockReturnValue(targetGroupsPromise);72 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});73 const formStore = new ResourceFormStore(resourceStore, 'pages');74 const router = new Router({});75 Preview.audienceTargeting = true;76 const preview = mount(<Preview formStore={formStore} router={router} />);77 const startPromise = Promise.resolve();78 const previewStore = preview.instance().previewStore;79 previewStore.start.mockReturnValue(startPromise);80 previewStore.starting = false;81 preview.instance().handleStartClick();82 return startPromise.then(() => {83 preview.update();84 expect(preview.render()).toMatchSnapshot();85 });86});87test('Render button to start preview', () => {88 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});89 const formStore = new ResourceFormStore(resourceStore, 'pages');90 const router = new Router({});91 const preview = mount(<Preview formStore={formStore} router={router} />);92 expect(preview.render()).toMatchSnapshot();93});94test('Render nothing if separate window is opened and rerender if it is closed', () => {95 const previewWindow = {addEventListener: jest.fn()};96 window.open.mockReturnValue(previewWindow);97 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});98 const formStore = new ResourceFormStore(resourceStore, 'pages');99 const router = new Router({});100 const preview = shallow(<Preview formStore={formStore} router={router} />);101 const startPromise = Promise.resolve();102 const previewStore = preview.instance().previewStore;103 previewStore.start.mockReturnValue(startPromise);104 previewStore.starting = false;105 preview.instance().handleStartClick();106 return startPromise.then(() => {107 expect(preview.render()).toMatchSnapshot();108 preview.find('Button[icon="su-link"]').simulate('click');109 expect(preview.html()).toEqual(null);110 expect(previewWindow.addEventListener).toBeCalledWith('beforeunload', expect.anything());111 previewWindow.addEventListener.mock.calls[0][1]();112 expect(preview.render()).toMatchSnapshot();113 });114});115test('Change css class when selection of device has changed', () => {116 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});117 const formStore = new ResourceFormStore(resourceStore, 'pages');118 const router = new Router({});119 const preview = shallow(<Preview formStore={formStore} router={router} />);120 const startPromise = Promise.resolve();121 const previewStore = preview.instance().previewStore;122 previewStore.start.mockReturnValue(startPromise);123 previewStore.starting = false;124 preview.instance().handleStartClick();125 return startPromise.then(() => {126 expect(preview.find('.auto')).toHaveLength(1);127 expect(preview.find('.desktop')).toHaveLength(0);128 expect(preview.find('.tablet')).toHaveLength(0);129 expect(preview.find('.smartphone')).toHaveLength(0);130 preview.find('Select').at(0).prop('onChange')('tablet');131 expect(preview.find('.auto')).toHaveLength(0);132 expect(preview.find('.desktop')).toHaveLength(0);133 expect(preview.find('.tablet')).toHaveLength(1);134 expect(preview.find('.smartphone')).toHaveLength(0);135 preview.find('Select').at(0).prop('onChange')('desktop');136 expect(preview.find('.auto')).toHaveLength(0);137 expect(preview.find('.desktop')).toHaveLength(1);138 expect(preview.find('.tablet')).toHaveLength(0);139 expect(preview.find('.smartphone')).toHaveLength(0);140 preview.find('Select').at(0).prop('onChange')('smartphone');141 expect(preview.find('.auto')).toHaveLength(0);142 expect(preview.find('.desktop')).toHaveLength(0);143 expect(preview.find('.tablet')).toHaveLength(0);144 expect(preview.find('.smartphone')).toHaveLength(1);145 });146});147test('Change webspace in PreviewStore when selection of webspace has changed', () => {148 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});149 const formStore = new ResourceFormStore(resourceStore, 'pages');150 const router = new Router({});151 const preview = shallow(<Preview formStore={formStore} router={router} />);152 const startPromise = Promise.resolve();153 const previewStore = preview.instance().previewStore;154 previewStore.start.mockReturnValue(startPromise);155 previewStore.starting = false;156 preview.instance().handleStartClick();157 return startPromise.then(() => {158 expect(PreviewStore).toBeCalledWith(undefined, undefined, 'de', 'sulu_io');159 preview.find('Select').at(1).prop('onChange')('example');160 expect(previewStore.setWebspace).toBeCalledWith('example');161 });162});163test('React and update preview when data is changed', () => {164 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});165 const formStore = new ResourceFormStore(resourceStore, 'pages');166 // $FlowFixMe167 formStore.data = observable.map({title: 'Test'});168 // $FlowFixMe169 formStore.loading = false;170 // $FlowFixMe171 formStore.type = observable.box('default');172 const router = new Router({});173 const preview = mount(<Preview formStore={formStore} router={router} />);174 const startPromise = Promise.resolve();175 const updatePromise = Promise.resolve('<h1>Sulu is awesome</h1>');176 const previewStore = preview.instance().previewStore;177 previewStore.start.mockReturnValue(startPromise);178 previewStore.update.mockReturnValue(updatePromise);179 previewStore.starting = false;180 preview.instance().handleStartClick();181 formStore.data.set('title', 'New Test');182 return startPromise.then(() => {183 preview.update();184 expect(previewStore.update).toBeCalledWith({title: 'New Test'});185 expect(preview.render()).toMatchSnapshot();186 });187});188test('React and update preview in external window when data is changed', () => {189 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});190 const formStore = new ResourceFormStore(resourceStore, 'pages');191 const previewWindow = {192 addEventListener: jest.fn(),193 document: {194 close: jest.fn(),195 open: jest.fn(),196 write: jest.fn(),197 },198 };199 window.open.mockReturnValue(previewWindow);200 // $FlowFixMe201 formStore.data = observable.map({title: 'Test'});202 // $FlowFixMe203 formStore.loading = false;204 // $FlowFixMe205 formStore.type = observable.box('default');206 const router = new Router({});207 const preview = mount(<Preview formStore={formStore} router={router} />);208 const startPromise = Promise.resolve();209 const updatePromise = Promise.resolve('<h1>Sulu is awesome</h1>');210 const previewStore = preview.instance().previewStore;211 previewStore.start.mockReturnValue(startPromise);212 previewStore.update.mockReturnValue(updatePromise);213 previewStore.starting = false;214 preview.instance().handleStartClick();215 preview.update();216 preview.find('Button[icon="su-link"]').prop('onClick')();217 preview.update();218 formStore.data.set('title', 'New Test');219 return startPromise.then(() => {220 preview.update();221 expect(previewStore.update).toBeCalledWith({title: 'New Test'});222 expect(preview.render()).toMatchSnapshot();223 expect(previewWindow.document.open).toBeCalledWith();224 expect(previewWindow.document.write).toBeCalledWith('<h1>Sulu is awesome</h1>');225 expect(previewWindow.document.close).toBeCalledWith();226 });227});228test('Dont react or update preview when data is changed during formstore is loading', () => {229 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});230 const formStore = new ResourceFormStore(resourceStore, 'pages');231 // $FlowFixMe232 formStore.data = observable.map({title: 'Test'});233 // $FlowFixMe234 formStore.loading = true;235 // $FlowFixMe236 formStore.type = observable.box('default');237 const router = new Router({});238 const preview = mount(<Preview formStore={formStore} router={router} />);239 const startPromise = Promise.resolve();240 const updatePromise = Promise.resolve('<h1>Sulu is awesome</h1>');241 const previewStore = preview.instance().previewStore;242 previewStore.start.mockReturnValue(startPromise);243 previewStore.update.mockReturnValue(updatePromise);244 previewStore.starting = false;245 preview.instance().handleStartClick();246 formStore.data.set('title', 'New Test');247 return startPromise.then(() => {248 preview.update();249 expect(previewStore.update).not.toBeCalled();250 expect(preview.render()).toMatchSnapshot();251 });252});253test('Dont react or update preview when data is changed during preview-store is starting', () => {254 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});255 const formStore = new ResourceFormStore(resourceStore, 'pages');256 // $FlowFixMe257 formStore.data = observable.map({title: 'Test'});258 // $FlowFixMe259 formStore.loading = false;260 // $FlowFixMe261 formStore.type = observable.box('default');262 const router = new Router({});263 const preview = mount(<Preview formStore={formStore} router={router} />);264 const startPromise = Promise.resolve();265 const updatePromise = Promise.resolve('<h1>Sulu is awesome</h1>');266 const previewStore = preview.instance().previewStore;267 previewStore.start.mockReturnValue(startPromise);268 previewStore.update.mockReturnValue(updatePromise);269 previewStore.starting = true;270 preview.instance().handleStartClick();271 formStore.data.set('title', 'New Test');272 return startPromise.then(() => {273 preview.update();274 expect(previewStore.update).not.toBeCalled();275 expect(preview.render()).toMatchSnapshot();276 });277});278test('React and update-context when type is changed', () => {279 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});280 const formStore = new ResourceFormStore(resourceStore, 'pages');281 // $FlowFixMe282 formStore.data = observable.map({title: 'Test'});283 // $FlowFixMe284 formStore.loading = false;285 // $FlowFixMe286 formStore.type = observable.box('default');287 const router = new Router({});288 const preview = mount(<Preview formStore={formStore} router={router} />);289 const startPromise = Promise.resolve();290 const updateContextPromise = Promise.resolve('<h1>Sulu is awesome</h1>');291 const previewStore = preview.instance().previewStore;292 previewStore.start.mockReturnValue(startPromise);293 previewStore.updateContext.mockReturnValue(updateContextPromise);294 previewStore.starting = false;295 preview.instance().handleStartClick();296 // $FlowFixMe297 formStore.type.set('homepage');298 return startPromise.then(() => {299 expect(previewStore.updateContext).toBeCalledWith('homepage');300 });301});302test('Change target group in PreviewStore when selection of target group has changed', () => {303 const resourceStore = new ResourceStore('pages', 1, {title: 'Test'});304 const formStore = new ResourceFormStore(resourceStore, 'pages');305 const router = new Router({});306 Preview.audienceTargeting = true;307 const preview = shallow(<Preview formStore={formStore} router={router} />);308 const startPromise = Promise.resolve();309 const previewStore = preview.instance().previewStore;310 previewStore.start.mockReturnValue(startPromise);311 previewStore.starting = false;312 preview.instance().handleStartClick();313 return startPromise.then(() => {314 expect(PreviewStore).toBeCalledWith(undefined, undefined, 'de', 'sulu_io');315 preview.find('Select').at(2).prop('onChange')(4);316 expect(previewStore.setTargetGroup).toBeCalledWith(4);317 expect(previewStore.update).toBeCalledWith(undefined);318 });...
sample-test.js
Source:sample-test.js
1const { BigNumber } = require("@ethersproject/bignumber");2const { expect } = require("chai");3const { ethers } = require("hardhat");4describe("Kye", () => {5 let Kye;6 let kye;7 let deployer;8 let accounts;9 let user1;10 let depositAmount;11 before(async () => {12 accounts = await ethers.getSigners();13 deployer = accounts[0];14 user1 = accounts[1];15 Kye = await ethers.getContractFactory("Kye");16 depositAmount = ethers.utils.parseEther("1.0");17 });18 describe("constructor", () => {19 before(async () => {20 kye = await Kye.deploy(ethers.utils.parseEther("1.0"), 7, 10);21 await kye.deployed();22 });23 it("should return depositAmount passed into constructor", async function () {24 expect(await kye.depositAmount()).to.equal(25 ethers.utils.parseEther("1.0")26 );27 });28 it("should return lengthOfRound passed into constructor", async function () {29 expect(await kye.lengthOfRound()).to.equal(7);30 });31 it("should return requiredNumberOfUsers passed into constructor", async function () {32 expect(await kye.requiredNumberOfUsers()).to.equal(10);33 });34 });35 describe("startKye()", () => {36 before(async () => {37 kye = await Kye.deploy(ethers.utils.parseEther("1.0"), 7, 10);38 await kye.deployed();39 });40 describe("when called by non-owner", () => {41 it("should revert if called by non-owner", async function () {42 await expect(kye.connect(user1).startKye()).to.be.revertedWith(43 "Only the contract owner can call this function"44 );45 });46 });47 describe("when called by owner", () => {48 before(async () => {49 const startPromise = await kye.startKye();50 await startPromise.wait();51 });52 it("should set isActive to true", async function () {53 expect(await kye.isActive()).to.equal(true);54 });55 56 it("should set firstRoundInProgress to true", async function () {57 expect(await kye.firstRoundInProgress()).to.equal(true);58 });59 60 it("should set lastDistribution to the current block timestamp", async function () {61 const blockNum = await ethers.provider.getBlockNumber();62 const block = await ethers.provider.getBlock(blockNum);63 const timestamp = block.timestamp;64 65 expect(await kye.lastDistribution()).to.equal(timestamp);66 });67 });68 });69 describe("addUser()", () => {70 before(async () => {71 kye = await Kye.deploy(ethers.utils.parseEther("1.0"), 7, 10);72 await kye.deployed();73 });74 describe("when startKye() has not been called", () => {75 it("should revert", async function () {76 await expect(kye.addUser(user1.address)).to.be.revertedWith(77 "Kye has not started yet"78 );79 });80 });81 describe("when startKye() has been called", () => {82 before(async () => {83 const startPromise = await kye.startKye();84 await startPromise.wait();85 });86 it("should revert if called by non-owner", async function () {87 const newUser = accounts[2];88 await expect(89 kye.connect(user1).addUser(newUser.address)90 ).to.be.revertedWith("Only the contract owner can call this function");91 });92 it("should set isUser for user1 to true", async function () {93 const addUserPromise = await kye.addUser(user1.address);94 await addUserPromise.wait();95 const userStruct = await kye.users(user1.address);96 97 expect(userStruct["isUser"]).to.equal(true);98 });99 100 it("should set hasDeposited for user1 to false", async function () {101 const userStruct = await kye.users(user1.address);102 103 expect(userStruct["hasDeposited"]).to.equal(false);104 });105 106 it("should set hasWon for user1 to false", async function () {107 const userStruct = await kye.users(user1.address);108 109 expect(userStruct["hasWon"]).to.equal(false);110 });111 });112 });113 describe("deposit()", () => {114 before(async () => {115 kye = await Kye.deploy(ethers.utils.parseEther("1.0"), 7, 10);116 await kye.deployed();117 });118 describe("when startKye() has not been called", () => {119 it("should revert if isActive is false", async function () {120 await expect(kye.addUser(user1.address)).to.be.revertedWith(121 "Kye has not started yet"122 );123 });124 });125 describe("when startKye() has been called", () => {126 before(async () => {127 const startPromise = await kye.startKye();128 await startPromise.wait();129 });130 it("should revert if called by non-user", async function () {131 await kye.addUser(user1.address);132 const nonUser = accounts[2];133 134 await expect(135 kye.connect(nonUser).deposit({ value: depositAmount })136 ).to.be.revertedWith("Only a user can call this function");137 });138 describe("when one user has deposited", () => {139 let firstDeposit;140 before(async () => {141 firstDeposit = await kye142 .connect(user1)143 .deposit({ value: depositAmount });144 });145 it("should emit Deposit event", async function () {146 expect(firstDeposit)147 .to.emit(kye, "Deposit")148 .withArgs(user1.address, depositAmount);149 });150 151 it("should add depositAmount to totalPool", async function () {152 expect(await kye.totalPool()).to.equal(depositAmount);153 });154 155 it("should set hasDeposited for user1 to true", async function () {156 const newUser = await kye.users(user1.address);157 158 expect(newUser["hasDeposited"]).to.equal(true);159 });160 161 it("should push user1 address to orderOfDeposits", async function () {162 await kye.users(user1.address);163 164 expect(await kye.orderOfDeposits(0)).to.equal(user1.address);165 });166 });167 describe("when all users have deposited", () => {168 it("should set readyToDistribute to true", async function () {169 for (const a of accounts.slice(2, 11)) {170 await kye.addUser(a.address);171 await kye.connect(a).deposit({ value: depositAmount });172 }173 174 expect(await kye.readyToDistribute()).to.equal(true);175 });176 });177 });178 });179 describe("distributePool()", () => {180 beforeEach(async () => {181 kye = await Kye.deploy(ethers.utils.parseEther("1.0"), 7, 10);182 await kye.deployed();183 const startPromise = await kye.startKye();184 await startPromise.wait();185 for (const a of accounts.slice(1, 11)) {186 const addUserPromise = await kye.addUser(a.address);187 await addUserPromise.wait();188 }189 });190 describe("when not all users have deposited", () => {191 it("should revert if not all users have deposited", async function () {192 expect(kye.connect(user1).distributePool()).to.be.revertedWith(193 "Not all users have deposited"194 );195 });196 });197 describe("when all users have deposited", () => {198 it("should revert if lengthOfRound has not passed since lastDistribution", async function () {199 for (const a of accounts.slice(1, 11)) {200 await kye.connect(a).deposit({ value: depositAmount });201 }202 203 await expect(kye.connect(user1).distributePool()).to.be.revertedWith(204 "Not enough time has passed since last distribution"205 );206 });207 it("should distribute pool", async function () {208 for (const a of accounts.slice(1, 11)) {209 await kye.connect(a).deposit({ value: depositAmount });210 }211 212 await network.provider.send("evm_increaseTime", [604800]);213 await network.provider.send("evm_mine");214 215 const distribution = await kye.connect(user1).distributePool();216 const user1Struct = await kye.users(user1.address);217 expect(user1Struct["hasWon"]).to.equal(true);218 expect(distribution)219 .to.emit(kye, "DistributePool")220 .withArgs(user1.address, BigNumber.from("10").pow(19));221 });222 });223 });...
ParallelsVm.ts
Source:ParallelsVm.ts
1import { exec, spawn, DebugLogger, ExtraSpawnOptions, log } from "builder-util"2import { SpawnOptions, execFileSync, ExecFileOptions } from "child_process"3import { VmManager } from "./vm"4/** @internal */5export async function parseVmList(debugLogger: DebugLogger) {6 // do not log output if debug - it is huge, logged using debugLogger7 let rawList = await exec("prlctl", ["list", "-i", "-s", "name"], undefined, false)8 debugLogger.add("parallels.list", rawList)9 rawList = rawList.substring(rawList.indexOf("ID:"))10 // let match: Array<string> | null11 const result: Array<ParallelsVm> = []12 for (const info of rawList.split("\n\n").map(it => it.trim()).filter(it => it.length > 0)) {13 const vm: any = {}14 for (const line of info.split("\n")) {15 const meta = /^([^:("]+): (.*)$/.exec(line)16 if (meta == null) {17 continue18 }19 const key = meta[1].toLowerCase()20 if (key === "id" || key === "os" || key === "name" || key === "state" || key === "name") {21 vm[key] = meta[2].trim()22 }23 }24 result.push(vm)25 }26 return result27}28/** @internal */29export class ParallelsVmManager extends VmManager {30 private startPromise: Promise<any>31 private isExitHookAdded = false32 constructor(private readonly vm: ParallelsVm) {33 super()34 this.startPromise = this.doStartVm()35 }36 get pathSep(): string {37 return "/"38 }39 private handleExecuteError(error: Error): any {40 if (error.message.includes("Unable to open new session in this virtual machine")) {41 throw new Error(`Please ensure that your are logged in "${this.vm.name}" parallels virtual machine. In the future please do not stop VM, but suspend.\n\n${error.message}`)42 }43 log.warn("ensure that 'Share folders' is set to 'All Disks', see https://goo.gl/E6XphP")44 throw error45 }46 async exec(file: string, args: Array<string>, options?: ExecFileOptions): Promise<string> {47 await this.ensureThatVmStarted()48 // it is important to use "--current-user" to execute command under logged in user - to access certs.49 return await exec("prlctl", ["exec", this.vm.id, "--current-user", file.startsWith("/") ? macPathToParallelsWindows(file) : file].concat(args), options)50 .catch(error => this.handleExecuteError(error))51 }52 async spawn(file: string, args: Array<string>, options?: SpawnOptions, extraOptions?: ExtraSpawnOptions): Promise<any> {53 await this.ensureThatVmStarted()54 return await spawn("prlctl", ["exec", this.vm.id, file].concat(args), options, extraOptions)55 .catch(error => this.handleExecuteError(error))56 }57 private async doStartVm() {58 const vmId = this.vm.id59 const state = this.vm.state60 if (state === "running") {61 return62 }63 if (!this.isExitHookAdded) {64 this.isExitHookAdded = true65 require("async-exit-hook")((callback: (() => void) | null) => {66 const stopArgs = ["suspend", vmId]67 if (callback == null) {68 execFileSync("prlctl", stopArgs)69 }70 else {71 exec("prlctl", stopArgs)72 .then(callback)73 .catch(callback)74 }75 })76 }77 await exec("prlctl", ["start", vmId])78 }79 private ensureThatVmStarted() {80 let startPromise = this.startPromise81 if (startPromise == null) {82 startPromise = this.doStartVm()83 this.startPromise = startPromise84 }85 return startPromise86 }87 toVmFile(file: string): string {88 // https://stackoverflow.com/questions/4742992/cannot-access-network-drive-in-powershell-running-as-administrator89 return macPathToParallelsWindows(file)90 }91}92export function macPathToParallelsWindows(file: string) {93 if (file.startsWith("C:\\")) {94 return file95 }96 return "\\\\Mac\\Host\\" + file.replace(/\//g, "\\")97}98export interface ParallelsVm {99 id: string100 name: string101 os: "win-10" | "ubuntu" | "elementary"102 state: "running" | "suspended" | "stopped"...
Using AI Code Generation
1const wpt = require('webpagetest');2const wptInstance = wpt('www.webpagetest.org');3wptInstance.startPromise({4}).then((data) => {5 console.log(data);6}).catch((err) => {7 console.log(err);8});
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3 if(err) {4 console.log(err);5 } else {6 console.log(data);7 }8});
Using AI Code Generation
1var wpt = require('./lib/webpagetest.js');2var options = {3};4var wpt = new wpt(options);5var runTest = function() {6 wpt.startTest(url, {7 }, function(err, data) {8 if (err) {9 console.log(err);10 } else {11 console.log(data);12 }13 });14};15runTest();
Using AI Code Generation
1const wpt = require('webpagetest');2const wptApi = wpt('www.webpagetest.org', 'A.8f7c6f1b1e9c9d8d1b0c6f9b6d3f3e8d');3wptApi.startPromise({url: 'www.google.com'})4 .then((data) => {5 console.log(data);6 })7 .catch((err) => {8 console.log(err);9 });10const wpt = require('webpagetest');11const wptApi = wpt('www.webpagetest.org', 'A.8f7c6f1b1e9c9d8d1b0c6f9b6d3f3e8d');12wptApi.runTest('www.google.com', (err, data) => {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19const wpt = require('webpagetest');20const wptApi = wpt('www.webpagetest.org', 'A.8f7c6f1b1e9c9d8d1b0c6f9b6d3f3e8d');21wptApi.runTest('www.google.com', (err, data) => {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28const wpt = require('webpagetest');29const wptApi = wpt('www.webpagetest.org', 'A.8f7c6f1b1e9c9d8d1b0c6f9b6d3f3e8d');30wptApi.getLocations((err, data) => {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37const wpt = require('webpagetest');38const wptApi = wpt('www.webpagetest.org', 'A.8f7c
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!!