Best JavaScript code snippet using wpt
httpd-proxy-remote.test.ts
Source:httpd-proxy-remote.test.ts
1import { makeReleaseConfig } from "./adl-gen/release";2import JSZip from "jszip";3import fsx from "fs-extra";4import { v4 as uuid } from "uuid";5import path from "path";6import {7 makeToolConfig,8 makeDeployMode,9 ToolConfig,10 makeProxyModeConfig,11 makeEndPoint,12 makeEndPointType,13 makeMachineLabel,14} from "./adl-gen/config";15import axios from "axios";16import {17 TestSetup,18 writeToolConfig,19 setupTest,20 tearDownTest,21 zipAddReleaseJson,22 writeReleaseZip,23 localstack,24 makeReleaseHttpd,25 defaultDeployName,26} from "./testUtils";27import { C2Exec } from "./C2Exec";28import promiseRetry from "promise-retry";29import { makeMaybe } from "./adl-gen/sys/types";30import { makePair } from "./adl-gen/runtime/sys/types";31const testfilePath = "testfile.txt";32/// Release zip of a simple http server33export function makeReleaseHttpdProxyMode(34 setup: TestSetup,35 testfileContents: string36): JSZip {37 return makeReleaseHttpd(38 setup,39 "{{ports.http}}",40 testfilePath,41 testfileContents42 );43}44/// Tool config with proxy mode45function makeConfig(setup: TestSetup): ToolConfig {46 return makeToolConfig({47 ...setup.dataDirs!.config,48 deployMode: makeDeployMode(49 "proxy",50 makeProxyModeConfig({51 endPoints: {52 main: makeEndPoint({53 serverNames: ["main.localhost"],54 etype: makeEndPointType("httpOnly", null),55 }),56 other: makeEndPoint({57 serverNames: ["other.localhost"],58 etype: makeEndPointType("httpOnly", null),59 }),60 },61 remoteStateS3: makeMaybe<string, "just">(62 "just",63 `s3://${localstack.bucket}/${localstack.prefix}/${setup.randomstr}/remotestate`64 ),65 dynamicPortRange: makePair({ v1: 8090, v2: 8099 }),66 slaveLabel: makeMachineLabel("label", "testslave"),67 })68 ),69 });70}71describe(`Run httpd-proxy-remote`, () => {72 const testSetup: TestSetup = {73 randomstr: uuid(),74 dataDirs: null,75 mode: "remote",76 };77 beforeEach(async () => {78 await setupTest(`httpd-proxy-remote`, testSetup);79 });80 afterEach(async () => {81 await tearDownTest(testSetup);82 });83 test("Config and deployment of a httpd server", async () => {84 const releases = [85 {86 releaseName: testSetup.randomstr + "A.zip",87 testcontents: "testcontentsA",88 endpoint: "main",89 },90 {91 releaseName: testSetup.randomstr + "B.zip",92 testcontents: "testcontentsB",93 endpoint: "other",94 },95 ];96 const dataDirs = testSetup.dataDirs!;97 // make several releases:98 for (const rel of releases) {99 await writeReleaseZip(100 testSetup,101 makeReleaseHttpdProxyMode(testSetup, rel.testcontents),102 rel.releaseName103 );104 }105 await writeToolConfig(testSetup, makeConfig(testSetup), "controller");106 await writeToolConfig(testSetup, makeConfig(testSetup), "target");107 const c2controller = new C2Exec(dataDirs, "controller");108 const c2machine = new C2Exec(dataDirs, "target");109 for (const rel of releases) {110 console.log("c2 start release", rel.releaseName);111 await c2controller.start(rel.releaseName);112 await c2controller.connect(rel.endpoint, defaultDeployName(rel.releaseName));113 }114 /// In deployment this happens on target machine periodically115 // for test - just run once after updateing remote config116 await c2machine.slaveUpdate();117 for (const rel of releases) {118 expect(119 await fsx.pathExists(120 path.join(dataDirs.machineOptDeploys, rel.releaseName, "started")121 )122 );123 console.log("http get file test start");124 const res = await promiseRetry(async (retry) => {125 try {126 console.log("try http get file test");127 const res = await axios.get(128 `http://${rel.endpoint}.localhost/${testfilePath}`129 );130 return res;131 } catch (error) {132 console.error("http get file test error, retrying...");133 retry(error);134 }135 });136 expect(res);137 if (res) {138 expect(res.data).toEqual(rel.testcontents);139 }140 }141 console.log("test OK");142 for (const rel of releases) {143 await c2controller!.disconnect(rel.endpoint);144 await c2controller!.stop(defaultDeployName(rel.releaseName));145 }146 await c2machine.slaveUpdate();147 // for test cleanup148 await c2machine.terminate();149 console.log("stopping...");150 });151 test("Config and deployment of multiple deploys of same release", async () => {152 const releaseName = testSetup.randomstr + ".zip"153 const testcontents = "testcontentsA"154 const releases = [155 {156 releaseName,157 testcontents,158 },159 ];160 const deploys = [161 {162 deployName: "deploy1",163 endpoint: "main"164 },165 {166 deployName: "deploy2",167 endpoint: "other"168 },169 ];170 const dataDirs = testSetup.dataDirs!;171 // make several releases:172 for (const rel of releases) {173 await writeReleaseZip(174 testSetup,175 makeReleaseHttpdProxyMode(testSetup, rel.testcontents),176 rel.releaseName177 );178 }179 await writeToolConfig(testSetup, makeConfig(testSetup), "controller");180 await writeToolConfig(testSetup, makeConfig(testSetup), "target");181 const c2controller = new C2Exec(dataDirs, "controller");182 const c2machine = new C2Exec(dataDirs, "target");183 for (const dep of deploys) {184 await c2controller.start(releaseName, dep.deployName);185 await c2machine.connect(dep.endpoint, dep.deployName);186 }187 /// In deployment this happens on target machine periodically188 // for test - just run once after updateing remote config189 await c2machine.slaveUpdate();190 for (const dep of deploys) {191 expect(192 await fsx.pathExists(193 path.join(dataDirs.machineOptDeploys, dep.deployName, "started")194 )195 );196 console.log("http get file test start");197 const res = await promiseRetry(async (retry) => {198 try {199 console.log("try http get file test");200 const res = await axios.get(201 `http://${dep.endpoint}.localhost/${testfilePath}`202 );203 return res;204 } catch (error) {205 console.error("http get file test error, retrying...");206 retry(error);207 }208 });209 expect(res);210 if (res) {211 expect(res.data).toEqual(testcontents);212 }213 }214 console.log("test OK");215 for (const dep of deploys) {216 await c2machine!.disconnect(dep.endpoint);217 await c2machine!.stop(dep.deployName);218 }219 await c2machine.slaveUpdate();220 // for test cleanup221 await c2machine.terminate();222 console.log("stopping...");223 });224});225// problems with testing:226// ports in use...
index.test.js
Source:index.test.js
1const testSetup = require('../__shared__/test-setup');2const fs = require('fs-extra');3const path = require('path');4test('formats babel syntax error', async () => {5 fs.copySync(6 path.join(__dirname, 'src', 'AppBabel.js'),7 path.join(testSetup.testDirectory, 'src', 'App.js')8 );9 const { stdout, stderr } = await testSetup.scripts.build();10 expect({ stdout, stderr }).toMatchSnapshot();11});12test('formats css syntax error', async () => {13 fs.copySync(14 path.join(__dirname, 'src', 'AppCss.js'),15 path.join(testSetup.testDirectory, 'src', 'App.js')16 );17 const { stdout, stderr } = await testSetup.scripts.build();18 expect({ stdout, stderr }).toMatchSnapshot();19});20test('formats unknown export', async () => {21 fs.copySync(22 path.join(__dirname, 'src', 'AppUnknownExport.js'),23 path.join(testSetup.testDirectory, 'src', 'App.js')24 );25 const { stdout, stderr } = await testSetup.scripts.build();26 expect({ stdout, stderr }).toMatchSnapshot();27});28test('formats aliased unknown export', async () => {29 fs.copySync(30 path.join(__dirname, 'src', 'AppAliasUnknownExport.js'),31 path.join(testSetup.testDirectory, 'src', 'App.js')32 );33 const { stdout, stderr } = await testSetup.scripts.build();34 expect({ stdout, stderr }).toMatchSnapshot();35});36test('formats no default export', async () => {37 fs.copySync(38 path.join(__dirname, 'src', 'AppNoDefault.js'),39 path.join(testSetup.testDirectory, 'src', 'App.js')40 );41 const { stdout, stderr } = await testSetup.scripts.build();42 expect({ stdout, stderr }).toMatchSnapshot();43});44test('formats missing package', async () => {45 fs.copySync(46 path.join(__dirname, 'src', 'AppMissingPackage.js'),47 path.join(testSetup.testDirectory, 'src', 'App.js')48 );49 let { stdout, stderr } = await testSetup.scripts.build();50 if (process.platform === 'win32') {51 stderr = stderr.replace('.\\src\\App.js', './src/App.js');52 }53 expect({ stdout, stderr }).toMatchSnapshot();54});55test('formats eslint warning', async () => {56 fs.copySync(57 path.join(__dirname, 'src', 'AppLintWarning.js'),58 path.join(testSetup.testDirectory, 'src', 'App.js')59 );60 let { stdout, stderr } = await testSetup.scripts.build();61 const sizeIndex = stdout.indexOf('File sizes after gzip');62 if (sizeIndex !== -1) {63 stdout = stdout.substring(0, sizeIndex);64 }65 expect({ stdout, stderr }).toMatchSnapshot();66});67test('formats eslint error', async () => {68 fs.copySync(69 path.join(__dirname, 'src', 'AppLintError.js'),70 path.join(testSetup.testDirectory, 'src', 'App.js')71 );72 const { stdout, stderr } = await testSetup.scripts.build();73 expect({ stdout, stderr }).toMatchSnapshot();74});75test('helps when users tries to use sass', async () => {76 fs.copySync(77 path.join(__dirname, 'src', 'AppSass.js'),78 path.join(testSetup.testDirectory, 'src', 'App.js')79 );80 const { stdout, stderr } = await testSetup.scripts.build();81 expect({ stdout, stderr }).toMatchSnapshot();82});83test('formats file not found error', async () => {84 fs.copySync(85 path.join(__dirname, 'src', 'AppUnknownFile.js'),86 path.join(testSetup.testDirectory, 'src', 'App.js')87 );88 let { stdout, stderr } = await testSetup.scripts.build();89 if (process.platform === 'win32') {90 stderr = stderr91 .replace('.\\src\\App.js', './src/App.js')92 .replace('.\\src', './src');93 }94 expect({ stdout, stderr }).toMatchSnapshot();95});96test('formats case sensitive path error', async () => {97 fs.copySync(98 path.join(__dirname, 'src', 'AppIncorrectCase.js'),99 path.join(testSetup.testDirectory, 'src', 'App.js')100 );101 const { stdout, stderr } = await testSetup.scripts.start({ smoke: true });102 if (process.platform === 'darwin') {103 expect(stderr).toMatch(104 `Cannot find file: 'export5.js' does not match the corresponding name on disk: './src/Export5.js'.`105 );106 } else {107 expect(stderr).not.toEqual(''); // TODO: figure out how we can test this on Linux/Windows108 // I believe getting this working requires we tap into enhanced-resolve109 // pipeline, which is debt we don't want to take on right now.110 }111});112test('formats out of scope error', async () => {113 fs.copySync(114 path.join(__dirname, 'src', 'AppOutOfScopeImport.js'),115 path.join(testSetup.testDirectory, 'src', 'App.js')116 );117 let { stdout, stderr } = await testSetup.scripts.build();118 if (process.platform === 'win32') {119 stderr = stderr.replace('.\\src\\App.js', './src/App.js');120 }121 expect({ stdout, stderr }).toMatchSnapshot();...
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.testSetup(function(err, data) {4 if (err) console.log(err);5 else console.log(data);6});7var wpt = require('wpt');8var wpt = new WebPageTest('www.webpagetest.org');9 if (err) console.log(err);10 else console.log(data);11});12var wpt = require('wpt');13var wpt = new WebPageTest('www.webpagetest.org');14 if (err) console.log(err);15 else console.log(data);16});17var wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org');19 if (err) console.log(err);20 else console.log(data);21});22var wpt = require('wpt');23var wpt = new WebPageTest('www.webpagetest.org');24 if (err) console.log(err);25 else console.log(data);26});27var wpt = require('wpt');28var wpt = new WebPageTest('www.webpagetest.org');29 if (err) console.log(err);30 else console.log(data);31});
Using AI Code Generation
1var wpt = require('./wpt.js');2module.exports.testSetup = function(url1, url2) {3 console.log(url1);4 console.log(url2);5};6module.exports = {7 testSetup: function(url1, url2) {8 console.log(url1);9 console.log(url2);10 }11};12var wpt = require(
Using AI Code Generation
1describe('test', function() {2 this.timeout(1000);3 before(wptSetup);4 after(wptTeardown);5 it('should work', function() {6 });7});
Using AI Code Generation
1var wpt = require('./wpt');2var wptTest = new wpt();3wptTest.testSetup('test', 'test', 'test', 'test', 'test');4wptTest.runTest();5var wpt = function() {6 this.testSetup = function() {7 console.log('test');8 }9 this.runTest = function() {10 console.log('run');11 }12}13module.exports = wpt;
Using AI Code Generation
1var wptDriver = require('wptDriver');2var wpt = new wptDriver();3wpt.runTest();4var WptDriver = function(){5 this.testSetup = function(url, testname, location){6 this.url = url;7 this.testname = testname;8 this.location = location;9 }10 this.runTest = function(){11 console.log(this.url);12 console.log(this.testname);13 console.log(this.location);14 }15}16module.exports = WptDriver;
Using AI Code Generation
1wpt.testSetup(function() {2 var test = wpt.createTest("TestName");3 test.run();4});5wpt.testSetup(function() {6 var test = wpt.createTest("TestName");7 test.run();8});9wpt.testSetup(function() {10 var test = wpt.createTest("TestName");11 test.run();12});13wpt.testSetup(function() {14 var test = wpt.createTest("TestName");15 test.run();16});17wpt.testSetup(function() {18 var test = wpt.createTest("TestName");19 test.run();20});21wpt.testSetup(function() {22 var test = wpt.createTest("TestName");23 test.run();24});
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!!