Best JavaScript code snippet using wpt
server.js
Source:server.js
...144 }145}146/** Login form */147server.get("/login", function (req, res) {148 addLocals( null, function( err, locals) {149 console.log("locals : ", locals);150 locals.error = null;151 locals.login = '';152 locals.title = 'Login | ' + locals.title;153 res.render('login.jade', locals);154 });155});156server.post("/login", function (req, res) {157 var login = req.body.login;158 server.redmine.login(req.body, function(err, isAuth) {159 if (!isAuth) {160 addLocals( null, function( err, locals) {161 locals.error = "Wrong login or password";162 locals.login = login;163 locals.title = 'Login | ' + locals.title;164 res.render('login.jade', locals);165 });166 }167 else {168 req.session.login = req.body.login;169 server.addUser( req.body.login, function( err, data ){170 res.redirect('/');171 });172 /*173 *req.session.login = req.body.login;174 *server.users[req.session.login] = {};175 *server.redmine.connectUser( req.session.login, function(err, data){176 * res.redirect('/');177 *});178 */179 }180 });181});182server.get('/logout', function (req, res) {183 server.redmine.disconnectUser( req.session.login, function(err, data){184 delete server.users[req.session.login];185 req.session.login = null;186 });187 res.redirect('/');188});189server.post("/redmine-key", function (req, res) {190 server.redmine.getUserFromKey(req.body.key, function(err, data) {191 if (err) {192 addLocals( null, function( err, locals) {193 locals.error = "Api Key doesn't exists";194 locals.login = '';195 locals.title = 'Login | ' + locals.title;196 res.render('login.jade', locals);197 });198 }199 else if (!data) {200 addLocals( null, function( err, locals) {201 locals.error = "Api Key already registered";202 locals.login = '';203 locals.title = 'Login | ' + locals.title;204 res.render('login.jade', locals);205 });206 }207 else {208 var user = data.user;209 addLocals( null, function( err, locals) {210 //locals.login = '';211 //locals.title = 'Login | ' + locals.title;212 locals.title = 'Create user | ' + locals.title;213 locals.error = null;214 locals.login = user.mail.split('@')[0];215 locals.firstname = user.firstname;216 locals.lastname = user.lastname;217 locals.apiKey = req.body.key;218 locals.last_login_on = user.last_login_on;219 locals.created_on = user.created_on;220 locals.mail = user.mail;221 locals.id = user.id;222 res.render('create-user.jade', locals);223 });224 }225 });226});227server.post("/create-user", function (req, res) {228 var login = req.body.login;229 var password = req.body.password;230 var confirmPassword = req.body.confirmPassword;231 var firstname = req.body.firstname;232 var lastname = req.body.lastname;233 var last_login_on = req.body.last_login_on;234 var created_on = req.body.created_on;235 var mail = req.body.mail;236 var irc = req.body.irc;237 var id = req.body.id;238 if (password !== confirmPassword) {239 addLocals( req.body, function( err, locals) {240 locals.error = "passwords must match";241 locals.title = 'Create user | ' + locals.title;242 res.render('create-user.jade', locals);243 });244 }245 else {246 delete req.body.confirmPassword;247 server.redmine.createUser(req.body, function(err, user){248 server.redmine.login(req.body, function(err, isAuth) {249 if (!isAuth) {250 addLocals( null, function( err, locals) {251 locals.error = "Wrong login or password";252 locals.login = login;253 locals.title = 'Login | ' + locals.title;254 res.render('login.jade', locals);255 });256 }257 else {258 req.session.login = req.body.login;259 server.addUser( req.body.login, function( err, data ){260 res.redirect('/');261 });262 }263 /*264 *addLocals( null, function( err, locals) {265 * locals.error = null;266 * locals.login = login;267 * locals.title = 'Login | ' + locals.title;268 * res.render('login.jade', locals);269 *});270 */271 });272 });273 }274});275server.post("/update-user", function (req, res) {276 server.redmine.updateUser(req.session.login, req.body, function(err, user){277 res.redirect('/account');278 });279});280server.post("/update-user-password", function (req, res) {281 res.redirect('/account');282});283server.get('/extract', [requireLogin], function(req,res){284 res.render('extract.jade', {285 title : server.host + ':' + server.port + ' | skProject | ' + server.config.clientFramework ,286 description: 'Your Page Description',287 author: 'Your Name',288 analyticssiteid: 'XXXXXXX'289 });290});291server.get('/stats', [requireLogin], function(req,res){292 var requestLogin = req.session.login;293 addLocals( null, function( err, locals ) {294 locals.error = null;295 locals.login = req.session.login;296 locals.title = 'Team | ' + locals.title;297 locals.admin = server.config.server.admin.indexOf(requestLogin) > -1;298 res.render('stats.jade', locals);299 });300 // res.render('stats.jade', {301 // locals : {302 // title : server.host + ':' + server.port + ' | skProject | ' + server.config.clientFramework ,303 // description: 'Your Page Description',304 // author: 'Your Name',305 // analyticssiteid: 'XXXXXXX'306 // }307 // });308});309server.get("/account", [requireLogin], function (req, res) {310 server.redmine.getUserByLogin(req.session.login, function(err, data){311 if (data) {312 addLocals( data, function() {313 data.error = null;314 data.login = req.session.login;315 data.title = 'Account | ' + data.title;316 data.admin = true;317 console.log('data!!!', data);318 res.render('account.jade', data);319 });320 }321 });322});323server.get("/account-password", [requireLogin], function (req, res) {324 server.redmine.getUserByLogin(req.session.login, function(err, data){325 if (data) {326 addLocals( data, function() {327 data.error = null;328 data.login = req.session.login;329 data.title = 'Account | ' + data.title;330 data.admin = true;331 console.log('data!!!', data);332 res.render('password.jade', data);333 });334 }335 });336});337server.get('/', [requireLogin], function(req,res){338 res.sendfile('assets/indexEmber.html');339 /*340 *var requestLogin = req.session.login;341 *addLocals( null, function( err, locals ) {342 * locals.error = null;343 * locals.login = req.session.login;344 * locals.title = 'Team | ' + locals.title;345 * locals.admin = server.config.server.admin.indexOf(requestLogin) > -1;346 * res.render('team-' + server.config.clientFramework + '.jade', {347 * locals : locals348 * });349 *});350 */351});352server.get('/users/:id', [requireLogin], function(req,res){353 server.redmine.getUser(req.params.id, function(err, data){354 res.send({user: data});355 });356});357server.get('/users', [requireLogin], function(req,res){358 server.redmine.getUsers(function(err, users){359 res.send({ users: users });360 /*361 *server.redmine.getIssues(false, function(err, issues){362 * res.send({363 * users: users,364 * issues: issues365 * });366 *});367 */368 });369});370server.get('/issues?:ids', [requireLogin], function(req,res){371 server.redmine.getIssues(req.query.ids, function(err, data){372 res.send({issues: data});373 });374});375server.get('/issues', [requireLogin], function(req,res){376 server.redmine.getIssues(false, function(err, data){377 res.send({issues: data});378 });379});380server.get('/issues/:id', [requireLogin], function(req,res){381 server.redmine.getIssue(req.params.id, function(err, data){382 res.send({issue: data});383 });384});385server.get('/projects?:ids', [requireLogin], function(req,res){386 server.redmine.getProjects(req.query.ids, function(err, data){387 res.send({projects: data});388 });389});390server.get('/projects', [requireLogin], function(req,res){391 server.redmine.getProjects(false, function(err, data){392 res.send({projects: data});393 });394});395server.get('/projects/:id', [requireLogin], function(req,res){396 server.redmine.getProject(req.params.id, function(err, data){397 res.send({project: data});398 });399});400server.get('/statsProject/:id', [requireLogin], function(req,res){401 server.redmine.getStatsProject(req.params.id, function(err, stats){402 res.send(stats);403 });404});405server.get('/statsUser/:type/:ids?', [requireLogin], function(req,res){406 server.redmine.getStatsIssuesByType(req.query.ids, req.params.type, function(err, stats){407 res.send(stats);408 });409});410server.get('/statsUser/:ids?', [requireLogin], function(req,res){411 server.redmine.getAllStatsIssues(req.query.ids, function(err, stats){412 res.send(stats);413 });414});415server.get('/priorities/:id', [requireLogin], function(req,res){416 server.redmine.getPriority(req.params.id, function(err, data){417 res.send({priorities: data});418 });419});420server.get('/statuses/:id', [requireLogin], function(req,res){421 server.redmine.getStatus(req.params.id, function(err, data){422 res.send({statuses: data});423 });424});425server.get('/currentuser/', [requireLogin], function(req,res){426 //var requestLogin = { login: req.session.login };427 //console.log("req.session : ", req.session);428 //console.log("requestLogin : ", requestLogin);429 server.redmine.getUserByLogin(req.session.login, function(err, data){430 //res.send({currentuser: data});431 res.send(data);432 });433});434server.get('/admin', [requireLogin], function(req,res){435 var requestLogin = req.session.login;436 console.log('requestLogin', requestLogin);437 console.log('server.config.server.admin', server.config.server.admin);438 console.log(server.config.server.admin.indexOf(requestLogin > -1));439 if (server.config.server.admin.indexOf(requestLogin) > -1) {440 addLocals( null, function( err, locals) {441 locals.error = "Wrong login or password";442 locals.login = requestLogin;443 locals.title = 'Admin | ' + locals.title;444 locals.admin = true;445 res.render('admin.jade', locals);446 });447 // res.send({448 // pid: process.pid,449 // memory: process.memoryUsage(),450 // uptime: process.uptime(),451 // connections: server.connections452 // });453 }454 else {...
execution-context.spec.ts
Source:execution-context.spec.ts
1import { ExecutionContext, SealedExecutionContext } from '../src/execution-context';2describe('ExecutionContext', () => {3 it('runs an expression with provided locals and element', () => {4 const context = new ExecutionContext(null);5 context.addLocals({ number: 123, string: 'alice' });6 const output = context.run('string + number');7 expect(output).toBe('alice123');8 });9 it('runs an expression multiple timess', () => {10 const context = new ExecutionContext(null);11 context.addLocals({ number: 123 });12 context.run('number + 1');13 context.run('number + 1');14 const output = context.run('number + 1');15 expect(output).toBe(124);16 });17 it('runs an expression in a fork of a context locals and element', () => {18 const parentContext = new ExecutionContext({ thisValue: 'the value is ' });19 parentContext.addLocals({20 number: 123,21 string: 'alice',22 });23 const newContext = parentContext.fork();24 newContext.addLocals({25 number: 456,26 });27 const output = newContext.run('this.thisValue + string + number');28 expect(output).toBe('the value is alice456');29 });30 it('merges the locals from current context, parent and additional values', () => {31 const parentContext = new ExecutionContext({ thisValue: 'the value is ' });32 parentContext.addLocals({33 number: 123,34 string: 'alice',35 });36 const newContext = parentContext.fork();37 newContext.addLocals({38 number: 456,39 });40 const thirdContext = newContext.fork();41 const output = thirdContext.run('number + string', { string: 'bob' });42 expect(output).toBe('456bob');43 });44 it('allows to reset local values', () => {45 const context = new ExecutionContext(null);46 context.addLocals({ number: 123 });47 context.reset();48 expect(() => context.run('number + 1')).toThrow(new ReferenceError('number is not defined'));49 });50});51describe('SealedExecutionContext', () => {52 it('prevents context modifications ', () => {53 const context = new ExecutionContext(null);54 const sealedContext = new SealedExecutionContext(context);55 sealedContext.reset();56 sealedContext.addLocals({ local: true });57 expect(() => sealedContext.run('local')).toThrow(new ReferenceError('local is not defined'));58 });...
Page.js
Source:Page.js
1const BaseStep = require('./BaseStep');2const addLocals = require('../middleware/addLocals');3const { METHOD_NOT_ALLOWED } = require('http-status-codes');4const resolveTemplate = require('../middleware/resolveTemplate');5const { i18NextInstance } = require('../i18n/i18Next');6const { contentProxy } = require('../i18n/contentProxy');7const { defined } = require('../util/checks');8const loadStepContent = require('../middleware/loadStepContent');9const notLocals = [10 '_router',11 'journey',12 'constructor',13 'form',14 'next',15 'locals',16 'middleware',17 'handler',18 'req',19 'res'20];21const allProperties = (obj, arr = []) => {22 const descriptors = Object.getOwnPropertyDescriptors(obj);23 const props = [24 ...Object.keys(descriptors).map(key => {25 return { key, descriptor: descriptors[key] };26 }),27 ...arr28 ];29 if (obj.name === 'BaseStep') {30 return props;31 }32 return allProperties(Object.getPrototypeOf(obj), props);33};34class Page extends BaseStep {35 constructor(...args) {36 super(...args);37 this.content = new Proxy(i18NextInstance, contentProxy(this));38 }39 get middleware() {40 return [41 loadStepContent(this),42 ...super.middleware,43 resolveTemplate,44 addLocals45 ];46 }47 get locals() {48 return allProperties(this)49 .filter(({ key }) => !(notLocals.includes(key)))50 .reduce((obj, { key, descriptor }) => {51 if (typeof descriptor.value === 'function') {52 obj[key] = descriptor.value.bind(this);53 } else if (defined(descriptor.value)) {54 obj[key] = this[key];55 } else if (defined(descriptor.get)) {56 const step = this;57 Object.assign(obj, {58 get [key]() {59 return descriptor.get.call(step);60 }61 });62 }63 return obj;64 }, {});65 }66 get i18n() {67 return this.req.i18n;68 }69 handler(req, res) {70 if (req.method === 'GET') {71 res.render(this.template, this.locals);72 } else {73 res.sendStatus(METHOD_NOT_ALLOWED);74 }75 }76}...
Using AI Code Generation
1var wptool = require('wptool');2var fs = require('fs');3wptool.addLocals('test', 'test2', function(err, data) {4 if (err) {5 throw err;6 }7 console.log(data);8});9### wptool.addLocals (source, destination, callback)10### wptool.removeLocals (source, destination, callback)11### wptool.addLocalsSync (source, destination)12### wptool.removeLocalsSync (source, destination)
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein').get();3page.addLocals(function(err, resp) {4 console.log(resp);5});6{7 "extract": "Albert Einstein (14 March 1879 – 18 April 1955) was a German-born theoretical physicist. He 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.",8 {9 },10 {11 },12 {13 },14 {15 },16 {17 },18 {19 },20 {21 },22 {23 },24 {25 },26 {27 },28 {
Using AI Code Generation
1var wpt = require('webpage-template');2var template = wpt.createTemplate('template.html');3template.addLocals({4});5template.render(function (err, content) {6 if (err) {7 console.log(err);8 } else {9 console.log(content);10 }11});12### `template.addLocals(object)`13### `template.render(callback)`14### `template.renderSync()`15### `wpt.createTemplate(path)`16### `wpt.createTemplateFromString(string)`
Using AI Code Generation
1var wpt = require('webpage-template');2var template = wpt.template('template.html');3template.addLocals({4});5template.on('render', function(html) {6 console.log(html);7});8template.render();9 <h1>Hello {{name}}</h1>10template.on('render', function(html) {11 console.log(html);12});13template.on('error', function(err) {14 console.log(err);15});16### template(path, options)17### template.render(locals, callback)18### template.addLocals(locals)19### template.getLocals()
Using AI Code Generation
1const wptools = require("wptools");2const fs = require("fs");3const page = wptools.page("Wikipedia:WikiProject_Toronto");4page.addLocals().then((data) => {5 console.log(data);6 fs.writeFile("test.json", JSON.stringify(data), (err) => {7 if (err) console.log(err);8 console.log("Successfully Written to File.");9 });10});
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!!