Best JavaScript code snippet using wpt
scriptmanager.js
Source:scriptmanager.js
...34 (() => new ScriptManager('es6',modelManager)).should.not.be.null;35 });36 it('should support both JavaScript and Ergo scripts', async function() {37 const scriptManager = new ScriptManager('es6',modelManager);38 const script1 = scriptManager.createScript('test.js','.js',jsSample);39 const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);40 scriptManager.addScript(script1);41 scriptManager.addScript(script2);42 scriptManager.getScript('test.js').should.not.be.null;43 scriptManager.getScript('test.ergo').should.not.be.null;44 scriptManager.getScripts().length.should.equal(2);45 scriptManager.getAllScripts().length.should.equal(2);46 scriptManager.getScriptsForTarget('ergo').length.should.equal(1);47 scriptManager.getScriptsForTarget('es5').length.should.equal(1);48 scriptManager.getScriptsForTarget('java').length.should.equal(0);49 (() => scriptManager.hasInit()).should.throw('Function __init was not found in logic');50 (() => scriptManager.hasDispatch()).should.not.throw;51 scriptManager.getLogic().map(x => x.name).should.deep.equal(['test.ergo']);52 scriptManager.allFunctionDeclarations().length.should.equal(2);53 scriptManager.allFunctionDeclarations().map(x => x.getName()).should.deep.equal(['paymentClause','__dispatch']);54 scriptManager.getCompiledScript().getContents().length.should.equal(47864);55 scriptManager.getCompiledJavaScript().length.should.equal(47864);56 scriptManager.allFunctionDeclarations().length.should.equal(152);57 scriptManager.allFunctionDeclarations().filter(x => x.name === '__init').length.should.equal(1);58 expect(scriptManager.hasInit()).to.not.throw;59 expect(scriptManager.hasDispatch()).to.not.throw;60 });61 it('should compile Ergo scripts', async function() {62 const scriptManager = new ScriptManager('es6',modelManager, null, {});63 const script1 = scriptManager.createScript('test.js','.js',jsSample);64 const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);65 scriptManager.addScript(script1);66 scriptManager.addScript(script2);67 scriptManager.compileLogic().getContents().length.should.equal(47864);68 scriptManager.getCompiledScript().getContents().length.should.equal(47864);69 scriptManager.getAllScripts().length.should.equal(3);70 });71 it('should fail to compile an Ergo script with a parse error', async function() {72 const scriptManager = new ScriptManager('es6',modelManager);73 const script1 = scriptManager.createScript('test.js','.js',jsSample);74 const script2 = scriptManager.createScript('test2.ergo','.ergo',ergoSample2);75 scriptManager.addScript(script1);76 scriptManager.addScript(script2);77 (() => scriptManager.compileLogic()).should.throw('Parse error (at file test2.ergo line 33 col 0). ');78 });79 it('should return no compiled script when no Ergo or JS', async function() {80 const scriptManager = new ScriptManager('es6',modelManager);81 scriptManager.getCombinedScripts().should.equal('');82 should.equal(scriptManager.compileLogic(false),null);83 });84 it('should return no combined script when not compiled', async function() {85 const scriptManager = new ScriptManager('es6',modelManager);86 const script2 = scriptManager.createScript('test2.ergo','.ergo',ergoSample2);87 scriptManager.addScript(script2);88 scriptManager.getCombinedScripts().should.equal('');89 });90 it('should fail to compile an Ergo script with an undefined built-in function', async function() {91 const scriptManager = new ScriptManager('es6',modelManager);92 const ergoErr = fs.readFileSync(Path.join(TESTS_DIR,'smoke/builtinErr.ergo'), 'utf8');93 const script1 = scriptManager.createScript('builtinErr.ergo','.ergo',ergoErr);94 scriptManager.addScript(script1);95 (() => scriptManager.compileLogic()).should.throw('System error. [ec2en/function] Function org.accordproject.builtin.foo did not get inlined');96 });97 it('should delete both JavaScript and Ergo scripts if they exist', async function() {98 const scriptManager = new ScriptManager('es6',modelManager);99 const script1 = scriptManager.createScript('test.js','.js',jsSample);100 const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);101 scriptManager.addScript(script1);102 scriptManager.addScript(script2);103 scriptManager.getScript('test.js').should.not.be.null;104 scriptManager.getScript('test.ergo').should.not.be.null;105 scriptManager.deleteScript('test.js');106 scriptManager.deleteScript('test.ergo');107 scriptManager.getScripts().length.should.equal(0);108 });109 it('should fail deleting a script which does not exist', async function() {110 const scriptManager = new ScriptManager('es6',modelManager);111 const script1 = scriptManager.createScript('test.js','.js',jsSample);112 scriptManager.addScript(script1);113 return (() => scriptManager.deleteScript('test.ergo')).should.throw('Script file does not exist');114 });115 it('should clear scripts', async function() {116 const scriptManager = new ScriptManager('es6',modelManager);117 const script1 = scriptManager.createScript('test.js','.js',jsSample);118 const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);119 scriptManager.addScript(script1);120 scriptManager.addScript(script2);121 scriptManager.getScript('test.js').should.not.be.null;122 scriptManager.getScript('test.ergo').should.not.be.null;123 scriptManager.clearScripts();124 });125 it('should get scripts identifiers', async function() {126 const scriptManager = new ScriptManager('es6',modelManager);127 const script1 = scriptManager.createScript('test.js','.js',jsSample);128 const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);129 scriptManager.addScript(script1);130 scriptManager.addScript(script2);131 scriptManager.getScriptIdentifiers().should.deep.equal(['test.js','test.ergo']);132 });133 it('should update script', async function() {134 const scriptManager = new ScriptManager('es6',modelManager);135 const script1 = scriptManager.createScript('test.js','.js',jsSample);136 const script2 = scriptManager.createScript('test.js','.js',jsSample2);137 scriptManager.addScript(script1);138 scriptManager.getScript('test.js').getTokens().length.should.equal(51);139 scriptManager.updateScript(script2);140 scriptManager.getScript('test.js').getTokens().length.should.equal(52);141 });142 it('should fail updating a script which does not exist', async function() {143 const scriptManager = new ScriptManager('es6',modelManager);144 const script1 = scriptManager.createScript('test.js','.js',jsSample);145 const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);146 scriptManager.addScript(script1);147 return (() => scriptManager.updateScript(script2)).should.throw('Script file does not exist');148 });149 it('should modify script', async function() {150 const scriptManager = new ScriptManager('es6',modelManager);151 const script1 = scriptManager.createScript('test.js','.js',jsSample);152 scriptManager.addScript(script1);153 scriptManager.modifyScript('test.js','.js',jsSample2);154 scriptManager.getScript('test.js').getTokens().length.should.equal(52);155 });156 it('clear all scripts', async function() {157 const scriptManager = new ScriptManager('es6',modelManager);158 const script1 = scriptManager.createScript('test.js','.js',jsSample);159 const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);160 scriptManager.addScript(script1);161 scriptManager.addScript(script2);162 scriptManager.compileLogic().getContents().length.should.equal(47864);163 scriptManager.getCompiledJavaScript().length.should.equal(47864);164 scriptManager.clearScripts();165 return (() => scriptManager.getCompiledJavaScript()).should.throw('Did not find any compiled JavaScript logic');166 });167 });...
elasticsearchService.spec.js
Source:elasticsearchService.spec.js
...63 service.add(query, (res) => expect(res).to.be.undefined)64 })65 it('test createScript function() should have defualt script', function () {66 const defualtScript = { lang: "painless", inline: "" }67 const obj = service.createScript()68 expect(obj.script).to.eql(defualtScript)69 })70 describe('createScript function() test', function () {71 let elasticsearch72 let service73 let scriptBuilder74 beforeEach(() => {75 elasticsearch = setElasticsearch()76 service = elasticsearchService(logger, { elasticsearch });77 scriptBuilder = service.createScript();78 })79 it('test createScript function()- return obj with pushToArray:function()', function () {80 const obj = service.createScript()81 expect(typeof (obj.pushToArray)).to.equal('function')82 })83 it('test createScript function()- return obj with popFromArray:function()', function () {84 const obj = service.createScript()85 expect(typeof (obj.popFromArray)).to.equal('function')86 })87 it('test createScript function()- return obj with increment:function()', function () {88 const obj = service.createScript()89 expect(typeof (obj.increment)).to.equal('function')90 })91 it('test createScript function()- return obj with decrement:function()', function () {92 const obj = service.createScript()93 expect(typeof (obj.decrement)).to.equal('function')94 })95 it('pushToArray:function() - should return the object called him', function () {96 const res = scriptBuilder.pushToArray('f', 'v')97 expect(scriptBuilder).to.equal(res)98 })99 it('popFromArray:function() - should return the object called him', function () {100 const res = scriptBuilder.popFromArray('f', 'v')101 expect(scriptBuilder).to.equal(res)102 })103 it('increment:function() - should return the object called him', function () {104 const res = scriptBuilder.increment('f', 'v')105 expect(scriptBuilder).to.equal(res)106 })107 it('decrement:function() - should return the object called him', function () {108 const res = scriptBuilder.decrement('f', 'v')109 expect(scriptBuilder).to.equal(res)110 })111 it(`test pushToArray function() - should add "ctx._source.field.add('value');" to inline property from script,when value is string`, function () {112 scriptBuilder = service.createScript()113 scriptBuilder.pushToArray('field', 'value');114 expect(scriptBuilder.script.inline).to.equal(`ctx._source.field.add('value');`)115 })116 it(`test pushToArray function() - should add "ctx._source.field.add(1);" to inline property from script,when value is number`, function () {117 scriptBuilder = service.createScript()118 scriptBuilder.pushToArray('field', 1);119 expect(scriptBuilder.script.inline).to.equal(`ctx._source.field.add(1);`)120 })121 it(`test popFromArray function() - should add "ctx._source.field.remove(ctx._source.field.indexOf('value'));" to inline property from script,when value is string`, function () {122 scriptBuilder = service.createScript()123 scriptBuilder.popFromArray('field', 'value');124 expect(scriptBuilder.script.inline).to.equal(`ctx._source.field.remove(ctx._source.field.indexOf('value'));`)125 })126 it(`test popFromArray function() - should add "ctx._source.field.remove(ctx._source.field.indexOf(1));" to inline property from script,when value is number`, function () {127 scriptBuilder = service.createScript()128 scriptBuilder.popFromArray('field', 1);129 expect(scriptBuilder.script.inline).to.equal(`ctx._source.field.remove(ctx._source.field.indexOf(1));`)130 })131 it(`test increment function() - should add "ctx._source.field += 'value';" to inline property from script,when value is string`, function () {132 scriptBuilder = service.createScript()133 scriptBuilder.increment('field', 'value');134 expect(scriptBuilder.script.inline).to.equal(`ctx._source.field += 'value';`)135 })136 it(`test increment function() - should add "ctx._source.field += 1;" to inline property from script,when value is number`, function () {137 scriptBuilder = service.createScript()138 scriptBuilder.increment('field', 1);139 expect(scriptBuilder.script.inline).to.equal(`ctx._source.field += 1;`)140 })141 it(`test decrement function() - should add "ctx._source.field -= 'value';" to inline property from script,when value is string`, function () {142 scriptBuilder = service.createScript()143 scriptBuilder.decrement('field', 'value');144 expect(scriptBuilder.script.inline).to.equal(`ctx._source.field -= 'value';`)145 })146 it(`test decrement function() - should add "ctx._source.field -= 1;" to inline property from script,when value is number`, function () {147 scriptBuilder = service.createScript()148 scriptBuilder.decrement('field', 1);149 expect(scriptBuilder.script.inline).to.equal(`ctx._source.field -= 1;`)150 })151 });152});153function setElasticsearch(clientOverride) {154 err = undefined;155 response = {};156 const cOverride = clientOverride || {}157 const client = {158 ping: (options, callback) => callback(undefined),159 create: (query, callback) => callback(err, response),160 update: (query, callback) => callback(err, response),161 get: (query, callback) => callback(err, response),...
npm-hooks.js
Source:npm-hooks.js
...25 prerestart: createScript.bind(undefined, 'prerestart'),26 restart: createScript.bind(undefined, 'restart'),27 postrestart: createScript.bind(undefined, 'postrestart')28};29function createScript(type, script, pathInto, cb) {30 pathInto = path.resolve(pathInto);31 if (typeof pathInto === 'function') {32 cb = pathInto;33 pathInto = path.join('.', 'node_modules');34 }35 var pathSplit = pathInto.split(path.sep);36 var pathNodeModules;37 var pathHook;38 var writeStream;39 if (pathSplit[pathSplit.length - 1] !== 'node_modules') {40 pathInto = path.join(pathInto, 'node_modules');41 }42 createNPMHooksFolder(pathInto, function (err, createdFolder) {43 if (err) {...
JavaScript1.js
Source:JavaScript1.js
1head = document.getElementsByTagName('head').item(0);2CreateLink("../../3rdParty/css/admin.global.css");3CreateLink("../../3rdParty/css/admin.content.css");4CreateLink("../../3rdParty/jBox/Skins/Green/jbox.css");5CreateScript("../../3rdParty/js/jquery-1.4.2.min.js");6CreateScript("../../3rdParty/js/jquery.utils.js");7CreateScript("../../3rdParty/js/admin.js");8CreateScript("../../3rdParty/jBox/jquery.jBox-2.3.min.js");9CreateScript("../../3rdParty/js/jquery.jUploader-1.01.min.js");10CreateScript("../../3rdParty/ueditor/ueditor.config.js");11CreateScript("../../3rdParty/ueditor/ueditor.all.js");12function CreateScript(file) {13 var new_element;14 new_element = document.createElement("script");15 new_element.setAttribute("type", "text/javascript");16 new_element.setAttribute("src", file);17 void (head.appendChild(new_element));18}19function CreateLink(file) {20 var new_element;21 new_element = document.createElement("link");22 new_element.setAttribute("type", "text/css");23 new_element.setAttribute("rel", "stylesheet");24 new_element.setAttribute("href", file);25 void (head.appendChild(new_element));...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.createScript(url, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org');9var options = {10};11wpt.createScript(url, options, function(err, data) {12 if (err) return console.error(err);13 console.log(data);14});15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org');17wpt.getLocations(function(err, data) {18 if (err) return console.error(err);19 console.log(data);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23var options = {24};25wpt.getLocations(options, function(err, data) {26 if (err) return console.error(err);27 console.log(data);28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31wpt.getTesters(function(err, data) {32 if (err) return console.error(err);33 console.log(data);34});35var wpt = require('webpagetest');36var wpt = new WebPageTest('www.webpagetest.org');37var options = {
Using AI Code Generation
1var wpt = require('webpagetest');2var webPageTest = new wpt('www.webpagetest.org');3webPageTest.createScript({4}, function(err, data) {5 if (err) {6 console.error(err);7 } else {8 console.log(data);9 }10});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = WebPageTest('www.webpagetest.org');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('webpagetest');10var wpt = WebPageTest('www.webpagetest.org');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('webpagetest');18var wpt = WebPageTest('www.webpagetest.org');19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('webpagetest');26var wpt = WebPageTest('www.webpagetest.org');27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('webpagetest');34var wpt = WebPageTest('www.webpagetest.org');35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.createScript(testUrl, { location: 'Dulles:Chrome' }, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org');9wpt.createScript(testUrl, { location: 'Dulles:Chrome' }, function(err, data) {10 if (err) return console.error(err);11 console.log(data);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15wpt.createScript(testUrl, { location: 'Dulles:Chrome' }, function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.createScript(testUrl, { location: 'Dulles:Chrome' }, function(err, data) {22 if (err) return console.error(err);23 console.log(data);24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27wpt.createScript(testUrl, { location: 'Dulles:Chrome' }, function(err, data) {28 if (err) return console.error(err);29 console.log(data);30});
Using AI Code Generation
1var script = wpt.createScript("alert('Hello World!');");2script.execute();3var script = wpt.createScript("alert('Hello World!');");4script.execute();5var script = wpt.createScript("alert('Hello World!');");6script.execute();7var script = wpt.createScript("alert('Hello World!');");8script.execute();9var script = wpt.createScript("alert('Hello World!');");10script.execute();11var script = wpt.createScript("alert('Hello World!');");12script.execute();13var script = wpt.createScript("alert('Hello World!');");14script.execute();15var script = wpt.createScript("alert('Hello World!');");16script.execute();17var script = wpt.createScript("alert('Hello World!');");18script.execute();
Using AI Code Generation
1var wptools = require('wptools');2var script = wptools.createScript('test');3script.addLine('var assert = require("assert");');4script.addLine('var wptools = require("wptools");');5script.addLine('assert.equal(1,1);');6script.addLine('console.log("test passed");');7script.save();8var wptools = require('wptools');9var script = wptools.createScript('test');10script.addLine('var assert = require("assert");');11script.addLine('var wptools = require("wptools");');12script.addLine('assert.equal(1,1);');13script.addLine('console.log("test passed");');14script.save();15var wptools = require('wptools');16var script = wptools.createScript('test');17script.addLine('var assert = require("assert");');18script.addLine('var wptools = require("wptools");');19script.addLine('assert.equal(1,1);');20script.addLine('console.log("test passed");');21script.save();22var wptools = require('wptools');23var script = wptools.createScript('test');24script.addLine('var assert = require("assert");');25script.addLine('var wptools = require("wptools");');26script.addLine('assert.equal(1,1);');27script.addLine('console.log("test passed");');28script.save();29var wptools = require('wptools');30var script = wptools.createScript('test');31script.addLine('var assert = require("assert");');32script.addLine('var wptools = require("wptools");');33script.addLine('assert.equal(1,1);');34script.addLine('console.log("test passed
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!!