Best JavaScript code snippet using appium-base-driver
auth.js
Source:auth.js
...13 'email': 'test@example.com',14 'password': '12345'15 },16 user, configureServer;17configureServer = function configureServer( options ) {18 var opts = options || {};19 auth.options( opts )20 .server();21};22suite( 'auth()', function () {23 suiteSetup( function ( done ) {24 return mongoose25 .connectAsync( 'mongodb://localhost/nlmg_test' )26 .then( function () {27 // hash a pw and create a user (assume it works)28 // really this should be stubbed... but i'm tired :(29 auth.hashPassword( usr.password )30 .then( function ( hash ) {31 // create a Test User32 return User.createAsync({33 'firstName': usr.firstName,34 'lastName': usr.lastName,35 'email': usr.email,36 'password': hash37 });38 })39 .then( function ( userModel ) {40 user = userModel;41 done();42 });43 });44 });45 // setup( function ( done ){done();});46 // teardown( function ( done ){done();});47 suiteTeardown( function ( done ) {48 return mongoose49 .connection50 .db51 .executeDbCommand({52 dropDatabase: 153 },54 function( err , result ) {55 return mongoose.connection.close( done );56 });57 });58 test( 'inherits from event emitter', function ( done ) {59 assert.instanceOf( auth, EventEmitter, 'auth module is instance of EventEmitter' );60 done();61 });62 test( 'does not configure server more than once', function ( done ) {63 var spy = sinon.spy( auth , 'configureServer' ),64 opts = {65 userModel: User,66 accessTokenModel: AccessToken67 };68 // initial call69 configureServer( opts );70 // testing second call71 configureServer( opts );72 assert.equal( spy.callCount , 1 , 'Configure method called only once' );73 auth.configureServer.restore();74 done();75 });76 test( 'throws error if no AccessToken Model supplied', function ( done ) {77 configureServer();78 assert.throws( auth.createToken.bind( this ) , Error , 'AccessToken model must be provided to the auth module.' );79 done();80 });81 test( 'creates token', function ( done ) {82 var client = {83 'id': '9876543210'84 },85 opts = {86 userModel: User,87 accessTokenModel: AccessToken88 };89 configureServer( opts );90 auth.createToken( client , usr , null )91 .then( function ( token ) {92 return AccessToken.findOneAsync({93 'userId': usr._id94 });95 })96 .then( function ( tokenModel ) {97 assert.equal( tokenModel.userId.toString() , usr._id.toString() , 'Token UserId Matches User\'s Id' );98 AccessToken99 .count({100 'userId': usr._id101 },102 function ( err , count ) {103 assert.notEqual( count , 0 , 'Token count is not 0' );104 assert.equal( count , 1 , 'Token count is 1' );105 done();106 }107 );108 })109 .catch( function ( err ) {110 console.log( err , '??!?' );111 assert.ok( false , 'Error creating token' );112 done();113 });114 });115 test( 'exchanges password for token' , function ( done ) {116 var client = {117 id: 'Shoptology.wut.wut'118 },119 opts = {120 userModel: User,121 accessTokenModel: AccessToken122 };123 configureServer( opts );124 auth.exchangePassword( client , usr.email , usr.password , null )125 .then( function ( token ) {126 assert.isDefined( token , 'Token was exchanged' );127 done();128 });129 });130 test( 'does not exchanges password for token when user not found' , function ( done ) {131 var client = {132 id: 'Shoptology.wut.wut'133 },134 opts = {135 userModel: User,136 accessTokenModel: AccessToken137 };138 configureServer( opts );139 auth.exchangePassword( client , 'foo' , 'foo' , null )140 .then( function ( token ) {141 assert.isUndefined( token , 'Token was not exchanged' );142 })143 .catch( function ( e ) {144 assert.equal( e.message , 'A user was not found with the given username/password.' );145 done();146 });147 });148 test( 'hashPassword' , function ( done ) {149 var t = auth.hashPassword( usr.password )150 .then( function ( hash ) {151 assert.instanceOf( t , Promises , 'Method is a Promise' );152 assert.isDefined( hash , 'hashPassword hashes password' );...
vite-launch.js
Source:vite-launch.js
1/**2 * å¯å¨vite3 */4const vscode = require("vscode");5// const exec = require("child_process").exec;6const vite = require("vite");7const open = require("open");8const fs = require("fs");9const path = require("path");10let relativePath = "/index.html";11let server = null;12module.exports = function (context) {13 context.subscriptions.push(14 vscode.commands.registerCommand(15 "extension.vite.viteLaunch",16 async function (uri) {17 // å·¥ç¨ç®å½18 const workspaceFolder = vscode.workspace.workspaceFolders[0];19 const root = workspaceFolder.uri.fsPath;20 // const root = "D:\\llbt\\ant-design-pro-vue";21 if (uri) {22 relativePath = uri.fsPath.substring(root.length);23 }24 const options = {25 root: root,26 port: 3000,27 };28 // 读åé
ç½®æ件29 // const userConfig = await vite.resolveConfig('development', root)30 // if (Array.isArray(userConfig.configureServer)) {31 // userConfig.configureServer.unshift(myPlugin)32 // } else if (userConfig.configureServer) {33 // userConfig.configureServer = [myPlugin, userConfig.configureServer]34 // } else {35 // userConfig.configureServer = [myPlugin]36 // }37 const userConfig = {38 configureServer: [myPlugin],39 root,40 port: 5550,41 relativePath,42 };43 // userConfig.configureServer = [myPlugin];44 // userConfig.root = root;45 // userConfig.port = 5550;46 if (!server || !server.listening) {47 server = runServe(userConfig);48 }49 statusBarItem.text = `$(debug-pause) vite: ${userConfig.port}`;50 statusBarItem.command = "extension.vite.viteClose";51 if (relativePath.endsWith(".js") || relativePath.endsWith(".vue")) {52 open(`http://localhost:${userConfig.port}/index.html`);53 } else {54 open(`http://localhost:${userConfig.port}${relativePath}`);55 }56 }57 )58 );59 context.subscriptions.push(60 vscode.commands.registerCommand("extension.vite.viteClose", function () {61 statusBarItem.text = `closing`;62 statusBarItem.command = null;63 server &&64 server.close(() => {65 vscode.window.showInformationMessage("vite is closed");66 statusBarItem.text = `$(debug-start) vite `;67 statusBarItem.command = "extension.vite.viteLaunch";68 });69 })70 );71 const statusBarItem = vscode.window.createStatusBarItem(72 vscode.StatusBarAlignment.Left,73 10074 );75 statusBarItem.text = `$(debug-start) vite`;76 statusBarItem.command = "extension.vite.viteLaunch";77 context.subscriptions.push(statusBarItem);78 statusBarItem.show();79};80function runServe(options) {81 const server = vite.createServer(options);82 let port = options.port || 3000;83 server.on("error", (e) => {84 // @ts-ignore85 if (e.code === "EADDRINUSE") {86 console.log(`Port ${port} is in use, trying another one...`);87 setTimeout(() => {88 server.close();89 server.listen(++port);90 }, 100);91 } else {92 console.error(e);93 }94 });95 server.listen(port, () => {96 console.log(`Dev server running at: ${port}`);97 });98 return server;99}100const myPlugin = (ctx) => {101 const app = ctx.app;102 if (relativePath.endsWith(".js")) {103 app.use((context, next) => {104 const {105 request: { url, query },106 } = context;107 if (url == "/" || url == "/index.html") {108 const p = path.resolve(__dirname, "./index.html");109 let content = fs.readFileSync(p, "utf-8");110 const newContent = content.replace("./src/main.js", relativePath);111 context.body = newContent;112 }113 next();114 });115 } else if (relativePath.endsWith(".vue")) {116 app.use((context, next) => {117 const {118 request: { url, query },119 } = context;120 if (url == "/" || url == "/index.html") {121 const p = path.resolve(__dirname, "./index.html");122 let content = fs.readFileSync(p, "utf-8");123 context.body = content;124 } else if (url == "/src/main.js") {125 const p = path.resolve(__dirname, "./main.js");126 let content = fs.readFileSync(p, "utf-8");127 const newContent = content.replace(128 "./App.vue",129 "/" + relativePath.substr(1)130 );131 context.type = "application/javascript";132 context.body = newContent;133 return;134 }135 next();136 });137 }...
server-specs.js
Source:server-specs.js
...42describe('server configuration', function () {43 it('should actually use the middleware', function () {44 const app = fakeApp();45 const configureRoutes = () => {};46 configureServer({app, addRoutes: configureRoutes});47 app.use.callCount.should.equal(14);48 app.all.callCount.should.equal(4);49 });50 it('should apply new methods in plugins to the standard method map', function () {51 const app1 = fakeApp();52 const app2 = fakeApp();53 const driver = fakeDriver();54 const addRoutes = routeConfiguringFunction(driver);55 configureServer({app: app1, addRoutes});56 configureServer({app: app2, addRoutes, plugins: [fakePlugin()]});57 app2.totalCount().should.eql(app1.totalCount() + 2);58 });59 it('should silently reject new methods in plugins if not plain objects', function () {60 const app1 = fakeApp();61 const app2 = fakeApp();62 const driver = fakeDriver();63 const addRoutes = routeConfiguringFunction(driver);64 const plugin = fakePlugin();65 plugin.newMethodMap = [];66 configureServer({app: app1, addRoutes});67 configureServer({app: app2, addRoutes, plugins: [plugin]});68 app2.totalCount().should.eql(app1.totalCount());69 });70 it('should allow plugins to update the server', async function () {71 const plugins = [fakePlugin()];72 const driver = fakeDriver();73 const _server = await server({74 routeConfiguringFunction: routeConfiguringFunction(driver),75 port: 8181,76 plugins,77 });78 try {79 _server.updated.should.be.true;80 } finally {81 await _server.close();...
todoco-init.js
Source:todoco-init.js
1const inquirer = require('inquirer');2const writeConfig = require('./src/config/write-config');3let questions = [4 {5 name: 'project.name',6 type: 'input',7 message: 'What is the name of your project'8 },9 {10 name: 'files.useGitignore',11 type: 'confirm',12 default: true,13 message: 'Do you want to use the .gitignore file to set ignored files?'14 },15 {16 name: 'configureServer',17 type: 'confirm',18 default: false,19 message: 'Do you wish to configure a ToDoCo Server connection?'20 },21 {22 when: response => response.configureServer,23 name: 'server.hostname',24 type: 'input',25 default: 'localhost',26 message: 'Hostname'27 },28 {29 when: response => response.configureServer,30 name: 'server.port',31 type: 'input',32 default: '80',33 message: 'Port',34 validate: value => isFinite(value)35 },36 {37 when: response => response.configureServer,38 name: 'server.username',39 type: 'input',40 message: 'Username'41 },42 {43 when: response => response.configureServer,44 name: 'server.password',45 type: 'password',46 message: 'Password'47 }48];49inquirer50 .prompt(questions)...
index.js
Source:index.js
...17 final = _updateWebpackConfig(final, env)18 }19 return final20 },21 configureServer(app, env) {22 configureServer(app, env)23 if (_configureServer) {24 _configureServer(app, env)25 }26 },27 })28}...
route_specs.js
Source:route_specs.js
...5}6from 'chai';7describe('route_table', () => {8 before(() => {9 return configureServer();10 });11 it('routes /js to file system', function () {12 return configureServer().then(function (server) {13 return server.match('get', '/js/some_file.js');14 }).then(function (route) {15 expect(route.path).to.eql('/js/{param*}');16 });17 });18 it('routes /img to file system', function () {19 return configureServer().then(function (server) {20 return server.match('get', '/img/some_file.js');21 }).then(function (route) {22 expect(route.path).to.eql('/img/{param*}');23 });24 });...
index.mjs
Source:index.mjs
...9 name: 'favicons',10 async configResolved(config) {11 command = config.command12 },13 configureServer: configureServer(icons),14 transformIndexHtml: generateBundle(icons),15 generateBundle: transformIndexHtml(icons, command),16 }17}...
configureIntegrationTests.js
Source:configureIntegrationTests.js
2const { configureContainer } = require('./configureContainer');3const { configureServer } = require('./configureServer');4beforeAll(async () => {5 global.container = configureContainer();6 global.server = await configureServer(global.container);7});8afterEach(async () => {9 await knexCleaner.clean(container.get('db'), {10 ignoreTables: ['knex_migrations', 'knex_migrations_lock'],11 });12});13afterAll(async () => {14 const db = global.container.get('db');15 await db.destroy();...
Using AI Code Generation
1const AppiumBaseDriver = require('appium-base-driver');2const appiumBaseDriver = new AppiumBaseDriver();3appiumBaseDriver.configureServer();4const appiumBaseDriver = new AppiumBaseDriver();5appiumBaseDriver.configureApp();6const appiumBaseDriver = new AppiumBaseDriver();7appiumBaseDriver.configureLogging();8const appiumBaseDriver = new AppiumBaseDriver();9appiumBaseDriver.configureTmpDir();10const appiumBaseDriver = new AppiumBaseDriver();11appiumBaseDriver.configureBaseDriver();12const appiumBaseDriver = new AppiumBaseDriver();13appiumBaseDriver.configureIos();14const appiumBaseDriver = new AppiumBaseDriver();15appiumBaseDriver.configureAndroid();16const appiumBaseDriver = new AppiumBaseDriver();17appiumBaseDriver.configureSelendroid();18const appiumBaseDriver = new AppiumBaseDriver();19appiumBaseDriver.configureChrome();20const appiumBaseDriver = new AppiumBaseDriver();21appiumBaseDriver.configureFirefox();22const appiumBaseDriver = new AppiumBaseDriver();23appiumBaseDriver.configureGeneric();24const appiumBaseDriver = new AppiumBaseDriver();25appiumBaseDriver.configureWindows();26const appiumBaseDriver = new AppiumBaseDriver();27appiumBaseDriver.configureMac();28const appiumBaseDriver = new AppiumBaseDriver();29appiumBaseDriver.configureSafari();30const appiumBaseDriver = new AppiumBaseDriver();
Using AI Code Generation
1const AppiumBaseDriver = require('appium-base-driver');2const appiumBaseDriver = new AppiumBaseDriver();3appiumBaseDriver.configureServer();4const AppiumDriver = require('appium');5const appiumDriver = new AppiumDriver();6appiumDriver.configureServer();7const appiumDriver = require('appium');8appiumDriver.configureServer();9const appiumBaseDriver = require('appium-base-driver');10appiumBaseDriver.configureServer();11const appiumBaseDriver = require('appium-base-driver').default;12appiumBaseDriver.configureServer();13const appiumDriver = require('appium').default;14appiumDriver.configureServer();15const appiumBaseDriver = require('appium-base-driver').AppiumBaseDriver;16appiumBaseDriver.configureServer();17const appiumDriver = require('appium').AppiumDriver;18appiumDriver.configureServer();19const {AppiumBaseDriver} = require('appium-base-driver');20const appiumBaseDriver = new AppiumBaseDriver();21appiumBaseDriver.configureServer();22const {AppiumDriver} = require('appium');23const appiumDriver = new AppiumDriver();24appiumDriver.configureServer();25const {AppiumBaseDriver} = require('appium-base-driver').default;26const appiumBaseDriver = new AppiumBaseDriver();27appiumBaseDriver.configureServer();28const {AppiumDriver} = require('appium').default;29const appiumDriver = new AppiumDriver();30appiumDriver.configureServer();31const {AppiumBaseDriver} = require('appium-base-driver').AppiumBaseDriver;32const appiumBaseDriver = new AppiumBaseDriver();33appiumBaseDriver.configureServer();
Using AI Code Generation
1let AppiumBaseDriver = require('appium-base-driver');2let appiumBaseDriver = new AppiumBaseDriver();3let serverConfig = {4};5appiumBaseDriver.configureServer(serverConfig);6class BaseDriver {7 constructor () {8 }9 configureServer (opts) {10 }11}12commands.configureServer = async function (opts) {13}14let AppiumBaseDriver = require('appium-base-driver');15let appiumBaseDriver = new AppiumBaseDriver();16let serverConfig = {17};18appiumBaseDriver.configureServer(serverConfig);19appiumBaseDriver.start();20class BaseDriver {21 constructor () {22 }23 configureServer (opts) {24 }25 start () {26 }27}28commands.start = async function () {29}
Using AI Code Generation
1const AppiumBaseDriver = require('appium-base-driver');2const { configureServer } = AppiumBaseDriver;3const server = configureServer({4 });5server.start();6server.stop();7const driver = await server.createSession({8 capabilities: {9 }10 });11await driver.execute('mobile: scroll', {12 });13await server.deleteSession();14server.stop();15server.start();16const driver = await server.createSession({17 capabilities: {18 }19 });20await driver.execute('mobile: scroll', {21 });22await server.deleteSession();23server.stop();24server.start();25const driver = await server.createSession({26 capabilities: {27 }28 });29await driver.execute('mobile: scroll', {30 });31await server.deleteSession();32server.stop();33server.start();34const driver = await server.createSession({35 capabilities: {36 }37 });
Using AI Code Generation
1await this.configureServer();2await this.startServer();3await this.stopServer();4await this.configureServer();5await this.startServer();6await this.stopServer();7await this.configureServer();8await this.startServer();9await this.stopServer();10await this.configureServer();11await this.startServer();12await this.stopServer();13await this.configureServer();14await this.startServer();15await this.stopServer();16await this.configureServer();17await this.startServer();18await this.stopServer();19await this.configureServer();20await this.startServer();21await this.stopServer();22await this.configureServer();23await this.startServer();
Using AI Code Generation
1const AppiumBaseDriver = require('appium-base-driver');2const server = AppiumBaseDriver.configureServer();3server.start();4const server = require('appium-express').server;5const configureServer = function (port, host, basePath) {6 return server({port, host, basePath});7};8module.exports = {9};10const express = require('express');11const bodyParser = require('body-parser');12const morgan = require('morgan');13const path = require('path');14const fs = require('fs');15const _ = require('lodash');16const { logger } = require('appium-support');17const { getNonDefaultArgs } = require('./utils');18const log = logger.getLogger('Appium');19const DEFAULT_LOG_FILENAME = 'appium.log';20const DEFAULT_BASE_PATH = '/wd/hub';
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!!